note 72578 added to function.exp

From: Date: Wed, 24 Jan 2007 23:13:12 +0000
Subject: note 72578 added to function.exp
Groups: php.notes 
Request: Send a blank email to php-notes+get-122166@lists.php.net to get a copy of this message
working version (checked) of below code is <?php // see bccomp for this code (signed and unsigned zero!) function bccomp_zero($amount) { return bccomp($amount, (@$amount{0}=="-"?'-':'').'0.0'); } // arbitrary precision function (x^n)/(n)! function bcpowfact($x, $n) { if (bccomp_zero($n) == 0) return '1'; if (bccomp($n, '1') == 0) return $x; $a = $x; // 1st step: a *= x / 1 $i = $n; while (bccomp($i, '1') == 1) { // ith step: a *= x / i $a = bcmul($a, bcdiv($x, $i)); $i = bcsub($i, '1'); // bc idiom for $i-- } return $a; } // arbitrary precision exp() function function bcexp($x, $digits) { $sum = $prev_sum = '0.0'; $error = '0.'.str_repeat('0', $digits-1).'1'; // 0.1*10^-k $n = '0.0'; do { $prev_sum = $sum; $sum = bcadd($sum, bcpowfact($x, $n)); $n = bcadd($n, '1'); // bc idiom for $n++ } while (bccomp(bcsub($sum, $prev_sum), $error) == 1); return $sum; } ?> ---- Server IP: 83.64.128.68 Probable Submitter: 212.87.13.71 (proxied: 10.1.234.242) ---- Manual Page -- http://www.php.net/manual/en/function.exp.php Edit -- https://master.php.net/note/edit/72578 Del: integrated -- https://master.php.net/note/delete/72578/integrated Del: useless -- https://master.php.net/note/delete/72578/useless Del: bad code -- https://master.php.net/note/delete/72578/bad+code Del: spam -- https://master.php.net/note/delete/72578/spam Del: non-english -- https://master.php.net/note/delete/72578/non-english Del: in docs -- https://master.php.net/note/delete/72578/in+docs Del: other reasons-- https://master.php.net/note/delete/72578 Reject -- https://master.php.net/note/reject/72578 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122166) next »