Forum und email

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.

安裝

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 的影響。

BC math configuration options
Name Default Changeable Changelog
bcmath.scale "0" PHP_INI_ALL  
有關 PHP_INI_* 常數進一步的細節與定義參見php.ini directives

以下是設定選項的簡要解釋。

bcmath.scale integer

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

資源類型

本擴充功能未定義任何資源類型。

預設常數

本擴充功能未定義任何常數。

Table of Contents

  • 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