Opened 12 years ago

Closed 12 years ago

#5385 closed Bugs (fixed)

atanh.hpp returns wrong limits for atanh(1)

Reported by: florian@… Owned by: John Maddock
Milestone: To Be Determined Component: math
Version: Boost 1.46.0 Severity: Showstopper
Keywords: Cc:

Description

Hej,

in boost/math/special_functions/atanh.hpp the return value for 1 in case of ignoring overflow errors is wrong. This error is present in Boost 1.46.1 as well in the trunk version of today.

Starting with line 59 it states:

59: else if(x < -1 + tools::epsilon<T>()) 60: { 61: -Infinity: 62: return -policies::raise_overflow_error<T>(function, 0, pol); 63: } 64: else if(x > 1 - tools::epsilon<T>()) 65: { 66: Infinity: 67: return -policies::raise_overflow_error<T>(function, 0, pol); 68: }

While the case of -Infinity works fine, the case +Infinity return the wrong sign. Thus, if I set #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error I expect that boost::math::atanh(1) would return +Inf, but instead I get -Inf, which is wrong.

Removing the minus sign (-) from the return value in line 67 solves this problem and the function behaves as intended. 66: Infinity: 67: return policies::raise_overflow_error<T>(function, 0, pol);

Best regards, /Florian

Change History (2)

comment:1 by florian@…, 12 years ago

Sorry, I screwed up the formatting:

The original source code in boost/math/special_functions/atanh.hpp

59: else if(x < -1 + tools::epsilon<T>())
60: {
61:    // -Infinity:
62:    return -policies::raise_overflow_error<T>(function, 0, pol);
63: }
64: else if(x > 1 - tools::epsilon<T>())
65: {
66:    // Infinity:
67:    return -policies::raise_overflow_error<T>(function, 0, pol);
68: }

should be changed to

66:    // Infinity:
67:    return policies::raise_overflow_error<T>(function, 0, pol);

where in line 67 the minus sign was removed to return +Infinity if the overflow error is ignored.

/Florian

comment:2 by John Maddock, 12 years ago

Resolution: fixed
Status: newclosed

(In [70692]) Fix value returned for atanh(1). Fixes #5385.

Note: See TracTickets for help on using tickets.