Page MenuHomePhabricator

mitk::Equal(ScalarType, ScalarType) calls std::fabs() instead of std::abs()
Closed, ResolvedPublic

Description

http://docs.mitk.org/nightly-qt4/mitkVector_8h_source.html#l00467

The subtraction result in line 469 is converted implicitly to float by std::fabs() before it is compared to mitk::eps.

Use std::abs() instead to keep precision.

Attention! This might cause some tests to fail due to increased precision. *DO NOT* change mitk::eps again to fix this issue - fix the tests!

Event Timeline

Which tests would fail after these changes? Is there a realistic chance that they will be fixed until Tuesday?

I did not fix it so far. It is just an assumption that a few tests might fail since we had many precision incidents regarding tests in the past. Fingers crossed, maybe all tests run successfully without any adaptions.

I'll give it a try next Tuesday if no one is going to do it the next days.

I do not think fabs converts to float. See e.g. mathcalls.h and math.h or
http://www.cplusplus.com/reference/cmath/fabs/

can it be that fabs was confused with fabsf, which is the explicly float variant of the function for some compilers?

I suggest no code alterations.

mylyn/context/zip

In that particular case I agree with Sebastian because fabs is overloaded for both float and double arguments.

In general I agree that as a rule of thumb "abs" should be preferred since in C++ by including the "cmath" header "abs" is overloaded for all primitive types and the compiler automatically selects the most appropriate one.