note 84746 added to ref.math
| From: | rubo77 at spacetrace dot org | Date: | Mon, 28 Jul 2008 14:39:04 +0000 |
| Subject: | note 84746 added to ref.math | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-142852@lists.php.net to get a copy of this message | ||
<?php
function lcd($n,$m, $maxvarianzpercent=0){
// set $maxvarianzpercent=5 to get a small, but approx. result
/* a better lcd function with varianz:
for example use
lcd(141,180,5) to get the approx. lcd '7/9' which is in fact 140/180
*/
// ATTENTION!!! can be really slow if $m is >1000
$d=$n/$m;
$f=1;
while($d*$f!=intval($d*$f)){
$f++;
}
$r=($d*$f).'/'.$f;
if(($d*$f)<=10 or $f<=10) return $r;
else if($maxvarianzpercent>0){
$f=1;
while($d*$f!=intval($d*$f) and ($d*$f)-intval($d*$f) > $maxvarianzpercent/100){
$f++;
}
return intval($d*$f).'/'.$f;
} else return $r;
}
?>
----
Server IP: 79.132.192.3
Probable Submitter: 82.82.134.155
----
Manual Page -- http://www.php.net/manual/en/ref.math.php
Edit -- https://master.php.net/note/edit/84746
Del: integrated -- https://master.php.net/note/delete/84746/integrated
Del: useless -- https://master.php.net/note/delete/84746/useless
Del: bad code -- https://master.php.net/note/delete/84746/bad+code
Del: spam -- https://master.php.net/note/delete/84746/spam
Del: non-english -- https://master.php.net/note/delete/84746/non-english
Del: in docs -- https://master.php.net/note/delete/84746/in+docs
Del: other reasons-- https://master.php.net/note/delete/84746
Reject -- https://master.php.net/note/reject/84746
Search -- https://master.php.net/manage/user-notes.php