Boost C++ Libraries: Ticket #5758: Boost.Test Floating-point comparison diagnostic output does not support radix 10 https://svn.boost.org/trac10/ticket/5758 <p> Boost.Test Floating-point comparison diagnostic output does not support radix 10. </p> <p> This emerged as a problem writing tests for Christopher Kormanyos proposed e_float extended precision float library which uses radix 10. </p> <p> Tests that fail do not provide sufficient decimal digits to reveal why the test fails. </p> <p> Numeric_limits is properly specialized for e_float, so max_digits10 is valid (and this is also true for a recent fixed decimal library. </p> <p> So I suggest that in test_tools.hpp function set_precision </p> <p> After dealing with the radix = 2 case, </p> <p> (and noting that although we would like to rely on max_digits10, older compilers/libraries do not provide it, and the recent MS VC10 wrongly implements float max_digits10 as 8 instead of 9, it is safer to continue to use the original Kahan formula)&gt; </p> <blockquote> <p> <em> Ideally should use max_digits10 if available, and correct! But this always works. </em></p> <blockquote> <p> if( std::numeric_limits&lt;T&gt;::is_specialized &amp;&amp; std::numeric_limits&lt;T&gt;::radix </p> </blockquote> </blockquote> <p> Add new code to deal with the radix=10 case (but in this case <strong>we can rely on max_digits10</strong>) </p> <blockquote> <p> <em> If radix = 10, is recent code so assume max_digits10 should be correct. </em> For example, e_float and a fixed decimal package(s) both comply. </p> </blockquote> <blockquote> <p> if( std::numeric_limits&lt;T&gt;::is_specialized &amp;&amp; std::numeric_limits&lt;T&gt;::radix == 10 ) </p> <blockquote> <p> ostr.precision( std::numeric_limits&lt;T&gt;::max_digits10 ); </p> </blockquote> </blockquote> <p> (Might also be worth a comment that for other cases, precision will remain at the default value, whatever that is). </p> <p> This has been tested and works as expected for e_float. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5758 Trac 1.4.3 Paul A. Bristow Tue, 05 Jun 2012 13:55:31 GMT <link>https://svn.boost.org/trac10/ticket/5758#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5758#comment:1</guid> <description> <p> This is also essential for the proposed Boost.Multiprecision (and probably proposed fixed-point). </p> <p> At 1.50 </p> <p> I:/boost-sandbox/big_number/libs/multiprecision/test/math/test_cpp_float_loopback.cpp(66): error : in "cpp_loopback_test_max": check l == b failed </p> <blockquote> <p> [1e+2776234983093287513 != 1e+2776234983093287513] </p> </blockquote> <p> which is most misleading (and nonsensical) </p> <p> Patched as proposed to use max_digits10 above gives the correct (and sensible) display </p> <p> I:/boost-sandbox/big_number/libs/multiprecision/test/math/test_cpp_float_loopback.cpp(66): error : in "cpp_loopback_test_max": check l == b failed </p> <p> [1e+2776234983093287513 != 9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999e+2776234983093287512] </p> <p> It would be very useful if this was corrected for 1.51 when Boost.Multiprecision will probably be included. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Paul A. Bristow</dc:creator> <pubDate>Tue, 12 Jun 2012 11:20:38 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5758#comment:2 https://svn.boost.org/trac10/ticket/5758#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">fixed</span> </li> </ul> <blockquote> <p> Patch committed Completed: At revision: 78908 </p> </blockquote> <p> if( std::numeric_limits&lt;T&gt;::is_specialized &amp;&amp; std::numeric_limits&lt;T&gt;::radix == 10 ) </p> <blockquote> <p> ostr.precision( 2 + std::numeric_limits&lt;T&gt;::max_digits10); </p> </blockquote> <p> This assumes that any new radix 10 library will implement max_digits10 as it should to be standard compliant. </p> Ticket Paul A. Bristow Thu, 14 Jun 2012 10:24:14 GMT <link>https://svn.boost.org/trac10/ticket/5758#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5758#comment:3</guid> <description> <p> Comment out this until can find a way to check if max_digits10 is supported. </p> </description> <category>Ticket</category> </item> <item> <author>Jeff Trull <edaskel@…></author> <pubDate>Thu, 14 Jun 2012 15:37:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5758#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5758#comment:4</guid> <description> <p> Also see bug 6986; I echo pbristow's third comment. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jürgen Hunold</dc:creator> <pubDate>Sat, 16 Jun 2012 10:42:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5758#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5758#comment:5</guid> <description> <p> I tested John suggestion on the ML thread and successfully used BOOST_NO_NUMERIC_LIMITS_LOWEST. Patch attached. I will also ask on the ML. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jürgen Hunold</dc:creator> <pubDate>Sat, 16 Jun 2012 10:43:08 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/5758 https://svn.boost.org/trac10/ticket/5758 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">max_digits10.diff</span> </li> </ul> <p> Check for BOOST_NO_NUMERIC_LIMITS_LOWEST </p> Ticket Paul A. Bristow Mon, 09 Jul 2012 13:50:09 GMT <link>https://svn.boost.org/trac10/ticket/5758#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5758#comment:6</guid> <description> <p> Using John Maddock and Christopher Kormanyos mutliprecision currently under review </p> <p> BOOST_AUTO_TEST_CASE(cpp_loopback_test_message) { <em> Loopback. </em></p> <blockquote> <p> using namespace boost::multiprecision; </p> </blockquote> <blockquote> <p> cpp_dec_float_100 a = "1."; cpp_dec_float_100 b = "1."; b += 1e-100; </p> </blockquote> <blockquote> <p> BOOST_CHECK_EQUAL(a, b); </p> </blockquote> <p> } <em> BOOST_AUTO_TEST_CASE(cpp_loopback_test_message) </em></p> <p> Gives this misleading message </p> <p> error : in "cpp_loopback_test_message": check a == b failed [1 != 1] </p> <blockquote> <p> else if ( std::numeric_limits&lt;T&gt;::is_specialized &amp;&amp; std::numeric_limits&lt;T&gt;::radix == 10 ) </p> </blockquote> <p> <em> adding this to cater for radix 10 </em></p> <blockquote> <p> { </p> </blockquote> <p> #ifdef BOOST_NO_NUMERIC_LIMITS_LOWEST <em> No support for std::numeric_limits&lt;double&gt;::max_digits10; </em> so guess that a couple of guard digits more than digits10 will display any difference. </p> <blockquote> <p> ostr.precision( 2 + std::numeric_limits&lt;T&gt;::digits10 ); </p> </blockquote> <p> #else </p> <blockquote> <p> <em> std::numeric_limits&lt;double&gt;::max_digits10; IS supported. </em> Any noisy or guard digits needed to display any difference are included in max_digits10. </p> <blockquote> <p> ostr.precision( std::numeric_limits&lt;T&gt;::max_digits10 ); </p> </blockquote> </blockquote> <p> #endif </p> <blockquote> <p> } <em> else if T is not specialized, then will just get the default precision of 6 digits. </em></p> </blockquote> <p> gives this more helpful mesage </p> <p> in "cpp_loopback_test_message": check a == b failed [1 != 1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000001999] </p> <blockquote> <p> BOOST_NO_NUMERIC_LIMITS_LOWEST is a proxy for support of max_digits10. </p> </blockquote> <p> And seems to work in tests using Boost.Math. </p> <p> At present only MSVC 10 and some gcc test platforms support max_digits10. </p> <p> Sandia clang darwin trunk c++11 seems to fail with and without check for BOOST_NO_NUMERIC_LIMITS_LOWEST. </p> <p> Please tell me immediately of any problem this revised version causes. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Paul A. Bristow</dc:creator> <pubDate>Fri, 13 Jul 2012 08:45:42 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/5758#comment:7 https://svn.boost.org/trac10/ticket/5758#comment:7 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.48.0</span> → <span class="trac-field-new">Boost 1.51.0</span> </li> </ul> Ticket