comparing float/double values using == operator

IBM has a recommendation for comparing two floats, using division rather than subtraction – this makes it easier to select an epsilon that works for all ranges of input.

if (abs(a/b - 1) < epsilon)

As for the value of epsilon, I would use 5.96e-08 as given in this Wikipedia table, or perhaps 2x that value.

Leave a Comment