BC (Arbitrary Precision) Functions
These BC functions are only available if PHP was compiled with the --enable-bcmath configure option.
BC (Arbitrary Precision) Functions
bcadd
Name
bcadd — Add two arbitrary precision numbers.
Description
string bcadd(string left operand, string right operand, int [scale]);
Adds the left operand to the right operand and returns the sum in a string. The optional
scale parameter is used to set the number of digits after the decimal place in the result. See also bcsub.
bccomp
Name
bccomp — Compare two arbitrary precision numbers.
Description
bcdiv
int bccomp(string left operand, string right operand, int [scale]);
Compares the left operand to the right operand and returns the result as an integer. The optional scale parameter is used to set the number of digits after the decimal place which will be used in the comparion. The return value is 0 if the two operands are equal. If the left operand is larger than the right operand the return value is +1 and if the left operand is less than the right operand the return value is -1.
Name
bcdiv — Divide two arbitrary precision numbers.
Description
string bcdiv(string left operand, string right operand, int [scale]);
Divides the left operand by the right operand and returns the result. The optional scale
sets the number of digits after the decimal place in the result. See also bcmul.
bcmod
Name
bcmod — Get modulus of an arbitrary precision number.
Description
string bcmod(string left operand, string modulus);
Get the modulus of the left operand using modulus. See also bcdiv.
bcmul
Name
bcmul — Multiply two arbitrary precision number.
Description
string bcmul(string left operand, string right operand, int [scale]);
Multiply the left operand by the right operand and returns the result. The optional scale
sets the number of digits after the decimal place in the result. See also bcdiv.
bcpow
Name
bcpow — Raise an arbitrary precision number to another.
Description
string bcpow(string x, string y, int [scale]);
Raise x to the power y. The scale can be used to set the number of digits after the decimal place in the result.
See also bcsqrt.
bcscale
Name
bcscale — Set default scale parameter for all bc math functions.
Description
string bcscale(int scale);
This function sets the default scale parameter for all subsequent bc math functions that do not explicitly specify a scale parameter.
bcsqrt
Name
bcsqrt — Get the square root of an arbitray precision number.
Description
string bcsqrt(string operand, int scale);
Return the square root of the operand. The optional scale parameter sets the number of digits after the decimal place in the result.
See also bcpow.
bcsub
Name
bcsub — Subtract one arbitrary precision number from another.
Description
string bcsub(string left operand, string right operand, int [scale]);
Subtracts the right operand from the left operand and returns the result in a string. The optional scale parameter is used to set the number of digits after the decimal place in the result.
See also bcadd.