<HTML ><HEAD ><TITLE >GMP functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Function Reference" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="textdomain" HREF="function.textdomain.html"><LINK REL="NEXT" TITLE="gmp_abs" HREF="function.gmp-abs.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.textdomain.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.gmp-abs.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.gmp" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >XXXVI. GMP functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN29633" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="gmp.intro" ></A >Introduction</H1 ><P > These functions allow you to work with arbitrary-length integers using the GNU <SPAN CLASS="acronym" >MP</SPAN > library. </P ><P > These functions have been added in PHP 4.0.4. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Most GMP functions accept GMP number arguments, defined as <TT CLASS="literal" >resource</TT > below. However, most of these functions will also accept numeric and string arguments, given that it is possible to convert the latter to a number. Also, if there is a faster function that can operate on integer arguments, it would be used instead of the slower function when the supplied arguments are integers. This is done transparently, so the bottom line is that you can use integers in every function that expects GMP number. See also the <A HREF="function.gmp-init.html" ><B CLASS="function" >gmp_init()</B ></A > function. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Warning</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > If you want to explicitly specify a large integer, specify it as a string. If you don't do that, PHP will interpret the integer-literal first, possibly resulting in loss of precision, even before <TT CLASS="literal" >GMP</TT > comes into play. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B >This extension is not available on Windows platforms.</P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="gmp.requirements" ></A >Requirements</H1 ><P > You can download the <SPAN CLASS="acronym" >GMP</SPAN > library from <A HREF="http://www.swox.com/gmp/" TARGET="_top" >http://www.swox.com/gmp/</A >. This site also has the <SPAN CLASS="acronym" >GMP</SPAN > manual available. </P ><P > You will need GMP version 2 or better to use these functions. Some functions may require more recent version of the GMP library. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="gmp.installation" ></A >Installation</H1 ><P > In order to have these functions available, you must compile PHP with <SPAN CLASS="acronym" >GMP</SPAN > support by using the <TT CLASS="option" >--with-gmp</TT > option. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="gmp.configuration" ></A >Runtime Configuration</H1 ><P >This extension has no configuration directives defined in <TT CLASS="filename" >php.ini</TT >.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="gmp.resources" ></A >Resource Types</H1 ><P >This extension has no resource types defined.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="gmp.constants" ></A >Predefined Constants</H1 ><P > The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime. </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >GMP_ROUND_ZERO</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >GMP_ROUND_PLUSINF</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >GMP_ROUND_MINUSINF</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="gmp.examples" ></A >Examples</H1 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN29692" ></A ><P ><B >Example 1. Factorial function using GMP</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function fact ($x) { if ($x <= 1) return 1; else return gmp_mul ($x, fact ($x-1)); } print gmp_strval (fact (1000)) . "\n"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > This will calculate factorial of 1000 (pretty big number) very fast. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="gmp.seealso" ></A >See Also</H1 ><P > More mathmatical functions can be found in the sections <A HREF="ref.bc.html" >BCMath Arbitrary Precision Mathematics Functions</A > and <A HREF="ref.math.html" >Mathematical Functions</A >. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="function.gmp-abs.html" >gmp_abs</A > -- Absolute value</DT ><DT ><A HREF="function.gmp-add.html" >gmp_add</A > -- Add numbers</DT ><DT ><A HREF="function.gmp-and.html" >gmp_and</A > -- Logical AND</DT ><DT ><A HREF="function.gmp-clrbit.html" >gmp_clrbit</A > -- Clear bit</DT ><DT ><A HREF="function.gmp-cmp.html" >gmp_cmp</A > -- Compare numbers</DT ><DT ><A HREF="function.gmp-com.html" >gmp_com</A > -- Calculates one's complement of a</DT ><DT ><A HREF="function.gmp-div-q.html" >gmp_div_q</A > -- Divide numbers</DT ><DT ><A HREF="function.gmp-div-qr.html" >gmp_div_qr</A > -- Divide numbers and get quotient and remainder</DT ><DT ><A HREF="function.gmp-div-r.html" >gmp_div_r</A > -- Remainder of the division of numbers</DT ><DT ><A HREF="function.gmp-div.html" >gmp_div</A > -- Divide numbers</DT ><DT ><A HREF="function.gmp-divexact.html" >gmp_divexact</A > -- Exact division of numbers</DT ><DT ><A HREF="function.gmp-fact.html" >gmp_fact</A > -- Factorial</DT ><DT ><A HREF="function.gmp-gcd.html" >gmp_gcd</A > -- Calculate GCD</DT ><DT ><A HREF="function.gmp-gcdext.html" >gmp_gcdext</A > -- Calculate GCD and multipliers</DT ><DT ><A HREF="function.gmp-hamdist.html" >gmp_hamdist</A > -- Hamming distance</DT ><DT ><A HREF="function.gmp-init.html" >gmp_init</A > -- Create GMP number</DT ><DT ><A HREF="function.gmp-intval.html" >gmp_intval</A > -- Convert GMP number to integer</DT ><DT ><A HREF="function.gmp-invert.html" >gmp_invert</A > -- Inverse by modulo</DT ><DT ><A HREF="function.gmp-jacobi.html" >gmp_jacobi</A > -- Jacobi symbol</DT ><DT ><A HREF="function.gmp-legendre.html" >gmp_legendre</A > -- Legendre symbol</DT ><DT ><A HREF="function.gmp-mod.html" >gmp_mod</A > -- Modulo operation</DT ><DT ><A HREF="function.gmp-mul.html" >gmp_mul</A > -- Multiply numbers</DT ><DT ><A HREF="function.gmp-neg.html" >gmp_neg</A > -- Negate number</DT ><DT ><A HREF="function.gmp-or.html" >gmp_or</A > -- Logical OR</DT ><DT ><A HREF="function.gmp-perfect-square.html" >gmp_perfect_square</A > -- Perfect square check</DT ><DT ><A HREF="function.gmp-popcount.html" >gmp_popcount</A > -- Population count</DT ><DT ><A HREF="function.gmp-pow.html" >gmp_pow</A > -- Raise number into power</DT ><DT ><A HREF="function.gmp-powm.html" >gmp_powm</A > -- Raise number into power with modulo</DT ><DT ><A HREF="function.gmp-prob-prime.html" >gmp_prob_prime</A > -- Check if number is "probably prime"</DT ><DT ><A HREF="function.gmp-random.html" >gmp_random</A > -- Random number</DT ><DT ><A HREF="function.gmp-scan0.html" >gmp_scan0</A > -- Scan for 0</DT ><DT ><A HREF="function.gmp-scan1.html" >gmp_scan1</A > -- Scan for 1</DT ><DT ><A HREF="function.gmp-setbit.html" >gmp_setbit</A > -- Set bit</DT ><DT ><A HREF="function.gmp-sign.html" >gmp_sign</A > -- Sign of number</DT ><DT ><A HREF="function.gmp-sqrt.html" >gmp_sqrt</A > -- Square root</DT ><DT ><A HREF="function.gmp-sqrtrm.html" >gmp_sqrtrm</A > -- Square root with remainder</DT ><DT ><A HREF="function.gmp-strval.html" >gmp_strval</A > -- Convert GMP number to string</DT ><DT ><A HREF="function.gmp-sub.html" >gmp_sub</A > -- Subtract numbers</DT ><DT ><A HREF="function.gmp-xor.html" >gmp_xor</A > -- Logical XOR</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.textdomain.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.gmp-abs.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >textdomain</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >gmp_abs</TD ></TR ></TABLE ></DIV ></BODY ></HTML >