tags:

views:

157

answers:

1
+10  A: 

Unfortunately the two aren't equivalent. (Specifically NaNs and signed zeros don't use bitwise comparison inside the FPU).

So you should make your choice based on correctness, not speed.

Ben Voigt
Right, I just completely forgot about that. Rookie mistake I suppose.
Duracell
@Duracell: The rookie mistake is worrying about performance over good code. :) Performance is your last concern.
GMan
@GMan: You could say that, but I'd completely overlooked the fact that memcmp wouldn't work. Without that, I'd assumed my code was good and could therefore look at speed.
Duracell
OK @Ben Voigt, with that out of the way, what if the vectors just used ints? And I know all about the "Don't prematurely optimize!!!!1" argument. I'm just interested to know.
Duracell
ints use bitwise comparison. Actually, using bitwise comparison on doubles is not necessarily a bad thing, *if you don't want IEEE handling of NaN values*. For example, using IEEE comparisons can result in the following: `bool func(vector a) { vector b = a; return b == a; }` returning `false` (in the case of quiet NaNs) or even crashing (in the case of signalling NaNs).
Ben Voigt
Thanks, I thought that was the case.
Duracell