Opened 8 years ago

Closed 8 years ago

#10173 closed Bugs (fixed)

Epsilon value returned by std::numeric_limits is too small on PowerPC, causing tests to fail

Reported by: Harris Munir <hamunir@…> Owned by: Antony Polukhin
Milestone: Boost 1.57.0 Component: lexical_cast
Version: Boost Release Branch Severity: Problem
Keywords: lexical_cast_float_types_test, epsilon Cc:

Description

In lexical_cast_float_types_test, std::numeric_limits<long double>::epsilon() is used as a tolerance value when comparing long double values to check the accuracy of lexical_cast.

On PowerPC, this epsilon value is extremely small for the long double type. While the value is technically correct, since adding 1.0L to it does in fact result in a distinct value, it is not suitable for use as a tolerance value in this type of comparison. Instead, we need a value such that:

x + x * eps != x for all x

This value can be found by calculating 2(1-D), where D is the number of bits of precision in the type.

We found this same issue in many parts of the Boost math library, and resolved it by adding a special case of boost::math::tools::epsilon<long double> for platforms that use the strange "double-double" implementation of long double, such as PowerPC. This change is now in the master branch and can be seen here:

https://github.com/boostorg/math/blob/7cb3316d0616db01f6c4a56126d4bf8c73e7b50d/include/boost/math/tools/precision.hpp#L160-178

I have created a pull request which replaces all instances of std::numeric_limits<T>::epsilon() with boost::math::tools::epsilon<T> in lexical_cast_float_types_test. This change fixes 5222 of the 5255 failures that currently occur within the test on a PowerPC machine with long double support enabled. The pull request can be found here:

https://github.com/boostorg/lexical_cast/pull/3

Change History (1)

comment:1 by Antony Polukhin, 8 years ago

Milestone: To Be DeterminedBoost 1.57.0
Resolution: fixed
Status: newclosed

Fix was applied to the develop branch and already merged to the master branch.

Note: See TracTickets for help on using tickets.