note 69635 deleted from language.operators.arithmetic by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:05:39 +0000 |
| Subject: | note 69635 deleted from language.operators.arithmetic by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189808@lists.php.net to get a copy of this message | ||
Note Submitter: mdirks at gulfstreamcoach dot com
----
Quote from TChan's post:
"...But if you're dealing with ints anyway, (a-a%b)/b has no function calls and returns an
int, while floor() always returns a float."
It *explicitly* says in the documentation that the division operator *always* returns a float value
*regardless* of the types of the operands. While you may get the "integer part" of the
number that way you will technically not get an integer. PHP may not be too strongly typed for the
most part, but it's important to make the distinction.
"... if the 'fractional part' of $a/$b is close to 1, then it can round up, and
floor($a/$b) will be larger than it should be."
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.