3 ms·
somewhat related question: how do I most easily verify / disprove that (a+b)-b == a exactly for a,b floating point numbers? (i.e. I don't want the compiler t
by DoctorOetker 7y ago
somewhat related question: how do I most easily verify / disprove that
(a+b)-b == a exactly
for a,b floating point numbers?
(i.e. I don't want the compiler to optimize the LHS away to a...)
- Doxin 7y agoYou could prevent the compiler from optimising it by either running with optimisations turned off or by declaring a and b as volatile. Declaring a variable as volatile tells the compiler that something external to the program (and indeed even external to the processor or memory!) might change the value of that variable at any time. In this case that's not actually true but it should stop the compiler from optimising the variable access in any case. The easiest case to disprove your proposed invariant is to set a to 0 and b to NaN. The output is NaN and not 0.