note 74737 deleted from language.operators.arithmetic by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:06:24 +0000 |
| Subject: | note 74737 deleted from language.operators.arithmetic by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189813@lists.php.net to get a copy of this message | ||
Note Submitter: T Chan
----
"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.