Thesefunctionsallowyoutoworkwitharbitrary-lengthintegersusingtheGNUMPlibrary.Inordertohavethesefunctionsavailable, youmustcompilePHPwithGMPsupportbyusingthe -- wit These functions allow you to work with arbitrary-length integers using the gnu mp library. in order to have these functions available, you must compile PHP with GMP support by using the -- with-gmp option.
Through the gun mp library, these functions allow you to use integers of any length. Use the -- with-gmp parameter when compiling php
You can download the GMP library from http://www.swox.com/gmp/. This site also has the GMP manual available.
You can download the GMP library from the http://www.swox.com/gmp/ and have a manual at the same time.
You will need GMP version 2 or better to use these functions. Some functions may require more recent version of the GMP library.
You need GMP 2.0 or better to use these functions. Some functions may need the latest GMP Library
These functions have been added in PHP 4.0.4.
Note: Most GMP functions accept GMP number arguments, defined as resource 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 wocould 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 gmp_init () function.
Note: Most GMP functions accept the GMP numerical parameters defined by the following resources. of course, most functions also accept numbers and string parameters, but are converted to numbers. At the same time, if a faster function is used to operate integer parameters, the faster function is used to operate integers. This is of course, so you can use integer parameters where GMP numbers are needed.
Example 1. Factorial function using GMP
Function fact ($ x ){
If ($ x <= 1)
Return 1;
Else
Return gmp_mul ($ x, fact ($ X-1 ));
}
Print gmp_strval (fact (1000). "n ";
?>
This will calculate factiorial of 1000 (pretty big number) very fast.