PHP4.04 adds support for infinite precision operations_PHP Tutorial

WBOY
Release: 2016-07-13 17:21:20
Original
913 people have browsed it

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. MP library, these functions allow you to work with integers of arbitrary length. You need to 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 http://www.swox.com/gmp/. Download the GMP library, which also comes with a manual.

You will need GMP version 2 or better to use these functions. Some functions may require more recent version of the GMP library.

You will need GMP version 2 or better to use these functions. Some functions may require the latest GMP libraries

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 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.

Note: Most GMP functions accept GMP numeric parameters defined in the resource below. Of course, most functions also accept numeric and string parameters, but they will be converted to numbers. At the same time, if a faster function exists to operate on integer parameters, that faster function will be used to operate on integers. This is of course so you can use integer arguments wherever GMP numbers are required.

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.




http://www.bkjia.com/PHPjc/532488.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532488.htmlTechArticleThese 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 usin...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template