Note regarding the mathematical function exp(x):
To continue accuracy of the exponential function to an infinite amount of decimal places, one would use the power series definition for exp(x).
(in LaTeX form:)
e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!}
So, to do that in PHP (using BC math):
<?php
function bcpowfact($x, $n) {
if (bccomp($n, '0') == 0) return '1.0';
if (bccomp($n, '1') == 1) return $x;
$a = $x; $i = $n;
while (bccomp($i, '1') == 1) {
$a = bcmul($a, bcdiv($x, $i));
$i = bcsub($i, '1'); }
return $a;
}
function bcexp($x, $decimal_places) {
$sum = $prev_sum = '0.0';
$error = bcdiv(bcpow('10', '-'.$decimal_places), 10); $n = '0';
do {
$prev_sum = $sum;
$sum = bcadd($sum, bcpowfact($x, $n));
}
while (bccomp(bcsub($sum, $prev_sum), $error) == 1);
return $sum;
}
?>