note 103525 added to language.operators.arithmetic
| From: | php at richardneill dot org | Date: | Mon, 18 Apr 2011 15:13:23 +0000 |
| Subject: | note 103525 added to language.operators.arithmetic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178944@lists.php.net to get a copy of this message | ||
For larger numbers (above PHP_INT_MAX), use fmod() rather than %.
The other operators (+-*/) work correctly with floats and integer overflow, but % uses integer wrap.
Eg.
var_dump(0xffffffff % 2);
//Prints int(-1) which is WRONG
var_dump(intval(fmod(0xffffffff,2)));
//Prints int(1) which is the right answer
(The reason this matters is that PHP's float is actually a double, and can accurately represent
integers up to 52-bits, even on 32-bit systems)
----
Server IP: 92.48.74.199
Probable Submitter: 87.194.171.29
----
Manual Page -- http://www.php.net/manual/en/language.operators.arithmetic.php
Edit -- https://master.php.net/note/edit/103525
Del: integrated -- https://master.php.net/note/delete/103525/integrated
Del: useless -- https://master.php.net/note/delete/103525/useless
Del: bad code -- https://master.php.net/note/delete/103525/bad+code
Del: spam -- https://master.php.net/note/delete/103525/spam
Del: non-english -- https://master.php.net/note/delete/103525/non-english
Del: in docs -- https://master.php.net/note/delete/103525/in+docs
Del: other reasons-- https://master.php.net/note/delete/103525
Reject -- https://master.php.net/note/reject/103525
Search -- https://master.php.net/manage/user-notes.php