Introducción
These functions allow you to work with arbitrary_length integers
using the GNU MP library_
These functions have been added in PHP 4_0_4_
Nota:
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 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 gmp_init() function_
| Aviso |
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 GMP
comes into play_
|
Nota: Esta
extensión no está disponible en plataformas
Windows
Requerimientos
You can download the GMP library from http://www_swox_com/gmp/_ This site also has the
GMP manual available_
You will need GMP version 2 or better to use these functions_ Some
functions may require more recent version of the GMP library_
Instalación
In order to have these functions available, you must compile PHP with
GMP support by using the __with_gmp option_
Configuración en tiempo de
ejecución
Esta extensión no tiene directivas de
configuración en php_ini_
Tipos de recursos
Esta extensión no tiene
ningún tipo de recurso definido_
Constantes predefinidas
Estas constantes están
definidas por esta extensión y estarán disponibles
solamente cuando la extensión ha sido o bien compilada dentro
de PHP o grabada dinámicamente en tiempo de ejecución_
Ejemplos
Ejemplo 1_ Factorial function using GMP <?php
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 factorial of 1000 (pretty big number)
very fast_