BCMath高精度数学类¶
各参数可以是字符串,也可以是原值。
由于精度问题,建议参数都以字符串形式传递。
| 属性 | 值 |
|---|---|
| 命名空间 | fize\math |
| 类名 | Bc |
| 方法: |
|---|
| 方法名 | 说明 |
|---|---|
| add() | 返回2个任意精度数字的加法计算,返回字符串结果 |
| adds() | 累加多个任意精度数字的加法计算 |
| comp() | 把right_operand和left_operand作比较, 并且返回一个整数的结果. |
| div() | 2个任意精度的数字除法计算 |
| mod() | 对一个任意精度数字取模 |
| mul() | 2个任意精度数字乘法计算 |
| muls() | 多个任意精度数字的乘法法计算,返回字符串结果 |
| pow() | 任意精度数字的乘方 |
| powmod() | 对乘方结果进行取模 |
| scale() | 设置所有bc数学函数的默认小数点保留位数 |
| sqrt() | 任意精度数字的二次方根 |
| sub() | 2个任意精度数字的减法 |
方法¶
add()¶
返回2个任意精度数字的加法计算,返回字符串结果
public static function add (
mixed $left_operand,
mixed $right_operand,
int $scale = null
) : string
| 参数: |
|
|---|
adds()¶
累加多个任意精度数字的加法计算
public static function adds (
array $operands,
int $scale = null
) : string
| 参数: |
|
|---|
comp()¶
把right_operand和left_operand作比较, 并且返回一个整数的结果.
public static function comp (
mixed $left_operand,
mixed $right_operand,
int $scale = null
) : int
| 参数: |
|
||||||||
|---|---|---|---|---|---|---|---|---|---|
| 返回值: | 如果两个数相等返回0, 左边的数left_operand比较右边的数right_operand大返回1, 否则返回-1. |
div()¶
2个任意精度的数字除法计算
public static function div (
mixed $left_operand,
mixed $right_operand,
int $scale = null
) : string
| 参数: |
|
||||||||
|---|---|---|---|---|---|---|---|---|---|
| 返回值: | 返回结果为字符串类型的结果,如果右操作数是0结果为null |
mod()¶
对一个任意精度数字取模
public static function mod (
mixed $left_operand,
mixed $modulus
) : string
| 参数: |
|
||||||
|---|---|---|---|---|---|---|---|
| 返回值: | 返回字符串类型取模后结果,如果系数为0则返回null |
mul()¶
2个任意精度数字乘法计算
public static function mul (
mixed $left_operand,
mixed $right_operand,
int $scale = null
) : string
| 参数: |
|
||||||||
|---|---|---|---|---|---|---|---|---|---|
| 返回值: | 返回计算结果字符串 |
muls()¶
多个任意精度数字的乘法法计算,返回字符串结果
public static function muls (
array $operands,
int $scale = null
) : string
| 参数: |
|
|---|
pow()¶
任意精度数字的乘方
public static function pow (
mixed $left_operand,
mixed $right_operand,
int $scale = null
) : string
| 参数: |
|
|---|
powmod()¶
对乘方结果进行取模
public static function powmod (
mixed $left_operand,
mixed $right_operand,
mixed $modulus,
int $scale = null
) : string
| 参数: |
|
|---|
scale()¶
设置所有bc数学函数的默认小数点保留位数
public static function scale (
int $scale
) : bool
| 参数: |
|
||||
|---|---|---|---|---|---|
| 返回值: | 成功时返回 TRUE , 或者在失败时返回 FALSE |
sqrt()¶
任意精度数字的二次方根
public static function sqrt (
mixed $operand,
int $scale = null
) : string
| 参数: |
|
|---|
sub()¶
2个任意精度数字的减法
public static function sub (
mixed $left_operand,
mixed $right_operand,
int $scale = null
) : string
| 参数: |
|
|---|