Timeline for Does comparing equality of float numbers mislead junior developers even if no rounding error occurs in my case?
Current License: CC BY-SA 3.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 16, 2022 at 20:48 | comment | added | gnasher729 | Putting a button on a screen takes ages compared to calculating its position. So performance is a complete non-argument. | |
| Feb 1, 2018 at 11:19 | comment | added | Jeroen Mostert | @leftaroundabout: Sure. My point wasn't about which one is definitely faster in any given situation, just that "I know FP is slow and integer is fast so I'll use integers if at all possible" isn't a good motivation even before you tackle the question of whether the thing you're doing needs optimization. | |
| Feb 1, 2018 at 11:12 | comment | added | leftaroundabout | @JeroenMostert SSE/AVX have vectorised operations for both integers and floats, and you may be able to use smaller integers (because no bits are wasted on exponent), so in principle one might often still squeeze out more performance from highly-optimised integer code than with floats. But again, this isn't relevant for most applications and definitely not for this question. | |
| Feb 1, 2018 at 11:01 | comment | added | Jeroen Mostert | "Floating point arithmetic is slow and integer arithmetic is fast" is a historical truism that you should not retain as gospel moving forward. To add to what @leftaroundabout said, it's not just true that the penalty would be almost irrelevant, you may well find floating-point operations to be faster than their equivalent integer operations, thanks to the magic of autovectorizing compilers and instruction sets that can crunch large amounts of floats in one cycle. For this question it's not relevant, but the basic "integer is faster than float" assumption hasn't been true for quite a while. | |
| Jan 31, 2018 at 23:04 | comment | added | leftaroundabout | The performance difference between integers and floats is important when writing C code for a small microprocessor, but modern x86-derived CPUs do floating point so fast that any penalty is easily eclipsed by the overhead of using a dynamic language. In particular, does not Javascript actually represent every number as floating-point anyway, using the NaN payload when necessary? | |
| Jan 31, 2018 at 16:47 | review | First posts | |||
| Jan 31, 2018 at 17:38 | |||||
| Jan 31, 2018 at 16:45 | history | answered | J.Farges | CC BY-SA 3.0 |