Having the following unions:
union {double first_d; uint64 first;};
union {double second_d; uint64 second;};
...
first_d = <a double value>
second_d = <a double value>
Does the output of following comparisons:
if(first_d > second_d)
// CASE 1 OUTPUT
else if(first_d < second_d)
// CASE 2 OUTPUT
else
// CASE 3 OUTPUT
always the same for the following?
if(first> second)
// CASE 1' OUTPUT
else if(first < second)
// CASE 2' OUTPUT
else
// CASE 3' OUTPUT
Nope. Here’s a counter-example using
NaNs:Output:
I’ll also mention that type-punning via unions isn’t 100% standard conformant. So you could also say it’s undefined behavior.