Saturday, 15 February 2014

c - Equivalence of comparison between floats or reinterpreted floats as UINTs -


Will it always be in the result of any difference compared to comparing two positive positive floats and comparison After referencing them binary presentation as unsigned integer?

In other words, the variable float x, y; which is always known to be positive or zero and 32 IEEE -Bat floats for storage, can I assume that this comparison:

  float x, y ; ... if (x & lt; y) {...}  

is always the same:

  float x, y; Unsigned int uix, uiy; ... uix = * (unsigned integer *) & amp; X; Uiy = * (unsigned full *) & amp; Y; If (uix & lt; uiy) {...}  

?

If both x and y both strictly It works, it works (ignoring the undefined behavior that is inserted from the indicator and assuming that you used a union or mempie instead of the command type, and assuming that you have some strange platforms There is no one where the floating-point end of an integer does not match the integer type), because it could Rational binary floating-point numbers are similar to their representation.

If y can be negative, it does not work, because 0.f < -0.F is incorrect, but 0x00000000 & lt; 0x80000000 is correct.

If it can be y , then it does not work, because representing a NaN is greater than the representation of any positive number, while x

P>

div>

No comments:

Post a Comment