note 74737 added to language.operators.arithmetic
| From: | TChan at osu1 dot php dot net | Date: | Wed, 25 Apr 2007 20:10:15 +0000 |
| Subject: | note 74737 added to language.operators.arithmetic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125863@lists.php.net to get a copy of this message | ||
"It *explicitly* says in the documentation that the division operator *always* returns a float
value *regardless* of the types of the operands."
Documentation is not always right. See http://uk.php.net/manual/en/language.operators.arithmetic.php#49371
"Actually I think you meant *smaller*, not larger... the reason floor($a/$b) isn't
absolutely equatable with the integer division of $a and $b is explained mainly at http://us3.php.net/float . By the look of things, any number
with a loss of precision will be truncated instead of rounded. This would at least make sense in the
big picture since truncation is more consistant than rounding."
No. The people who wrote IEEE 754 made the default rounding mode round-to-nearest, because it tends
to give a more accurate result. To illustrate, if the true value of a/b is (say)
3.9999999999999999999, this will be rounded up to 4. Then, floor(4) = 4, whereas the true value is
3.
That said, it depends on (at least) the particular version of PHP you're running. PHP
doesn't guarantee anything - it can use whatever approximate floating point implementation it
likes.
----
Server IP: 194.145.210.3
Probable Submitter: 131.111.8.98 (proxied: 131.111.244.99)
----
Manual Page -- http://www.php.net/manual/en/language.operators.arithmetic.php
Edit -- https://master.php.net/note/edit/74737
Del: integrated -- https://master.php.net/note/delete/74737/integrated
Del: useless -- https://master.php.net/note/delete/74737/useless
Del: bad code -- https://master.php.net/note/delete/74737/bad+code
Del: spam -- https://master.php.net/note/delete/74737/spam
Del: non-english -- https://master.php.net/note/delete/74737/non-english
Del: in docs -- https://master.php.net/note/delete/74737/in+docs
Del: other reasons-- https://master.php.net/note/delete/74737
Reject -- https://master.php.net/note/reject/74737
Search -- https://master.php.net/manage/user-notes.php