Alex Rivera | Logout

Comparing IEEE floats and doubles for equality

Asked 2008-08-21T21:47:24.230
9

What is the best method for comparing IEEE floats and doubles for equality? I have heard of several methods, but I wanted to see what the community thought.

Edit
Report

2 Answers

0

This seems to take care of most problems by combining relative and absolute error tolerance. Is the ULP approach better? If so, why?

ULPs are a direct measure of the "distance" between two floating point numbers. This means that they don't require you to conjure up the relative and absolute error values, nor do you have to make sure to get those values "about right". With ULPs, you can express directly how close you want the numbers to be, and the same threshold works just as well for small values as for large ones.

answered 2008-08-21T22:07:11.700
0

If you are looking for two floats to be equal, then they should be identically equal in my opinion. If you are facing a floating point rounding problem, perhaps a fixed point representation would suit your problem better.

Perhaps we cannot afford the loss of range or performance that such an approach would inflict.

answered 2008-08-21T22:11:27.837

Your Answer