Page MenuHomePhabricator

Provide more sophisticate Equal method for floating point values
Closed, WontfixPublic

Description

The current mitk::Equal method for float and double values does only compare these in respect to an absolute epsilon. This leads to the problem that the result of the comparison is only meaningful for numbers in specific ranges since the allowed epsilon must be known.

Example:
If 10000 is compared to 10000.001 they seem to be equal, since there is only a difference of 0.001. But if 0.1 is compared to 0.101 this is very likely not equal, even though the absolute difference is still the same.

We should implement the method described in http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ and provide 3 possible mitk::equal-functions for floating point values.

One showing the same behaviour like the current implementation, one that compares to ULP (e.g. floating point distance) and one compares to with respect to both methods. (Usefull if values near zero are possible, see link)

To ensure that the compare functions work properly we should implement some unit tests which compare fixed floating point values. Since the outcome will be known it can be tested if the comparison method works as intended.

Event Timeline

New remote branch pushed: bug-16324-AdvancedFloatingPointComparison

I pushed a first draft, which includes the new mitk::Equal(...) for float. As of today, the branch needs more work:

  • Create a verbode function
  • Replace default equal method by defining default parameters
  • Deprecate old equal method
  • Replace old equal method at least in the core (Everywhere, where a eps has been specified) because of warning-free policy.

-> Do all for double as well.

Since this affects a lot of files, the best idea is probably to either integrate this to the float->double conversion or wait until this is merged to avoid doubling work.

I think it's worth presenting your idea in the MITK meeting first, so that people hear the idea and can give feedback. Without having read the whole cited article, it seems reasonable to give the option of several equals. However, it requires people to understand the differences.

The idea was presented in the MITK-meeting and approved.

We want to include this version in the next release as an optional way of comparing. Maybe it will become default in a later release.

REVIEW:

  • hide or rename Float_t and Double_t types
  • short wiki page describing the Feature (link to article etc.)
  • check availability of uint32_t on different platforms / C++ versions
  • implement double version and test mixed float/double invocation of Equal function
kislinsk removed goetzm as the assignee of this task.
kislinsk added a project: Auto-closed.
kislinsk added subscribers: goetzm, kislinsk.

Hi there! ๐Ÿ™‚

This task was auto-closed according to our Task Lifecycle Management.
Please follow this link for more information and don't forget that you are encouraged to reasonable re-open tasks to revive them. ๐Ÿš‘

Best wishes,
The MITK devs