Modify

Opened 6 years ago

Closed 6 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 6 years ago.

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by Mathias Gaunard

Attachment: nextafter_test.cpp added

comment:1 Changed 6 years ago by Mathias Gaunard

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 Changed 6 years ago by John Maddock

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 Changed 6 years ago by Mathias Gaunard

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 Changed 6 years ago by John Maddock

Resolution: wontfix
Status: closedreopened

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

comment:5 Changed 6 years ago by John Maddock

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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain John Maddock.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.