PHP4.04 增加了对无限精度运算的支持_PHP教程

WBOY
풀어 주다: 2016-07-13 17:21:20
원래의
915명이 탐색했습니다.

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.
通过 GUN MP 库,这些函数允许你使用任意长度的整数。你需要编译 php 时使用 --with-gmp 参数

You can download the GMP library from http://www.swox.com/gmp/. This site also has the GMP manual available.
你可以从 http://www.swox.com/gmp/ 下载 GMP 库,同时有手册。

You will need GMP version 2 or better to use these functions. Some functions may require more recent version of the GMP library.
你需要 GMP 2.0 或更好的来使用这些函数。某些函数可能需要最新的 GMP库

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.
注意:大多数 GMP 函数接受下面资源定义的 GMP 数值参数,当然,大多数函数也接受数字和字符串参数,但是会被转化为数字。同时,如果存在更快的函数来操作整形参数,则会使用那个更快的函数来操作整数。这是当然的,所以你可以在需要 GMP 数字的地方用整数参数。

Example 1. Factorial function using GMP

function fact ($x) {
if ($x 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.



www.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...
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿