Arbitrary-Precision Numbers PHP

Doubles are usually sufficiently precise for any numerical analysis you may wish to perform. However, PHP offers a way to work with numbers of much higher precision. The functions in this section use strings to store very long floating-point numbers. They each use a scale value that is the number of digits to the right of the decimal point. The scale argument that appears in all of the functions is optional and will override the default scale.

These functions are activated when PHP is compiled. They are part of the binary distribution for windows, but they are not activated by default for other operating systems. If PHP reports these functions as being unrecognized, you may need to recompile PHP using the —enable-bcmath option.

integer bccomp(string left, string right, integer scale)
The bccomp function compares left to right. If they are equal, zero is returned. If left is less than right, -1 is returned. If left is greater than right, 1 is returned.

string bcmod(string left, string right)
The bcmod function finds the modulus of the division of left by right.

<?print(bcmod("66394593", "133347"));?>

string bcmul(string left, string right, integer scale)
Use bcmul to multiply the left argument and the right argument.

<?print(bcmul("66394593", "133347", 10));?>

string bcpow(string value, string exponent, integer scale)
The bcpow function raises the value argument to the power of the exponent argument. If the exponent is not an integer, the fractional part will be chopped off.