15-2. Comparing Floating-Point Numbers Using Integer Operations
One of the features of the IEEE encodings is that non-NAN values are properly ordered if treated as signed magnitude integers.
To program a floating-point comparison using integer operations, it is necessary that the “unordered” result not be needed. In IEEE 754, the unordered result occurs when one or both comparands are NaNs. The methods below treat NaNs as if they were numbers greater in magnitude than infinity.
The comparisons are also much simpler if −0.0 may be treated as strictly less than +0.0 (which is not in accordance with IEEE 754). Assuming this is acceptable, the comparisons may be done as shown below, where and denote floating-point comparisons, and the ≈ symbol ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access