note 76231 added to language.operators.arithmetic
| From: | nicolas_rainard_NOSPAM at yahoo dot fr | Date: | Fri, 06 Jul 2007 11:08:34 +0000 |
| Subject: | note 76231 added to language.operators.arithmetic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128264@lists.php.net to get a copy of this message | ||
gilthansREMOVEME at gmail dot com proposed a nice integer division function, but its speed greatly
depends on the size difference between the two provided numbers. If the first number is very big and
the second one is very small, this function will take a (relative) long time to resolve (because of
the loop).
Here is another integer division function, wich always takes the same time to resolve, what ever the
provided numbers are. In most cases, it will be faster, but if the numbers are close, the other one
will be twice as fast. It's up to you to choose one of these functions, depending on the
expected input numbers...
function int_divide($x, $y) {
if ($x == 0) return 0;
if ($y == 0) return FALSE;
$result = $x/$y;
$pos = strpos($result, '.');
if (!$pos) {
return $result;
} else {
return (int) substr($result, 0, $pos);
}
}
----
Server IP: 217.174.196.197
Probable Submitter: 90.31.3.94
----
Manual Page -- http://www.php.net/manual/en/language.operators.arithmetic.php
Edit -- https://master.php.net/note/edit/76231
Del: integrated -- https://master.php.net/note/delete/76231/integrated
Del: useless -- https://master.php.net/note/delete/76231/useless
Del: bad code -- https://master.php.net/note/delete/76231/bad+code
Del: spam -- https://master.php.net/note/delete/76231/spam
Del: non-english -- https://master.php.net/note/delete/76231/non-english
Del: in docs -- https://master.php.net/note/delete/76231/in+docs
Del: other reasons-- https://master.php.net/note/delete/76231
Reject -- https://master.php.net/note/reject/76231
Search -- https://master.php.net/manage/user-notes.php