zlacker

[parent] [thread] 8 comments
1. cogman+(OP)[view] [source] 2024-01-16 14:13:49
Ehh, not so much inaccurate, more of a "floating point numbers are tricky, let's act like they aren't".

Compilers are pretty skittish about changing the order of floating point operations (for good reason) and ffast-math is the thing that lets them transform equations to try and generate faster code.

IE, instead of doing "n / 10" doing "n * 0.1". The issue, of course, being that things like 0.1 can't be perfectly represented with floats but 100 / 10 can be. So now you've introduced a tiny bit of error where it might not have existed.

replies(2): >>phkahl+02 >>rwmj+Y2
2. phkahl+02[view] [source] 2024-01-16 14:27:18
>>cogman+(OP)
I've never understood why generating exceptions is preferable to just using higher precision.
replies(2): >>gumby+O7 >>dahart+5i
3. rwmj+Y2[view] [source] 2024-01-16 14:31:53
>>cogman+(OP)
It isn't just that. -ffast-math also allows the compiler to ignore infinites. In fact for GCC with -ffast-math, isinf always returns false. Something similar happens for NaNs/isnan.
replies(1): >>cogman+Qh
◧◩
4. gumby+O7[view] [source] [discussion] 2024-01-16 14:57:58
>>phkahl+02
Higher precision isn’t always available. IEEE 754 is an unusually well-thought-through standard (thanks to some smart people with a lot of painful experience) and is pretty good at justifying its decisions, some of which are surprising (far from obvious) to anyone not steeped in it.
replies(1): >>cogman+3j
◧◩
5. cogman+Qh[view] [source] [discussion] 2024-01-16 15:42:14
>>rwmj+Y2
I lump this into "floating points are tricky". NaNs and inf are definitely legitimate floating point values. They are also things that a lot of applications will break on they ever encounter them.
◧◩
6. dahart+5i[view] [source] [discussion] 2024-01-16 15:42:58
>>phkahl+02
On a GPU, higher precision can cost between 2 and 64 times more than single precision, with typical ratios for consumer cards being 16 or 32. Even on the CPU, fp64 workloads tend to run at half the speed on real data due to the extra bandwidth needed for higher precision.
◧◩◪
7. cogman+3j[view] [source] [discussion] 2024-01-16 15:46:10
>>gumby+O7
The main problem with floats in general is they are designed primarily for scientific computing.

We are fortunately starting to see newer (well, not that new now) CPU instructions like FMA that make more accurate decimal representations not take such huge performance hits.

replies(1): >>adgjls+7D
◧◩◪◨
8. adgjls+7D[view] [source] [discussion] 2024-01-16 17:18:45
>>cogman+3j
what does fma have to do with decimal numbers?
replies(1): >>cogman+jK
◧◩◪◨⬒
9. cogman+jK[view] [source] [discussion] 2024-01-16 17:51:47
>>adgjls+7D
Oh shoot, nvm, I thought it was an optimization for integers.

Really it'll be the SIMD style instructions that speeds things up.

[go to top]