note 76887 added to language.operators.arithmetic
| From: | thookerovA at Tgmaildotcom | Date: | Fri, 03 Aug 2007 21:58:24 +0000 |
| Subject: | note 76887 added to language.operators.arithmetic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129159@lists.php.net to get a copy of this message | ||
To the comment from nicholas_rainard: Your function is much more efficient, but should probably be
combined with the first two lines from the function prior to yours:
function int_divide($x, $y) {
if ($x == 0) return 0;
if ($y == 0) return FALSE;
return ($x - ($x % $y)) / $y;
}
Permits for zero in either argument. Also, this always returns the floor of the division. Probably
seems obvious to most, but it didn't to me at first. Maybe a rounding function would look like:
function up_or_dn($x, $y) {
if ($x == 0) return 0;
if ($y == 0) return FALSE;
return ($x % $y >= $y / 2) ?
(($x - ($x % $y)) / $y) + 1 : ($x - ($x % $y)) / $y;
}
Adds 1 if the mod result is more than half $y (which if my math is right means the float result is
.5+, so round up).
Simplest example: $x = 3, $y = 2.
----
Server IP: 208.69.120.35
Probable Submitter: 209.172.8.80
----
Manual Page -- http://www.php.net/manual/en/language.operators.arithmetic.php
Edit -- https://master.php.net/note/edit/76887
Del: integrated -- https://master.php.net/note/delete/76887/integrated
Del: useless -- https://master.php.net/note/delete/76887/useless
Del: bad code -- https://master.php.net/note/delete/76887/bad+code
Del: spam -- https://master.php.net/note/delete/76887/spam
Del: non-english -- https://master.php.net/note/delete/76887/non-english
Del: in docs -- https://master.php.net/note/delete/76887/in+docs
Del: other reasons-- https://master.php.net/note/delete/76887
Reject -- https://master.php.net/note/reject/76887
Search -- https://master.php.net/manage/user-notes.php