Re: [STANDARDS] Integer operations are implementation-defined
[email protected] (Drew Paroski)
| Newsgroups | php.standards |
|---|---|
| Message-ID | <CAF_a60qvAq_1rAKJ4sRX1=Z0Fc=uOMQY3CGpB62gLAotQ6w7xw@mail.gmail.com> |
On Fri, Aug 8, 2014 at 8:52 AM, Andrea Faulds <[email protected]> wrote: > > Thanks for sending your thoughts. > > If I might say it again, while PHP.net’s behaviour here is far from ideal, I > think it’s still much better than just wrapping around. It changes type, but > most of the information is preserved (sign, leading digits, magnitude). If > your number wraps around on overflow, all information is lost, and it’s not > even obvious anything went wrong. Basically, for naïvely-written apps, the > PHP.net behaviour will break them least and is the most intuitive. It’s far > from perfect and I’d love to use bigints or something, but until that > happens, I’d much rather overflow to float. Thanks for taking the time to further elaborate your position. If I'm hearing you correctly, the main points you're putting forth seem to be (1) int->float promotion is not as crappy as int wraparound for users, (2) there are a good number of use cases where the int->float promotion is what users want or what causes the least surprise for users, (3) the performance hit of having to support int->float promotion is minor, (4) this behavior has been around for a long time and while most apps don't depend on it, there are a small percentage that do, (5) the bigint RFC might never land, or it might not land for a while, and so in the meantime the spec should specify the existing php.net behavior that some apps in the wild currently rely on, and (6) given all the points above, it seems like a win to avoid making integer overflow an issue where users have to worry about different implementations doing different things. I think your argument makes a lot of sense. Thinking about the issue more, it seems like requiring int->float promotion on integer overflow is not unreasonable. My main concern was avoiding the slippery slope of arguing that the spec should always require the exact behavior of php.net PHP down to the last detail. It sounds like there are some good reasons for requiring int->float promotion aside from "this is how php.net PHP does it" :) Thanks again for entertaining my feedback and questions. -Drew