I know that I can not compare two floating point or double numbers for absolute equality on C++/C. If for some reason, I write a if condition which uses the absolute equality, is it guaranteed that the if condition will return the same result on different runs of the program for same data? Or it is purely non-deterministic and the result can vary?
+2
A:
For the same compiled binary and on the same PC, results should be the same. If you use another compiler or another PC, results may vary.
schnaader
2010-09-24 19:53:26
By another PC, you mean with a different architecture?
why should I tell you my name
2010-09-24 19:54:34
Yes, I think this is the only thing that makes a difference here.
schnaader
2010-09-24 20:09:39
A:
I once had a unit test that failed on a machine with an Intel CPU but worked OK on an AMD. There was probably some difference in rounding off, and the test moreorless hit the pass/fail criterion head on.
But I would not litter your code with overcomplex tests everywhere just because of that.
jdv
2010-09-24 20:00:12