Re: Float comparison



CBFalconer <cbfalconer@xxxxxxxxx> writes:
Keith Thompson wrote:
[...]
However floating-point types do have adjacent values. For example,
1.0 and 1.0+DBL_EPSILON are adjacent values of type double; there
are no double values between them.

True again. Now all I want is for people to keep that (and the
consequences) in mind.

That's exactly what I've been doing. You should try it.

A stored value of type double cannot represent the real value
1.0+DBL_EPSILON/2.0, any more than a stored value of type int can
represent the value 1.5.

The computation 1.0/3.0 may yield any value within some
implementation-defined range. When the result of the computation is
stored in a double object, any range information is discarded; only a
single exact value (not exactly one third, but *some* exact value) is
stored.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.