note 14945 added to language.types.integer.php
| From: | carl at NOSPAM dot thep dot lu dot se | Date: | Wed, 22 Aug 2001 09:51:42 +0000 |
| Subject: | note 14945 added to language.types.integer.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-16979@lists.php.net to get a copy of this message | ||
One note about integer division:
PHP of course has the << and >> operators, so as long as you need to do integer division
by a power of 2 you can just shift to the right.
However, as the floating point numbers are 64-bit rather than 32-bit all possible values for a
32-bit int can be represented exactly by a float, so there is no risk of rounding errors when doing
(int)(n1/n2).
The overhead of converting to float and back can probably be ignored for an interpreted language
like PHP, unless the engine is insanely optimized. (Testing confirms that $a/$b takes only
marginally longer than $a>>$b and $a*$b for integers $a and $b.)
http://www.php.net/manual/en/language.types.integer.php