Formatting -0.0 as 0.0

Elronnd elronnd at elronnd.net
Fri Oct 15 22:26:12 UTC 2021


On Friday, 15 October 2021 at 14:09:32 UTC, Steven Schveighoffer 
wrote:
> Note that if ldc is optimizing out an addition with 0, and that 
> actually changes the observable results, that technically is an 
> invalid optimization.

I disagree.  With -ffast-math you're explicitly saying 'please 
feel free to make changes to expressions involving floating-point 
numbers which maintain all observable results only under the 
assumption that floating-point numbers have properties that they 
actually don't'.

Most usually, these changes are things like turning (x+y)+z into 
x+(y+z) because it schedules better, turning or x+y*z into an 
FMA.  Both of these can affect observable results because FP math 
is not associative, and because FMA is computed at high precision 
without an intermediate rounding stage.  Elimination of x+0.0 
definitely falls under that umbrella.


More information about the Digitalmars-d mailing list