Boost C++ Libraries: Ticket #5823: nextafter doesn't work correctly with non-finite values -- even in C99/TR1 mode https://svn.boost.org/trac10/ticket/5823 <p> boost::math::tr1::nextafter(inf, 0) should yield the maximum value, yet it yields nan instead. </p> <p> I think it would be a good idea to make it work like this directly boost::math::nextafter. </p> <p> Attached is a testcase that demonstrates the problem (requires a C99 standard library for comparison). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5823 Trac 1.4.3 Mathias Gaunard Mon, 29 Aug 2011 13:57:46 GMT attachment set https://svn.boost.org/trac10/ticket/5823 https://svn.boost.org/trac10/ticket/5823 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">nextafter_test.cpp</span> </li> </ul> Ticket Mathias Gaunard Mon, 29 Aug 2011 13:59:26 GMT summary changed https://svn.boost.org/trac10/ticket/5823#comment:1 https://svn.boost.org/trac10/ticket/5823#comment:1 <ul> <li><strong>summary</strong> <span class="trac-field-old">nextafter doesn't work with denormals -- even in C99/TR1 mode</span> → <span class="trac-field-new">nextafter doesn't work correctly with non-finite values -- even in C99/TR1 mode</span> </li> </ul> Ticket John Maddock Mon, 10 Oct 2011 08:52:42 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5823#comment:2 https://svn.boost.org/trac10/ticket/5823#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> 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. </p> <p> 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. </p> <p> 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. </p> Ticket Mathias Gaunard Mon, 10 Oct 2011 11:23:34 GMT <link>https://svn.boost.org/trac10/ticket/5823#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5823#comment:3</guid> <description> <p> 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. </p> <p> With the current situation, for us Boost.Math is unfortunately not usable directly as an alternative to a standard C99 library. </p> <p> Why not just add the check in boost_nextafter for feature parity? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 10 Oct 2011 17:25:53 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/5823#comment:4 https://svn.boost.org/trac10/ticket/5823#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">wontfix</span> </li> </ul> <p> OK I've checked and both GLIBC and MSVC have the behaviour you describe, will fix later. </p> Ticket John Maddock Tue, 11 Oct 2011 17:28:16 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5823#comment:5 https://svn.boost.org/trac10/ticket/5823#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/74918" title="Change nextafter and related functions to handle infinities as ...">[74918]</a>) Change nextafter and related functions to handle infinities as arguments the same way as GLIBC and MSVC. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5823" title="#5823: Bugs: nextafter doesn't work correctly with non-finite values -- even in ... (closed: fixed)">#5823</a>. </p> Ticket