views:

74

answers:

3

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
By another PC, you mean with a different architecture?
why should I tell you my name
Yes, I think this is the only thing that makes a difference here.
schnaader
A: 

The answer is yes as long as your routines are deterministic.

wheaties
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