Re: [VOTE][RFC] intdiv()
| From: | Andrea Faulds | Date: | Sun, 03 Aug 2014 14:31:28 +0000 |
| Subject: | Re: [VOTE][RFC] intdiv() | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-76323@lists.php.net to get a copy of this message | ||
On 3 Aug 2014, at 15:27, Lester Caine <lester@lsces.co.uk> wrote:
> Your missing the point I was trying to make. That "(int)(3 / 2)"
> essentially goes wrong only on 64bit systems is the bug that needs
> fixing.
(int)(3 / 2) works fine, (int)(PHP_INT_MAX / 3) does not.
It’s not a bug, it’s entirely intentional and expected behaviour. You’re doing a
floating-point division then casting to integer, which will sometimes lead to a loss of precision.
And no, having a division wrapped in (int) work differently from a normal division isn’t a good
idea. That means the operator acts differently based on context. It would mean $a = PHP_INT_MAX / 3;
$a = (int)$a; would do something entirely different from $a = (int)(PHP_INT_MAX / 3);
--
Andrea Faulds
http://ajf.me/