\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{andystp} \pdfinfo{ /Title (gnu-multiple-precision-gnu-mp-gmp.pdf) /Creator (Cheatography) /Author (andystp) /Subject (GNU Multiple Precision - GNU MP - GMP Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{GNU Multiple Precision - GNU MP - GMP Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{andystp} via \textcolor{DarkBackground}{\uline{cheatography.com/54020/cs/14512/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}andystp \\ \uline{cheatography.com/andystp} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 13th February, 2018.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Header}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{\#include\textless{}gmp.h\textgreater{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.6629 cm} x{12.6071 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} mpz\_t & multiple precision integer \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} mpq\_t & multiple precision fraction \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} mpf\_t & float is an arbitrary precision mantissa with a limited precision exponent \tn % Row Count 5 (+ 3) % Row 3 \SetRowColor{white} mp\_exp\_t & floating point functions accept and return exponents in this type \tn % Row Count 8 (+ 3) % Row 4 \SetRowColor{LightBackground} mp\_limb\_t & a limb means the part of a multi-precision number that ts in a single machine word (normally 32bit or 64bit) \tn % Row Count 12 (+ 4) % Row 5 \SetRowColor{white} mp\_size\_t & counts of limbs of a multi-precision number represented \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{mp\_bitcnt\_t} & counts of bits of a multi-precision number \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{gmp\_randstate\_t} & random state means an algorithm selection and current state data \tn % Row Count 19 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} x{15.543 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Function Class prefixes}} \tn % Row 0 \SetRowColor{LightBackground} mpz\_ & Functions for signed integer arithmetic \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} mpq\_ & Functions for rational number arithmetic \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} mpf\_ & Functions for floating-point arithmetic \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} mpn\_ & Fast low-level functions that operate on natural numbers. These are used by the functions in the preceding groups, and you can also call them directly from very time-critical user programs. \tn % Row Count 12 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Initialization Functions}} \tn % Row 0 \SetRowColor{LightBackground} void mpz\_init (mpz\_t x) & Initialize x, and set its value to 0. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} void mpq\_init (mpq\_t x) & Initialize x and set it to 0/1. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} void mpf\_init (mpf\_t x) & Initialize x to 0. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} void mp{[}z,q,f{]}\_inits (mp{[}z,q,f{]} x, ...) & Initialize a NULL-terminated list of mp{[}z,q,f{]}\_t variables, and set their values to 0. \tn % Row Count 11 (+ 5) % Row 4 \SetRowColor{LightBackground} void mp{[}z,q,f{]}\_clear (mp{[}z,q,f{]}\_t x) & Free the space occupied by x. Call this function for all mp{[}z,q,f{]}\_t variables when you are done with them. \tn % Row Count 17 (+ 6) % Row 5 \SetRowColor{white} void mp{[}z,q,f{]}\_clears (mp{[}z,q,f{]}\_t x, ...) & Free the space occupied by a NULL-terminated list of mp{[}z,q,f{]}\_t variables. \tn % Row Count 21 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Assignment Functions}} \tn % Row 0 \SetRowColor{LightBackground} void mpz\_set (mpz\_t rop, const mpz\_t op) & Set the value of rop from op. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} void mpz\_set\_ui (mpz\_t rop, unsigned long int op) & " \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} void mpz\_set\_si (mpz\_t rop, signed long int op) & " \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} void mpz\_set\_d (mpz\_t rop, double op) & truncate \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} void mpz\_set\_q (mpz\_t rop, const mpq\_t op) & " \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} void mpz\_set\_f (mpz\_t rop, const mpf\_t op) & " \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} void mpq\_set (mpq\_t rop, const mpq\_t op) & Assign rop from op. \tn % Row Count 18 (+ 2) % Row 7 \SetRowColor{white} void mpq\_set\_z (mpq\_t rop, const mpz\_t op) & " \tn % Row Count 21 (+ 3) % Row 8 \SetRowColor{LightBackground} void mpq\_set\_ui (mpq\_t rop, unsigned long int op1, unsigned long int op2) & Set the value of rop to op1/op2. Note that if op1 and op2 have common factors, rop has to be passed to mpq\_canonicalize before any operations are performed on rop. \tn % Row Count 30 (+ 9) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Assignment Functions (cont)}} \tn % Row 9 \SetRowColor{LightBackground} void mpq\_set\_si (mpq\_t rop, signed long int op1, unsigned long int op2) & " \tn % Row Count 4 (+ 4) % Row 10 \SetRowColor{white} void mpf\_set (mpf\_t rop, const mpf\_t op) & Set the value of rop from op. \tn % Row Count 6 (+ 2) % Row 11 \SetRowColor{LightBackground} void mpf\_set\_ui (mpf\_t rop, unsigned long int op) & " \tn % Row Count 9 (+ 3) % Row 12 \SetRowColor{white} void mpf\_set\_si (mpf\_t rop, signed long int op) & " \tn % Row Count 12 (+ 3) % Row 13 \SetRowColor{LightBackground} void mpf\_set\_d (mpf\_t rop, double op) & " \tn % Row Count 14 (+ 2) % Row 14 \SetRowColor{white} void mpf\_set\_z (mpf\_t rop, const mpz\_t op) & " \tn % Row Count 17 (+ 3) % Row 15 \SetRowColor{LightBackground} void mpf\_set\_q (mpf\_t rop, const mpq\_t op) & " \tn % Row Count 20 (+ 3) % Row 16 \SetRowColor{white} int mpz\_set\_str (mpz\_t rop, const char *str, int base) & Set the value of rop from str, a null-terminated C string in base base. White space is allowed in the string, and is simply ignored. Should return 0, if error returns -1. \tn % Row Count 29 (+ 9) % Row 17 \SetRowColor{LightBackground} int mpq\_set\_str (mpq\_t rop, const char *str, int base) & Set rop from a null-terminated string str in the given base. Should return 0, if error returns -1. \tn % Row Count 34 (+ 5) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Assignment Functions (cont)}} \tn % Row 18 \SetRowColor{LightBackground} int mpf\_set\_str (mpf\_t rop, const char *str, int base) & et the value of rop from the string in str. Should return 0, if error returns -1. \tn % Row Count 5 (+ 5) % Row 19 \SetRowColor{white} void mpz\_swap (mpz\_t rop1, mpz\_t rop2) & Swap the values rop1 and rop2 efficiently. \tn % Row Count 8 (+ 3) % Row 20 \SetRowColor{LightBackground} void mpq\_swap (mpq\_t rop1, mpq\_t rop2) & Swap the values rop1 and rop2 efficiently. \tn % Row Count 11 (+ 3) % Row 21 \SetRowColor{white} void mpf\_swap (mpf\_t rop1, mpf\_t rop2) & Swap rop1 and rop2 efficiently. Both the values and the precisions of the two variables are swapped. \tn % Row Count 16 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Conversion Functions}} \tn % Row 0 \SetRowColor{LightBackground} unsigned long int mpz\_get\_ui (const mpz\_t op) & Return the value of op as an unsigned long. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} signed long int mpz\_get\_si (const mpz\_t op) & If op fits into a signed long int return the value of op. Otherwise return the least significant part of op, with the same sign as op. \tn % Row Count 10 (+ 7) % Row 2 \SetRowColor{LightBackground} double mpz\_get\_d (const mpz\_t op) & Convert op to a double, truncating if necessary (i.e. rounding towards zero). \tn % Row Count 14 (+ 4) % Row 3 \SetRowColor{white} double mpz\_get\_d\_2exp (signed long int *exp, const mpz\_t op) & Convert op to a double, truncating if necessary (i.e. rounding towards zero), and returning the exponent separately. \tn % Row Count 20 (+ 6) % Row 4 \SetRowColor{LightBackground} char {\emph{ mpz\_get\_str (char }}str, int base, const mpz\_t op) & Convert op to a string of digits in base base. The base argument may vary from 2 to 62 or from -2 to -36. \tn % Row Count 26 (+ 6) % Row 5 \SetRowColor{white} double mpq\_get\_d (const mpq\_t op) & Convert op to a double, truncating if necessary (i.e. rounding towards zero). \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Conversion Functions (cont)}} \tn % Row 6 \SetRowColor{LightBackground} void mpq\_set\_d (mpq\_t rop, double op) & Set rop to the value of op. There is no rounding, this conversion is exact. \tn % Row Count 4 (+ 4) % Row 7 \SetRowColor{white} void mpq\_set\_f (mpq\_t rop, const mpf\_t op) & Set rop to the value of op. There is no rounding, this conversion is exact. \tn % Row Count 8 (+ 4) % Row 8 \SetRowColor{LightBackground} char {\emph{ mpq\_get\_str (char }}str, int base, const mpq\_t op) & Convert op to a string of digits in base base. The base may vary from 2 to 36. The string will be of the form 'num/den', or if the denominator is 1 then just 'num'. \tn % Row Count 17 (+ 9) % Row 9 \SetRowColor{white} double mpf\_get\_d (const mpf\_t op) & Convert op to a double, truncating if necessary (i.e. rounding towards zero). \tn % Row Count 21 (+ 4) % Row 10 \SetRowColor{LightBackground} double mpf\_get\_d\_2exp (signed long int *exp, const mpf\_t op) & Convert op to a double, truncating if necessary (i.e. rounding towards zero), and with an exponent returned separately. \tn % Row Count 27 (+ 6) % Row 11 \SetRowColor{white} long mpf\_get\_si (const mpf\_t op) & Convert op to a long or unsigned long, truncating any fraction part. If op is too big for the return type, the result is undefined. \tn % Row Count 34 (+ 7) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Conversion Functions (cont)}} \tn % Row 12 \SetRowColor{LightBackground} unsigned long mpf\_get\_ui (const mpf\_t op) & Convert op to a long or unsigned long, truncating any fraction part. If op is too big for the return type, the result is undefined. \tn % Row Count 7 (+ 7) % Row 13 \SetRowColor{white} char {\emph{ mpf\_get\_str (char }}str, mp\_exp\_t *expptr, int base, size\_t n\_digits, const mpf\_t op) & Convert op to a string of digits in base base. The base argument may vary from 2 to 62 or from -2 to -36. Up to n\_digits digits will be generated. Trailing zeros are not returned. No more digits than can be accurately represented by op are ever generated. If n\_digits is 0 then that accurate maximum number of digits are generated. \tn % Row Count 24 (+ 17) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Arithmetic Functions}} \tn % Row 0 \SetRowColor{LightBackground} void mpz\_add (mpz\_t rop, const mpz\_t op1, const mpz\_t op2) & Set rop to op1 + op2. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} void mpz\_add\_ui (mpz\_t rop, const mpz\_t op1, unsigned long int op2) & Set rop to op1 + op2. \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} void mpz\_sub (mpz\_t rop, const mpz\_t op1, const mpz\_t op2) & Set rop to op1 - op2. \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} void mpz\_sub\_ui (mpz\_t rop, const mpz\_t op1, unsigned long int op2) & Set rop to op1 - op2. \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} void mpz\_ui\_sub (mpz\_t rop, unsigned long int op1, const mpz\_t op2) & Set rop to op1 - op2. \tn % Row Count 18 (+ 4) % Row 5 \SetRowColor{white} void mpz\_mul (mpz\_t rop, const mpz\_t op1, const mpz\_t op2) & Set rop to op1 times op2. \tn % Row Count 21 (+ 3) % Row 6 \SetRowColor{LightBackground} void mpz\_mul\_si (mpz\_t rop, const mpz\_t op1, long int op2) & Set rop to op1 times op2. \tn % Row Count 24 (+ 3) % Row 7 \SetRowColor{white} void mpz\_mul\_ui (mpz\_t rop, const mpz\_t op1, unsigned long int op2) & Set rop to op1 times op2. \tn % Row Count 28 (+ 4) % Row 8 \SetRowColor{LightBackground} void mpz\_addmul (mpz\_t rop, const mpz\_t op1, const mpz\_t op2) & Set rop to rop + op1 times op2. \tn % Row Count 32 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Arithmetic Functions (cont)}} \tn % Row 9 \SetRowColor{LightBackground} void mpz\_addmul\_ui (mpz\_t rop, const mpz\_t op1, unsigned long int op2) & Set rop to rop + op1 times op2. \tn % Row Count 4 (+ 4) % Row 10 \SetRowColor{white} void mpz\_submul (mpz\_t rop, const mpz\_t op1, const mpz\_t op2) & Set rop to rop - op1 times op2. \tn % Row Count 8 (+ 4) % Row 11 \SetRowColor{LightBackground} void mpz\_submul\_ui (mpz\_t rop, const mpz\_t op1, unsigned long int op2) & Set rop to rop - op1 times op2. \tn % Row Count 12 (+ 4) % Row 12 \SetRowColor{white} void mpz\_mul\_2exp (mpz\_t rop, const mpz\_t op1, mp\_bitcnt\_t op2) & Set rop to op1 times 2 raised to op2. This operation can also be defined as a left shift by op2 bits. \tn % Row Count 18 (+ 6) % Row 13 \SetRowColor{LightBackground} void mpz\_neg (mpz\_t rop, const mpz\_t op) & Set rop to -op. \tn % Row Count 20 (+ 2) % Row 14 \SetRowColor{white} void mpz\_abs (mpz\_t rop, const mpz\_t op) & Set rop to the absolute value of op. \tn % Row Count 22 (+ 2) % Row 15 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 22 (+ 0) % Row 16 \SetRowColor{white} void mpq\_add (mpq\_t sum, const mpq\_t addend1, const mpq\_t addend2) & Set sum to addend1 + addend2. \tn % Row Count 26 (+ 4) % Row 17 \SetRowColor{LightBackground} void mpq\_sub (mpq\_t difference, const mpq\_t minuend, const mpq\_t subtrahend) & Set difference to minuend - subtrahend. \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Arithmetic Functions (cont)}} \tn % Row 18 \SetRowColor{LightBackground} void mpq\_mul (mpq\_t product, const mpq\_t multiplier, const mpq\_t multiplicand) & Set product to multiplier times multiplicand. \tn % Row Count 4 (+ 4) % Row 19 \SetRowColor{white} void mpq\_mul\_2exp (mpq\_t rop, const mpq\_t op1, mp\_bitcnt\_t op2) & Set rop to op1 times 2 raised to op2. This operation can also be defined as a left shift by op2 bits. \tn % Row Count 10 (+ 6) % Row 20 \SetRowColor{LightBackground} void mpq\_div (mpq\_t quotient, const mpq\_t dividend, const mpq\_t divisor) & Set quotient to dividend/divisor. \tn % Row Count 14 (+ 4) % Row 21 \SetRowColor{white} void mpq\_div\_2exp (mpq\_t rop, const mpq\_t op1, mp\_bitcnt\_t op2) & Set rop to op1 divided by 2 raised to op2. \tn % Row Count 18 (+ 4) % Row 22 \SetRowColor{LightBackground} void mpq\_neg (mpq\_t negated\_operand, const mpq\_t operand) & Set negated\_operand to -operand. \tn % Row Count 21 (+ 3) % Row 23 \SetRowColor{white} void mpq\_abs (mpq\_t rop, const mpq\_t op) & Set rop to the absolute value of op. \tn % Row Count 23 (+ 2) % Row 24 \SetRowColor{LightBackground} void mpq\_inv (mpq\_t inverted\_number, const mpq\_t number) & Set inverted\_number to 1/number. If the new denominator is zero, this routine will divide by zero. \tn % Row Count 28 (+ 5) % Row 25 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 28 (+ 0) % Row 26 \SetRowColor{LightBackground} void mpf\_add (mpf\_t rop, const mpf\_t op1, const mpf\_t op2) & Set rop to op1 + op2. \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Arithmetic Functions (cont)}} \tn % Row 27 \SetRowColor{LightBackground} void mpf\_add\_ui (mpf\_t rop, const mpf\_t op1, unsigned long int op2) & Set rop to op1 + op2. \tn % Row Count 4 (+ 4) % Row 28 \SetRowColor{white} void mpf\_sub (mpf\_t rop, const mpf\_t op1, const mpf\_t op2) & Set rop to op1 - op2. \tn % Row Count 7 (+ 3) % Row 29 \SetRowColor{LightBackground} void mpf\_ui\_sub (mpf\_t rop, unsigned long int op1, const mpf\_t op2) & Set rop to op1 - op2. \tn % Row Count 11 (+ 4) % Row 30 \SetRowColor{white} void mpf\_sub\_ui (mpf\_t rop, const mpf\_t op1, unsigned long int op2) & Set rop to op1 - op2. \tn % Row Count 15 (+ 4) % Row 31 \SetRowColor{LightBackground} void mpf\_mul (mpf\_t rop, const mpf\_t op1, const mpf\_t op2) & Set rop to op1 times op2. \tn % Row Count 18 (+ 3) % Row 32 \SetRowColor{white} void mpf\_mul\_ui (mpf\_t rop, const mpf\_t op1, unsigned long int op2) & Set rop to op1 times op2. \tn % Row Count 22 (+ 4) % Row 33 \SetRowColor{LightBackground} void mpf\_div (mpf\_t rop, const mpf\_t op1, const mpf\_t op2) & Set rop to op1/op2. \tn % Row Count 25 (+ 3) % Row 34 \SetRowColor{white} void mpf\_ui\_div (mpf\_t rop, unsigned long int op1, const mpf\_t op2) & Set rop to op1/op2. \tn % Row Count 29 (+ 4) % Row 35 \SetRowColor{LightBackground} void mpf\_div\_ui (mpf\_t rop, const mpf\_t op1, unsigned long int op2) & Set rop to op1/op2. \tn % Row Count 33 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Arithmetic Functions (cont)}} \tn % Row 36 \SetRowColor{LightBackground} void mpf\_sqrt (mpf\_t rop, const mpf\_t op) & Set rop to the square root of op. \tn % Row Count 3 (+ 3) % Row 37 \SetRowColor{white} void mpf\_sqrt\_ui (mpf\_t rop, unsigned long int op) & Set rop to the square root of op. \tn % Row Count 6 (+ 3) % Row 38 \SetRowColor{LightBackground} void mpf\_pow\_ui (mpf\_t rop, const mpf\_t op1, unsigned long int op2) & Set rop to op1 raised to the power op2. \tn % Row Count 10 (+ 4) % Row 39 \SetRowColor{white} void mpf\_neg (mpf\_t rop, const mpf\_t op) & Set rop to -op. \tn % Row Count 12 (+ 2) % Row 40 \SetRowColor{LightBackground} void mpf\_abs (mpf\_t rop, const mpf\_t op) & Set rop to the absolute value of op. \tn % Row Count 14 (+ 2) % Row 41 \SetRowColor{white} void mpf\_mul\_2exp (mpf\_t rop, const mpf\_t op1, mp\_bitcnt\_t op2) & Set rop to op1 times 2 raised to op2. This operation can also be defined as a left shift by op2 bits. \tn % Row Count 20 (+ 6) % Row 42 \SetRowColor{LightBackground} void mpf\_div\_2exp (mpf\_t rop, const mpf\_t op1, mp\_bitcnt\_t op2) & Set rop to op1 divided by 2 raised to op2. \tn % Row Count 24 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Division Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{void mpz\_cdiv\_q (mpz\_t q, const mpz\_t n, const mpz\_t d)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{void mpz\_cdiv\_r (mpz\_t r, const mpz\_t n, const mpz\_t d)} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{void mpz\_cdiv\_qr (mpz\_t q, mpz\_t r, const mpz\_t n, const mpz\_t d)} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_cdiv\_q\_ui (mpz\_t q, const mpz\_t n, unsigned long int d)} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_cdiv\_r\_ui (mpz\_t r, const mpz\_t n, unsigned long int d)} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_cdiv\_qr\_ui (mpz\_t q, mpz\_t r, const mpz\_t n, unsigned long int d)} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_cdiv\_ui (const mpz\_t n, unsigned long int d)} \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{void mpz\_cdiv\_q\_2exp (mpz\_t q, const mpz\_t n, mp\_bitcnt\_t b)} \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{void mpz\_cdiv\_r\_2exp (mpz\_t r, const mpz\_t n, mp\_bitcnt\_t b)} \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 18 (+ 0) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{void mpz\_fdiv\_q (mpz\_t q, const mpz\_t n, const mpz\_t d)} \tn % Row Count 20 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{void mpz\_fdiv\_r (mpz\_t r, const mpz\_t n, const mpz\_t d)} \tn % Row Count 22 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{void mpz\_fdiv\_qr (mpz\_t q, mpz\_t r, const mpz\_t n, const mpz\_t d)} \tn % Row Count 24 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_fdiv\_q\_ui (mpz\_t q, const mpz\_t n, unsigned long int d)} \tn % Row Count 26 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_fdiv\_r\_ui (mpz\_t r, const mpz\_t n, unsigned long int d)} \tn % Row Count 28 (+ 2) % Row 15 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_fdiv\_qr\_ui (mpz\_t q, mpz\_t r, const mpz\_t n, unsigned long int d)} \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Division Functions (cont)}} \tn % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_fdiv\_ui (const mpz\_t n, unsigned long int d)} \tn % Row Count 2 (+ 2) % Row 17 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{void mpz\_fdiv\_q\_2exp (mpz\_t q, const mpz\_t n, mp\_bitcnt\_t b)} \tn % Row Count 4 (+ 2) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{void mpz\_fdiv\_r\_2exp (mpz\_t r, const mpz\_t n, mp\_bitcnt\_t b)} \tn % Row Count 6 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 6 (+ 0) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{void mpz\_tdiv\_q (mpz\_t q, const mpz\_t n, const mpz\_t d)} \tn % Row Count 8 (+ 2) % Row 21 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{void mpz\_tdiv\_r (mpz\_t r, const mpz\_t n, const mpz\_t d)} \tn % Row Count 10 (+ 2) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{void mpz\_tdiv\_qr (mpz\_t q, mpz\_t r, const mpz\_t n, const mpz\_t d)} \tn % Row Count 12 (+ 2) % Row 23 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_tdiv\_q\_ui (mpz\_t q, const mpz\_t n, unsigned long int d)} \tn % Row Count 14 (+ 2) % Row 24 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_tdiv\_r\_ui (mpz\_t r, const mpz\_t n, unsigned long int d)} \tn % Row Count 16 (+ 2) % Row 25 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_tdiv\_qr\_ui (mpz\_t q, mpz\_t r, const mpz\_t n, unsigned long int d)} \tn % Row Count 18 (+ 2) % Row 26 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{unsigned long int mpz\_tdiv\_ui (const mpz\_t n, unsigned long int d)} \tn % Row Count 20 (+ 2) % Row 27 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{void mpz\_tdiv\_q\_2exp (mpz\_t q, const mpz\_t n, mp\_bitcnt\_t b)} \tn % Row Count 22 (+ 2) % Row 28 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{void mpz\_tdiv\_r\_2exp (mpz\_t r, const mpz\_t n, mp\_bitcnt\_t b)} \tn % Row Count 24 (+ 2) % Row 29 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 24 (+ 0) % Row 30 \SetRowColor{LightBackground} Divide n by d, forming a quotient q and/or remainder r. For the 2exp functions, d=2\textasciicircum{}b. The rounding is in three styles, each suiting different applications. & cdiv rounds q up towards +infinity, and r will have the opposite sign to d. The c stands for "ceil". \tn % Row Count 32 (+ 8) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Division Functions (cont)}} \tn % Row 31 \SetRowColor{LightBackground} & fdiv rounds q down towards -infinity, and r will have the same sign as d. The f stands for "floor". \tn % Row Count 6 (+ 6) % Row 32 \SetRowColor{white} & tdiv rounds q towards zero, and r will have the same sign as n. The t stands for "truncate". \tn % Row Count 11 (+ 5) % Row 33 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{In all cases q and r will satisfy n=q*d+r, and r will satisfy 0\textless{}=abs(r)\textless{}abs(d).} \tn % Row Count 13 (+ 2) % Row 34 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{The q functions calculate only the quotient, the r functions only the remainder, and the qr functions calculate both. Note that for qr the same variable cannot be passed for both q and r, or results will be unpredictable.} \tn % Row Count 18 (+ 5) % Row 35 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{For the ui variants the return value is the remainder, and in fact returning the remainder is all the div\_ui functions do. For tdiv and cdiv the remainder can be negative, so for those the return value is the absolute value of the remainder.} \tn % Row Count 23 (+ 5) % Row 36 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{For the 2exp variants the divisor is 2\textasciicircum{}b. These functions are implemented as right shifts and bit masks, but of course they round the same as the other functions.} \tn % Row Count 27 (+ 4) % Row 37 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{For positive n both mpz\_fdiv\_q\_2exp and mpz\_tdiv\_q\_2exp are simple bitwise right shifts. For negative n, mpz\_fdiv\_q\_2exp is effectively an arithmetic right shift treating n as twos complement the same as the bitwise logical functions do, whereas mpz\_tdiv\_q\_2exp effectively treats n as sign and magnitude.} \tn % Row Count 34 (+ 7) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Division Functions (cont)}} \tn % Row 38 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) % Row 39 \SetRowColor{white} void mpz\_mod (mpz\_t r, const mpz\_t n, const mpz\_t d) & Set r to n mod d. The sign of the divisor is ignored; the result is always non-negative. \tn % Row Count 5 (+ 5) % Row 40 \SetRowColor{LightBackground} unsigned long int mpz\_mod\_ui (mpz\_t r, const mpz\_t n, unsigned long int d) & Set r to n mod d. The sign of the divisor is ignored; the result is always non-negative. \tn % Row Count 10 (+ 5) % Row 41 \SetRowColor{white} & mpz\_mod\_ui is identical to mpz\_fdiv\_r\_ui above, returning the remainder as well as setting r. See mpz\_fdiv\_ui above if only the return value is wanted. \tn % Row Count 18 (+ 8) % Row 42 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 18 (+ 0) % Row 43 \SetRowColor{white} void mpz\_divexact (mpz\_t q, const mpz\_t n, const mpz\_t d) & Set q to n/d. These functions produce correct results only when it is known in advance that d divides n. \tn % Row Count 24 (+ 6) % Row 44 \SetRowColor{LightBackground} void mpz\_divexact\_ui (mpz\_t q, const mpz\_t n, unsigned long d) & Set q to n/d. These functions produce correct results only when it is known in advance that d divides n. \tn % Row Count 30 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Division Functions (cont)}} \tn % Row 45 \SetRowColor{LightBackground} & These routines are much faster than the other division functions, and are the best choice when exact division is known to occur, for example reducing a rational to lowest terms. \tn % Row Count 9 (+ 9) % Row 46 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 9 (+ 0) % Row 47 \SetRowColor{LightBackground} int mpz\_divisible\_p (const mpz\_t n, const mpz\_t d) & Return non-zero if n is exactly divisible by d, or in the case of \seqsplit{mpz\_divisible\_2exp\_p} by 2\textasciicircum{}b. \tn % Row Count 14 (+ 5) % Row 48 \SetRowColor{white} int \seqsplit{mpz\_divisible\_ui\_p} (const mpz\_t n, unsigned long int d) & Return non-zero if n is exactly divisible by d, or in the case of \seqsplit{mpz\_divisible\_2exp\_p} by 2\textasciicircum{}b. \tn % Row Count 19 (+ 5) % Row 49 \SetRowColor{LightBackground} int \seqsplit{mpz\_divisible\_2exp\_p} (const mpz\_t n, mp\_bitcnt\_t b) & Return non-zero if n is exactly divisible by d, or in the case of \seqsplit{mpz\_divisible\_2exp\_p} by 2\textasciicircum{}b. \tn % Row Count 24 (+ 5) % Row 50 \SetRowColor{white} & n is divisible by d if there exists an integer q satisfying n = q*d. Unlike the other division functions, d=0 is accepted and following the rule it can be seen that only 0 is considered divisible by 0. \tn % Row Count 35 (+ 11) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Division Functions (cont)}} \tn % Row 51 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) % Row 52 \SetRowColor{white} int mpz\_congruent\_p (const mpz\_t n, const mpz\_t c, const mpz\_t d) & Return non-zero if n is congruent to c modulo d, or in the case of \seqsplit{mpz\_congruent\_2exp\_p} modulo 2\textasciicircum{}b. \tn % Row Count 5 (+ 5) % Row 53 \SetRowColor{LightBackground} int \seqsplit{mpz\_congruent\_ui\_p} (const mpz\_t n, unsigned long int c, unsigned long int d) & Return non-zero if n is congruent to c modulo d, or in the case of \seqsplit{mpz\_congruent\_2exp\_p} modulo 2\textasciicircum{}b. \tn % Row Count 10 (+ 5) % Row 54 \SetRowColor{white} int \seqsplit{mpz\_congruent\_2exp\_p} (const mpz\_t n, const mpz\_t c, mp\_bitcnt\_t b) & Return non-zero if n is congruent to c modulo d, or in the case of \seqsplit{mpz\_congruent\_2exp\_p} modulo 2\textasciicircum{}b. \tn % Row Count 15 (+ 5) % Row 55 \SetRowColor{LightBackground} & n is congruent to c mod d if there exists an integer q satisfying n = c + q*d. Unlike the other division functions, d=0 is accepted and following the rule it can be seen that n and c are considered congruent mod 0 only when exactly equal. \tn % Row Count 27 (+ 12) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Exponentiation Functions}} \tn % Row 0 \SetRowColor{LightBackground} void mpz\_powm (mpz\_t rop, const mpz\_t base, const mpz\_t exp, const mpz\_t mod) & Set rop to (base raised to exp) modulo mod. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} void mpz\_powm\_ui (mpz\_t rop, const mpz\_t base, unsigned long int exp, const mpz\_t mod) & Set rop to (base raised to exp) modulo mod. \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} & Negative exp is supported if an inverse base\textasciicircum{}-1 mod mod exists (see mpz\_invert in Number Theoretic Functions). If an inverse doesn't exist then a divide by zero is raised. \tn % Row Count 18 (+ 9) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 18 (+ 0) % Row 4 \SetRowColor{LightBackground} void mpz\_powm\_sec (mpz\_t rop, const mpz\_t base, const mpz\_t exp, const mpz\_t mod) & Set rop to (base raised to exp) modulo mod. \tn % Row Count 23 (+ 5) % Row 5 \SetRowColor{white} & It is required that exp \textgreater{} 0 and that mod is odd. \tn % Row Count 26 (+ 3) % Row 6 \SetRowColor{LightBackground} & This function is designed to take the same time and have the same cache access patterns for any two same-size arguments, assuming that function arguments are placed at the same position and that the machine state is identical upon function entry. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired. \tn % Row Count 44 (+ 18) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Exponentiation Functions (cont)}} \tn % Row 7 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) % Row 8 \SetRowColor{white} void mpz\_pow\_ui (mpz\_t rop, const mpz\_t base, unsigned long int exp) & Set rop to base raised to exp. The case 0\textasciicircum{}0 yields 1. \tn % Row Count 4 (+ 4) % Row 9 \SetRowColor{LightBackground} void mpz\_ui\_pow\_ui (mpz\_t rop, unsigned long int base, unsigned long int exp) & Set rop to base raised to exp. The case 0\textasciicircum{}0 yields 1. \tn % Row Count 8 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Root Extraction Functions}} \tn % Row 0 \SetRowColor{LightBackground} int mpz\_root (mpz\_t rop, const mpz\_t op, unsigned long int n) & Set rop to the truncated integer part of the nth root of op. Return non-zero if the computation was exact, i.e., if op is rop to the nth power. \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} void mpz\_rootrem (mpz\_t root, mpz\_t rem, const mpz\_t u, unsigned long int n) & Set root to the truncated integer part of the nth root of u. Set rem to the remainder, u-root**n. \tn % Row Count 13 (+ 5) % Row 2 \SetRowColor{LightBackground} void mpz\_sqrt (mpz\_t rop, const mpz\_t op) & Set rop to the truncated integer part of the square root of op. \tn % Row Count 17 (+ 4) % Row 3 \SetRowColor{white} void mpz\_sqrtrem (mpz\_t rop1, mpz\_t rop2, const mpz\_t op) & Set rop1 to the truncated integer part of the square root of op, like mpz\_sqrt. Set rop2 to the remainder op-rop1*rop1, which will be zero if op is a perfect square. \tn % Row Count 26 (+ 9) % Row 4 \SetRowColor{LightBackground} & If rop1 and rop2 are the same variable, the results are undefined. \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Root Extraction Functions (cont)}} \tn % Row 5 \SetRowColor{LightBackground} int \seqsplit{mpz\_perfect\_power\_p} (const mpz\_t op) & Return non-zero if op is a perfect power, i.e., if there exist integers a and b, with b\textgreater{}1, such that op equals a raised to the power b. \tn % Row Count 7 (+ 7) % Row 6 \SetRowColor{white} & Under this definition both 0 and 1 are considered to be perfect powers. Negative values of op are accepted, but of course can only be odd perfect powers. \tn % Row Count 15 (+ 8) % Row 7 \SetRowColor{LightBackground} int \seqsplit{mpz\_perfect\_square\_p} (const mpz\_t op) & Return non-zero if op is a perfect square, i.e., if the square root of op is an integer. Under this definition both 0 and 1 are considered to be perfect squares. \tn % Row Count 24 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Number Theoretic Functions}} \tn % Row 0 \SetRowColor{LightBackground} int \seqsplit{mpz\_probab\_prime\_p} (const mpz\_t n, int reps) & Determine whether n is prime. Return 2 if n is definitely prime, return 1 if n is probably prime (without being certain), or return 0 if n is definitely non-prime. \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} & This function performs some trial divisions, then reps Miller-Rabin probabilistic primality tests. A higher reps value will reduce the chances of a non-prime being identified as "probably prime". A composite number will be identified as a prime with a probability of less than 4\textasciicircum{}(-reps). Reasonable values of reps are between 15 and 50. \tn % Row Count 26 (+ 17) % Row 2 \SetRowColor{LightBackground} void mpz\_nextprime (mpz\_t rop, const mpz\_t op) & Set rop to the next prime greater than op. \tn % Row Count 29 (+ 3) % Row 3 \SetRowColor{white} & This function uses a probabilistic algorithm to identify primes. For practical purposes it's adequate, the chance of a composite passing will be extremely small. \tn % Row Count 38 (+ 9) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Number Theoretic Functions (cont)}} \tn % Row 4 \SetRowColor{LightBackground} void mpz\_gcd (mpz\_t rop, const mpz\_t op1, const mpz\_t op2) & Set rop to the greatest common divisor of op1 and op2. The result is always positive even if one or both input operands are negative. Except if both inputs are zero; then this function defines gcd(0,0) = 0. \tn % Row Count 11 (+ 11) % Row 5 \SetRowColor{white} unsigned long int mpz\_gcd\_ui (mpz\_t rop, const mpz\_t op1, unsigned long int op2) & Compute the greatest common divisor of op1 and op2. If rop is not NULL, store the result there. \tn % Row Count 16 (+ 5) % Row 6 \SetRowColor{LightBackground} & If the result is small enough to fit in an unsigned long int, it is returned. If the result does not fit, 0 is returned, and the result is equal to the argument op1. Note that the result will always fit if op2 is non-zero. \tn % Row Count 28 (+ 12) % Row 7 \SetRowColor{white} void mpz\_gcdext (mpz\_t g, mpz\_t s, mpz\_t t, const mpz\_t a, const mpz\_t b) & Set g to the greatest common divisor of a and b, and in addition set s and t to coefficients satisfying a{\emph{s + b}}t = g. The value in g is always positive, even if one or both of a and b are negative (or zero if both inputs are zero). The values in s and t are chosen such that normally, abs(s) \textless{} abs(b) / (2 g) and abs(t) \textless{} abs(a) / (2 g), and these relations define s and t uniquely. There are a few exceptional cases: \tn % Row Count 49 (+ 21) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Number Theoretic Functions (cont)}} \tn % Row 8 \SetRowColor{LightBackground} & If abs(a) = abs(b), then s = 0, t = sgn(b). \tn % Row Count 3 (+ 3) % Row 9 \SetRowColor{white} & Otherwise, s = sgn(a) if b = 0 or abs(b) = 2 g, and t = sgn(b) if a = 0 or abs(a) = 2 g. \tn % Row Count 8 (+ 5) % Row 10 \SetRowColor{LightBackground} & In all cases, s = 0 if and only if g = abs(b), i.e., if b divides a or a = b = 0. \tn % Row Count 13 (+ 5) % Row 11 \SetRowColor{white} & If t is NULL then that value is not computed. \tn % Row Count 16 (+ 3) % Row 12 \SetRowColor{LightBackground} void mpz\_lcm (mpz\_t rop, const mpz\_t op1, const mpz\_t op2) & Set rop to the least common multiple of op1 and op2. rop is always positive, irrespective of the signs of op1 and op2. rop will be zero if either op1 or op2 is zero. \tn % Row Count 25 (+ 9) % Row 13 \SetRowColor{white} void mpz\_lcm\_ui (mpz\_t rop, const mpz\_t op1, unsigned long op2) & Set rop to the least common multiple of op1 and op2. rop is always positive, irrespective of the signs of op1 and op2. rop will be zero if either op1 or op2 is zero. \tn % Row Count 34 (+ 9) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Number Theoretic Functions (cont)}} \tn % Row 14 \SetRowColor{LightBackground} int mpz\_invert (mpz\_t rop, const mpz\_t op1, const mpz\_t op2) & Compute the inverse of op1 modulo op2 and put the result in rop. If the inverse exists, the return value is non-zero and rop will satisfy 0 \textless{}= rop \textless{} abs(op2) (with rop = 0 possible only when abs(op2) = 1, i.e., in the somewhat degenerate zero ring). If an inverse doesn't exist the return value is zero and rop is undefined. The behaviour of this function is undefined when op2 is zero. \tn % Row Count 20 (+ 20) % Row 15 \SetRowColor{white} int mpz\_jacobi (const mpz\_t a, const mpz\_t b) & Calculate the Jacobi symbol (a/b). This is defined only for b odd. \tn % Row Count 24 (+ 4) % Row 16 \SetRowColor{LightBackground} int mpz\_legendre (const mpz\_t a, const mpz\_t p) & Calculate the Legendre symbol (a/p). This is defined only for p an odd positive prime, and for such p it's identical to the Jacobi symbol. \tn % Row Count 31 (+ 7) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Number Theoretic Functions (cont)}} \tn % Row 17 \SetRowColor{LightBackground} int mpz\_kronecker (const mpz\_t a, const mpz\_t b) & Calculate the Jacobi symbol (a/b) with the Kronecker extension (a/2)=(2/a) when a odd, or (a/2)=0 when a even. \tn % Row Count 6 (+ 6) % Row 18 \SetRowColor{white} int mpz\_kronecker\_si (const mpz\_t a, long b) & Calculate the Jacobi symbol (a/b) with the Kronecker extension (a/2)=(2/a) when a odd, or (a/2)=0 when a even. \tn % Row Count 12 (+ 6) % Row 19 \SetRowColor{LightBackground} int mpz\_kronecker\_ui (const mpz\_t a, unsigned long b) & Calculate the Jacobi symbol (a/b) with the Kronecker extension (a/2)=(2/a) when a odd, or (a/2)=0 when a even. \tn % Row Count 18 (+ 6) % Row 20 \SetRowColor{white} int mpz\_si\_kronecker (long a, const mpz\_t b) & Calculate the Jacobi symbol (a/b) with the Kronecker extension (a/2)=(2/a) when a odd, or (a/2)=0 when a even. \tn % Row Count 24 (+ 6) % Row 21 \SetRowColor{LightBackground} int mpz\_ui\_kronecker (unsigned long a, const mpz\_t b) & Calculate the Jacobi symbol (a/b) with the Kronecker extension (a/2)=(2/a) when a odd, or (a/2)=0 when a even. \tn % Row Count 30 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Number Theoretic Functions (cont)}} \tn % Row 22 \SetRowColor{LightBackground} mp\_bitcnt\_t mpz\_remove (mpz\_t rop, const mpz\_t op, const mpz\_t f) & Remove all occurrences of the factor f from op and store the result in rop. The return value is how many such occurrences were removed. \tn % Row Count 7 (+ 7) % Row 23 \SetRowColor{white} void mpz\_fac\_ui (mpz\_t rop, unsigned long int n) & Set rop to the factorial of n: mpz\_fac\_ui computes the plain factorial n!, mpz\_2fac\_ui computes the double-factorial n!!, and mpz\_mfac\_uiui the m-multi-factorial n!\textasciicircum{}(m). \tn % Row Count 16 (+ 9) % Row 24 \SetRowColor{LightBackground} void mpz\_2fac\_ui (mpz\_t rop, unsigned long int n) & Set rop to the factorial of n: mpz\_fac\_ui computes the plain factorial n!, mpz\_2fac\_ui computes the double-factorial n!!, and mpz\_mfac\_uiui the m-multi-factorial n!\textasciicircum{}(m). \tn % Row Count 25 (+ 9) % Row 25 \SetRowColor{white} void mpz\_mfac\_uiui (mpz\_t rop, unsigned long int n, unsigned long int m) & Set rop to the factorial of n: mpz\_fac\_ui computes the plain factorial n!, mpz\_2fac\_ui computes the double-factorial n!!, and mpz\_mfac\_uiui the m-multi-factorial n!\textasciicircum{}(m). \tn % Row Count 34 (+ 9) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Number Theoretic Functions (cont)}} \tn % Row 26 \SetRowColor{LightBackground} void mpz\_primorial\_ui (mpz\_t rop, unsigned long int n) & Set rop to the primorial of n, i.e. the product of all positive prime numbers \textless{}=n. \tn % Row Count 5 (+ 5) % Row 27 \SetRowColor{white} void mpz\_bin\_ui (mpz\_t rop, const mpz\_t n, unsigned long int k) & Compute the binomial coefficient n over k and store the result in rop. Negative values of n are supported by mpz\_bin\_ui, using the identity bin(-n,k) = (-1)\textasciicircum{}k * bin(n+k-1,k), see Knuth volume 1 section 1.2.6 part G. \tn % Row Count 16 (+ 11) % Row 28 \SetRowColor{LightBackground} void mpz\_bin\_uiui (mpz\_t rop, unsigned long int n, unsigned long int k) & Compute the binomial coefficient n over k and store the result in rop. Negative values of n are supported by mpz\_bin\_ui, using the identity bin(-n,k) = (-1)\textasciicircum{}k * bin(n+k-1,k), see Knuth volume 1 section 1.2.6 part G. \tn % Row Count 27 (+ 11) % Row 29 \SetRowColor{white} void mpz\_fib\_ui (mpz\_t fn, unsigned long int n) & mpz\_fib\_ui sets fn to to F{[}n{]}, the n'th Fibonacci number. mpz\_fib2\_ui sets fn to F{[}n{]}, and fnsub1 to F{[}n-1{]}. \tn % Row Count 33 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Number Theoretic Functions (cont)}} \tn % Row 30 \SetRowColor{LightBackground} void mpz\_fib2\_ui (mpz\_t fn, mpz\_t fnsub1, unsigned long int n) & mpz\_fib\_ui sets fn to to F{[}n{]}, the n'th Fibonacci number. mpz\_fib2\_ui sets fn to F{[}n{]}, and fnsub1 to F{[}n-1{]}. \tn % Row Count 6 (+ 6) % Row 31 \SetRowColor{white} & These functions are designed for calculating isolated Fibonacci numbers. When a sequence of values is wanted it's best to start with mpz\_fib2\_ui and iterate the defining F{[}n+1{]}=F{[}n{]}+F{[}n-1{]} or similar. \tn % Row Count 17 (+ 11) % Row 32 \SetRowColor{LightBackground} void mpz\_lucnum\_ui (mpz\_t ln, unsigned long int n) & mpz\_lucnum\_ui sets ln to to L{[}n{]}, the n'th Lucas number. mpz\_lucnum2\_ui sets ln to L{[}n{]}, and lnsub1 to L{[}n-1{]}. \tn % Row Count 23 (+ 6) % Row 33 \SetRowColor{white} void mpz\_lucnum2\_ui (mpz\_t ln, mpz\_t lnsub1, unsigned long int n) & mpz\_lucnum\_ui sets ln to to L{[}n{]}, the n'th Lucas number. mpz\_lucnum2\_ui sets ln to L{[}n{]}, and lnsub1 to L{[}n-1{]}. \tn % Row Count 29 (+ 6) % Row 34 \SetRowColor{LightBackground} & These functions are designed for calculating isolated Lucas numbers. When a sequence of values is wanted it's best to start with mpz\_lucnum2\_ui and iterate the defining L{[}n+1{]}=L{[}n{]}+L{[}n-1{]} or similar. \tn % Row Count 40 (+ 11) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Integer Number Theoretic Functions (cont)}} \tn % Row 35 \SetRowColor{LightBackground} & The Fibonacci numbers and Lucas numbers are related sequences, so it's never necessary to call both mpz\_fib2\_ui and mpz\_lucnum2\_ui. The formulas for going from Fibonacci to Lucas can be found in Lucas Numbers Algorithm, the reverse is straightforward too. \tn % Row Count 13 (+ 13) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}