News for hackers. Stuff that matters.
Re:Optimizations Enabled by -ffast-Math by adrian_b on Wednesday October 20, 2021 @04:15AM (#28928090)
The whole rationale for the standard for floating-point operations is to specify the FP operations with such properties that a naive programmer will be able to write programs which will behave as expected.

If you choose any option that is not compliant with the standard, that means, exactly as you have noticed, that you claim that you are an expert in FP computations and you know how to write FP programs that will give the desired results even with FP operations that can behave in strange ways.

So yes, that means that you become responsible to either guarantee that erroneous results do not matter or that you will take care to always check the ranges of input operands, as "okl" has already posted, to ensure that no overflows, underflows or undefined operations will happen.

Re:Optimizations Enabled by -ffast-Math by celrod on Wednesday October 20, 2021 @09:26AM (#28930378)
> So yes, that means that you become responsible to either guarantee that erroneous results do not matter or that you will take care to always check the ranges of input operands, as "okl" has already posted, to ensure that no overflows, underflows or undefined operations will happen.

This is why I dislike the fact that it removes simple methods for checking if values are NaN, for example. I do not find it ergonomic to disable these checks.

Re:Optimizations Enabled by -ffast-Math by kazinator on Thursday October 21, 2021 @01:52PM (#28948313)
If NaN and Inf values can still happen, but you don't have reliable ways of working with them, that is poor.

I think what people really want is a sane floating point mode that throws exceptions instead of these Inf and NaN things, so if their program isn't debugged, they get a clear signal by way of its abnormal termination.

Re:Optimizations Enabled by -ffast-Math by billfruit on Wednesday October 20, 2021 @12:30PM (#28932684)
Is it adviced to detect overflow and do something about it after an FP computation rather than adding pre-checks to try to avert the overflow?
Re:Optimizations Enabled by -ffast-Math by owlbite on Wednesday October 20, 2021 @12:44PM (#28932861)
So it depends on how you want to detect overflow.

Trapping on math exceptions or otherwise pulling an emergency break doesn't really fit with modern hardware design if you want performance (for one thing, what do you do with the rest of your vector? do you just live with a pipeline flush?).

Adding targeted checks used sparingly can work, but probably requires a deeper understanding of the underlying numerical analysis of your problem. Generally just checking for NaN or Inf at the end is a better solution as these are in most cases absorbing states.

Re:Optimizations Enabled by -ffast-Math by KarlKemp on Wednesday October 20, 2021 @02:07PM (#28933890)
The only obvious way to test if some operation is going to produce some value(s) is to perform that operation. Yes, for, say, a single multiplication I can anticipate the necessary bounds for each input value. But even short sequences of operations would quickly devolve into labyrinthine nested switch statements.
Re:Optimizations Enabled by -ffast-Math by owlbite on Wednesday October 20, 2021 @12:38PM (#28932794)
Rename to: -fdisable-math-safeties