Opened 11 years ago

Closed 11 years ago

#5823 closed Bugs (fixed)

nextafter doesn't work correctly with non-finite values -- even in C99/TR1 mode

Reported by: Mathias Gaunard Owned by: John Maddock
Milestone: To Be Determined Component: math
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:

Description

boost::math::tr1::nextafter(inf, 0) should yield the maximum value, yet it yields nan instead.

I think it would be a good idea to make it work like this directly boost::math::nextafter.

Attached is a testcase that demonstrates the problem (requires a C99 standard library for comparison).

Attachments (1)

nextafter_test.cpp (652 bytes ) - added by Mathias Gaunard 11 years ago.

Download all attachments as: .zip

Change History (6)

by Mathias Gaunard, 11 years ago

Attachment: nextafter_test.cpp added

comment:1 by Mathias Gaunard, 11 years ago

Summary: nextafter doesn't work with denormals -- even in C99/TR1 modenextafter doesn't work correctly with non-finite values -- even in C99/TR1 mode

comment:2 by John Maddock, 11 years ago

Resolution: wontfix
Status: newclosed

The current implementation deliberately treats an infinite argument as a domain error and raises an exception in C++ mode, or returns NaN in TR1 mode.

It would be easy enough to change this, but IMO it's questionable what the return value should be in this case - I'm not convinced that converting an infinite value to a finite one is the "right" answer - arguably the result could/should still be infinite.

So unless we can get a definitive answer from the C99 folks as to what the correct answer should be, I'm inclined to leave it as it is for now.

comment:3 by Mathias Gaunard, 11 years ago

While the C99 standard seems allows this, this is not what existing C99 implementations do (which the attached testcase does demonstrate), nor what other standard libraries in other languages do.

With the current situation, for us Boost.Math is unfortunately not usable directly as an alternative to a standard C99 library.

Why not just add the check in boost_nextafter for feature parity?

comment:4 by John Maddock, 11 years ago

Resolution: wontfix
Status: closedreopened

OK I've checked and both GLIBC and MSVC have the behaviour you describe, will fix later.

comment:5 by John Maddock, 11 years ago

Resolution: fixed
Status: reopenedclosed

(In [74918]) Change nextafter and related functions to handle infinities as arguments the same way as GLIBC and MSVC. Fixes #5823.

Note: See TracTickets for help on using tickets.