note 99875 added to function.gmp-fact
| From: | ghsot at ghost-tech dot com dot au | Date: | Sun, 12 Sep 2010 05:13:00 +0000 |
| Subject: | note 99875 added to function.gmp-fact | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172490@lists.php.net to get a copy of this message | ||
Alternative method of calculating factorials.
<?php
function fact($n){
if($n > 170){return 0;} //This function can only calculate the factorial of numbers below 171
$i = $a = 1;
while ($i<=$n){
$a = $a * $i;
$i++;
}
$a = sprintf('%f', $a); //Convert from Scientific notation
return substr($a, 0, -7); //Remove the trailing decimal places
}
echo fact(171); //Returns 0
echo "<br />";
echo fact(12); //Returns 479001600
?>
----
Server IP: 117.55.229.1
Probable Submitter: 110.175.5.221
----
Manual Page -- http://www.php.net/manual/en/function.gmp-fact.php
Edit -- https://master.php.net/note/edit/99875
Del: integrated -- https://master.php.net/note/delete/99875/integrated
Del: useless -- https://master.php.net/note/delete/99875/useless
Del: bad code -- https://master.php.net/note/delete/99875/bad+code
Del: spam -- https://master.php.net/note/delete/99875/spam
Del: non-english -- https://master.php.net/note/delete/99875/non-english
Del: in docs -- https://master.php.net/note/delete/99875/in+docs
Del: other reasons-- https://master.php.net/note/delete/99875
Reject -- https://master.php.net/note/reject/99875
Search -- https://master.php.net/manage/user-notes.php