BC Extra is a library of functions that work in PHP's BC Math. BC Math allows arbitrary precision arithmetic on values represented as strings, but only includes basic mathematical functions. This library adds several additional functions:


The functions of this library are pretty straight forward. Detailed documentation is available online, generated from the source code using phpDocumentor. The documentation can be recreated from the source if needed.


Download 'bcextra.php'

User comments

From Andrew Que (http://www.DrQue.net)

Middleton, WI

March 12, 2015 at 10:54 PM

Leave a comment if you find this library useful.

From Marcos


August 16, 2017 at 6:32 PM

Hi Andrew!

First of all, thank you for sharing such a fantastic library. I've been working with high precise numbers in PHP for the last months, and your library is impressive fast when compared to other libraries with the same purpose. Congratulations!

I'm writing because I found some issues when computing the power of numbers using fractional exponents. The algorithm relies on the formula x ^ y = exp(y * log (x))  to calculate exponentiation. My guess is that the problem is related to estimating the scale needed for precisely computing the result up to a given scale.

I'm trying to fix it because the application I'm working on requires accurate results. If you have any guess about how to compute it, please let me know, it will help a lot.


// Expected: 310472657364304703.652201517571826032805777140298

// Result: 310472657364304703.652201517571826028599733563396

bcpow('9223372036854775807', '0.9223372036854775807', 25)

Thank you again.

- Marcos

From Murat Karagöz


August 02, 2018 at 3:01 AM

echo bcsin(90); gives  1.39    .It is wrong. It has to give 1            Secondly, write bcscale( $scale + 5 );  right after function bccos() ,because it gives error.


BC Extra is is free, open-source software released under the GNU license.


BC Extra is written and maintained by Andrew Que. To get in touch with Andrew Que, visit his contact page.