Boost C++ Libraries: Ticket #6171: nonconforming behavior of inverse functions on branch cuts https://svn.boost.org/trac10/ticket/6171 <p> The inverse trigonometric and hyperbolic functions in boost/math treat signed zero incorrectly. The positions of the branch cuts are right, but C99 specifies to "<em>map a cut so the function is continuous as the cut is approached coming around the finite endpoint of the cut in a counter clockwise direction</em>" and so does C++11. </p> <p> Here are some examples of failures: </p> <ul><li>asin(-1.75-0.0*I) returns -1.5708+1.1588*I (should be -1.5708-1.1588*I) </li><li>acos(-1.25+0.0*I) returns +3.1416+0.6932*I (should be +3.1416-0.6932*I) </li><li>atan(-0.0-1.75*I) returns +1.5708-0.6496*I (should be -1.5708-0.6496*I) </li><li>asinh(+0.0+1.5*I) returns -0.9624+1.5708*I (should be +0.9624+1.5708*I) </li><li>acosh(-2.5+0.0*I) returns +1.5668-3.1416*I (should be +1.5668+3.1416*I) </li><li>atanh(-2.0-0.0*I) returns -0.5493+1.5708*I (should be -0.5493-1.5708*I) </li></ul><p> I'm attaching a patch. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6171 Trac 1.4.3 Richard B. Kreckel <kreckel@…> Thu, 24 Nov 2011 09:05:40 GMT attachment set https://svn.boost.org/trac10/ticket/6171 https://svn.boost.org/trac10/ticket/6171 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost.patch</span> </li> </ul> <p> patch </p> Ticket Richard B. Kreckel <kreckel@…> Mon, 12 Dec 2011 08:48:57 GMT <link>https://svn.boost.org/trac10/ticket/6171#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6171#comment:1</guid> <description> <p> Reading my report again, I appear to have quoted the wrong section of the standard. The one that applies is the <em>first</em> paragraph in [7.3.3] (not the second): "<em>For implementations with a signed zero (including all IEC 60559 implementations) that follow the specifications of annex G, the sign of zero distinguishes one side of a cut from another so the function is continuous (except for format limitations) as the cut is approached from either side.</em>" I apologize for the confusion. But anyway: the patch I attached accomplishes exactly that and is correct. Could somebody, please, apply it? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 12 Dec 2011 19:19:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6171#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6171#comment:2</guid> <description> <p> Investigating: your patch doesn't quite get all the cases (and causes some tests to fail), but I think I'm nearly there.... </p> <p> John Maddock. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Tue, 13 Dec 2011 18:11:50 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6171#comment:3 https://svn.boost.org/trac10/ticket/6171#comment:3 <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">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/75933" title="Fix complex number routines to work with signed zeros, changes ...">[75933]</a>) Fix complex number routines to work with signed zeros, changes involve: </p> <ul><li>Use boost::math::signbit rather than comparison to zero. </li><li>Use boost::math::changesign rather than unary negation (unary negation fails for Intel on Linux when the argument is a zero). </li><li>Update to use boost::math::isnan/isinf rather than the old code. </li><li>Update to use boost::math constants. </li></ul><p> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6171" title="#6171: Bugs: nonconforming behavior of inverse functions on branch cuts (closed: fixed)">#6171</a>. </p> Ticket anonymous Tue, 13 Dec 2011 22:23:08 GMT <link>https://svn.boost.org/trac10/ticket/6171#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6171#comment:4</guid> <description> <p> Thanks for applying this patch. I've tried it and it passes my tests. </p> <p> I see only one potential problem in the way acosh has been fixed: it tests the sign of the imaginary part of the result of the acos function. It is generally much safer to test the location in the complex plain of input variables like z.imag() instead of the location of intermediate results like result.imag(). This is because intermediate results may suffer from roundoff. </p> <p> My original patch avoided this problem I'm seeing problems related to this in various projects (e.g. GLibC <a class="ext-link" href="http://cygwin.com/bugzilla/show_bug.cgi?id=13305"><span class="icon">​</span>http://cygwin.com/bugzilla/show_bug.cgi?id=13305</a>). Please consider applying the patch I'm going to attach next. </p> </description> <category>Ticket</category> </item> <item> <author>Richard B. Kreckel <kreckel@…></author> <pubDate>Tue, 13 Dec 2011 22:44:35 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/6171 https://svn.boost.org/trac10/ticket/6171 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">acosh.patch</span> </li> </ul> Ticket