IV. BCMath Arbitrary Precision Mathematics Functions

简介

For arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision, represented as strings.

需求

Since PHP 4.0.4, libbcmath is bundled with PHP. You don't need any external libraries for this extension.

安装

In PHP 4, these functions are only available if PHP was configured with --enable-bcmath. In PHP 3, these functions are only available if PHP was NOT configured with --disable-bcmath.

PHP 的 Windows 版本已经内置该扩展模块的支持。您无需加载任何附加的扩展库即可使用这些函数。

运行时配置

这些函数的行为受到全局配置文件 php.ini 的影响。

表格 1. BC math configuration options

NameDefaultChangeable
bcmath.scale0PHP_INI_ALL
For further details and definition of the PHP_INI_* constants see ini_set().

以下是该配置选项的简要解释。

bcmath.scale integer

Number of decimal digits for all bcmath functions. See also bcscale().

资源类型

该扩展模块未定义任何资源类型。

预定义常量

该扩展模块未定义任何常量。

目录
bcadd -- Add two arbitrary precision numbers
bccomp -- Compare two arbitrary precision numbers
bcdiv -- Divide two arbitrary precision numbers
bcmod --  Get modulus of an arbitrary precision number
bcmul -- Multiply two arbitrary precision number
bcpow --  Raise an arbitrary precision number to another
bcpowmod --  Raise an arbitrary precision number to another, reduced by a specified modulus.
bcscale --  Set default scale parameter for all bc math functions
bcsqrt --  Get the square root of an arbitrary precision number
bcsub --  Subtract one arbitrary precision number from another