
Binary representation of
floating-point numbers is
discussed in Appendix E.
REFERENCE POINT
5.8 Comparing Floating-Point Numbers 239
5.8 Comparing Floating-Point Numbers
As we explain in Appendix E, floats and doubles are stored using IEEE 754
standard format, which can introduce minor rounding errors when arith-
metic is performed. That said, it is not advisable to simply rely on the
equality operators to compare floating-point numbers.
Let’s take a look at Example 5.8, which computes 11 * .1 two ways. First, at
line 11, we assign .0 to a double variable, d1, and at lines 12–22 we add .1 to
d1 eleven times. Then, at line 24, we declare a second double ...