超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<aspell_suggestbcadd>
Last updated: Fri, 22 Jun 2007

IV. BCMath 任意精度数学函数库

简介

PHP 为任意精度数学计算提供了二进制计算器 (Binary Calculator),他支持任意大小和精度的数字,以字符串形式描述。

需求

自 PHP 4.0.4 以来,libbcmath 都绑定在 PHP 内部。这个扩展不需要其它外部库的支持。

安装

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



add a note add a note User Contributed Notes
BCMath 任意精度数学函数库
benjcarson at digitaljunkies ca
08-Jul-2002 07:17
Note that bcmath doesn't seem to handle numbers in exponential notation (i.e. "1e4"), although PHP considers such a value a number.

example:

$exp1 = "1E5";
$exp2 = "2E4";
$ans1 = bcadd($exp1, $exp2, 3);
$ans2 = $exp1 + exp2;
echo("bcadd: $exp1 + $exp2 = $ans1");
echo("php: $exp1 + $exp2 = $ans2");

// Output:
bcadd: 1E5 + 2E4 = 0.000
php: 1E5 + 2E4 = 120000

Just a gotcha if you're using passing PHP numbers into bcmath functions...

<aspell_suggestbcadd>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22