note 95362 deleted from ref.bc by danbrown
| From: | danbrown@php.net | Date: | Thu, 31 Dec 2009 16:38:20 +0000 |
| Subject: | note 95362 deleted from ref.bc by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164500@lists.php.net to get a copy of this message | ||
Note Submitter: Markus Wichmann
----
In reference to the factorial function posted previously: A recursive solution is almost any time
worse than an iterative one. Plus, in this case it is easy to provide such a solution:
<?php
bcfact($x) {
$res = 1;
for ($i = $x; bccomp($i, '0') == 1; bcsub($i, '1')) {
$res = bcmul($res, $i);
}
return $res;
}
?>