PHP 手冊
上一頁 |  | 下一頁

# XXXVIII.GMP Functions

# 介紹

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.

> 備注: 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.

切記!
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.

> 備注:此延伸不適用於 Windows 平台。

# 需求

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.

# 安裝

In order to have these functions available, you must compile PHP with GMP support by using the --with-gmp option.

# 執行時期組態

`php.ini`中沒有定義此延伸的組態指令。

# 資源類型

這個延伸沒有定義任何資源。

# 預先定義常數

以下的常數由此延伸定義，只在這個延伸被編譯成PHP或實行時期被動態載入時有效。

`GMP_ROUND_ZERO` (integer)

`GMP_ROUND_PLUSINF` (integer)

`GMP_ROUND_MINUSINF` (integer)

# 範例

示範 1.Factorial function using GMP

`<?php function fact($x) { if ($x <= 1) { return 1; } else { return gmp_mul($x, fact($x-1)); } } echo gmp_strval(fact(1000)) . "\n"; ?>`

This will calculate factorial of 1000 (pretty big number) very fast.

# 參考

More mathematical functions can be found in the sections BCMath Arbitrary Precision Mathematics Functions and Mathematical Functions.

上一頁 | 最開頭 | 下一頁
textdomain | 上一層 | gmp_abs