Boost C++ Libraries: Ticket #13148: Zero value cannot be converted from cpp_dec_float_50 to cpp_rational https://svn.boost.org/trac10/ticket/13148 <p> String "boost::multiprecision::cpp_rational result(d1);" eats CPU forever. </p> <p> It is reproduced on boost_1_65_0_beta1 and boost_1_64_0. </p> <pre class="wiki"> boost::multiprecision::cpp_rational rationalfromStr(const char* str) { boost::multiprecision::cpp_dec_float_50 d1(str); boost::multiprecision::cpp_rational result(d1); // &lt;--- eats CPU forever return result; } void test() { // this example is OK { boost::multiprecision::cpp_rational expected=1; assert(expected == rationalfromStr("1")); } // this example is OK { boost::multiprecision::cpp_rational expected=boost::multiprecision::cpp_rational(25)/boost::multiprecision::cpp_rational(10); assert(expected == rationalfromStr("2.5")); } // this example is OK { boost::multiprecision::cpp_rational expected=boost::multiprecision::cpp_rational(5)/boost::multiprecision::cpp_rational(1000); assert(expected == rationalfromStr("0.005")); } // this example is OK { boost::multiprecision::cpp_rational expected=0; assert(expected == boost::multiprecision::cpp_rational("0")); // direct cpp_rational from str is ok } // this example fails { boost::multiprecision::cpp_rational expected=0; // reacheble code assert(expected == rationalfromStr("0")); // cpp_rational from cpp_dec_float_50 is not ok // unreacheble code } } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13148 Trac 1.4.3 Jacob Garber <jgarber1@…> Tue, 15 Aug 2017 17:08:13 GMT <link>https://svn.boost.org/trac10/ticket/13148#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13148#comment:1</guid> <description> <p> Compiling with <code>-fsanitize=undefined</code> reveals an integer overflow: </p> <pre class="wiki">/usr/local/include/boost/multiprecision/detail/generic_interconvert.hpp:433:22: runtime error: negation of -2147483648 cannot be represented in type 'typename cpp_dec_float&lt;50, int, void&gt;::exponent_type' (aka 'int'); cast to an unsigned type to negate this value to itself </pre><p> I can't reproduce with 1.63. It looks like this was introduced in the fix for <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/12625" title="#12625: Bugs: multiprecision acos() sometimes does not return (closed: fixed)">#12625</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Wed, 27 Dec 2017 19:45:19 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/13148#comment:2 https://svn.boost.org/trac10/ticket/13148#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> <p> Fixed in <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/37c813f764eec8ca7cd9beba3a9ba785503c6d21"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/37c813f764eec8ca7cd9beba3a9ba785503c6d21</a> </p> <p> Thanks for the report! </p> Ticket anonymous Tue, 27 Feb 2018 05:39:50 GMT <link>https://svn.boost.org/trac10/ticket/13148#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13148#comment:3</guid> <description> <p> Hello. Which boost version the fix will be available? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 27 Feb 2018 09:37:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13148#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13148#comment:4</guid> <description> <p> I've just this second merged to master, so it should be in 1.67. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 27 Feb 2018 11:49:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13148#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13148#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/13148#comment:4" title="Comment 4">anonymous</a>: thanks </p> </description> <category>Ticket</category> </item> </channel> </rss>