zlacker

[parent] [thread] 4 comments
1. useful+(OP)[view] [source] 2024-01-16 15:46:10
> Fast math is only slightly less accurate

'slightly'? Last I checked, -Ofast completely breaks std::isnan and std::isinf--they always return false.

replies(2): >>dahart+B1 >>xigoi+tv
2. dahart+B1[view] [source] 2024-01-16 15:53:31
>>useful+(OP)
Hopefully it was clear from the rest of my comment that I was talking about in-range floats there. I wouldn’t necessarily call inf & nan handling an accuracy issue, that’s more about exceptional cases, but to your point I would have to agree that losing std::isinf is kinda bad since divide by zero is probably near the very top of the list of things most people using floats casually might have to deal with.

Which compiler are you using where std::isinf breaks? Hopefully it was also clear that my experience leans toward CUDA, and I think the inf & nan support works there in the presence of NVCC’s fast-math.

replies(1): >>useful+F8
◧◩
3. useful+F8[view] [source] [discussion] 2024-01-16 16:27:52
>>dahart+B1
My experience is with gcc and clang on x86. I generally agree with you regarding accuracy, which is why I was quite surprised when I first discovered that -Ofast breaks isnan/isinf.

Even if I don't care about the accuracy differences, I still need a way to check for invalid input data. The upshot is that I had to roll my own isnan and isinf to be able to use -Ofast (because it's actually the underlying __builtin_xxx intrinsics that are broken), which still seems wrong to me.

4. xigoi+tv[view] [source] 2024-01-16 18:15:27
>>useful+(OP)
They are talking about -ffast-math, not -Ofast.
replies(1): >>gumby+lR
◧◩
5. gumby+lR[view] [source] [discussion] 2024-01-16 19:36:35
>>xigoi+tv
From the gcc manual:

-Ofast

Disregard strict standards compliance. -Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for all standard-compliant programs. It turns on -ffast-math, -fallow-store-data-races and the Fortran-specific -fstack-arrays, unless -fmax-stack-var-size is specified, and -fno-protect-parens. It turns off -fsemantic-interposition.

[go to top]