Boost C++ Libraries: Ticket #10993: frexp with multiprecision cpp_dec_float_50 returns random values with VS 2013 https://svn.boost.org/trac10/ticket/10993 <p> With VS 2013, math function frexp with multiprecision cpp_dec_float_50 and with expression-templates ON returns spectacularly wrong and random values. </p> <p> GCC 4.9.1 returns the expected values. </p> <p> Switching expression-templates OFF also works as expected. </p> <p> multiprecision cpp_bin_float_50 works as expected. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10993 Trac 1.4.3 Paul A. Bristow Wed, 04 Feb 2015 10:04:15 GMT attachment set https://svn.boost.org/trac10/ticket/10993 https://svn.boost.org/trac10/ticket/10993 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cpp</span> </li> </ul> Ticket John Maddock Thu, 05 Feb 2015 19:16:52 GMT <link>https://svn.boost.org/trac10/ticket/10993#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10993#comment:1</guid> <description> <p> With expression templates on, then the return value is an expression template - no calculations have been performed at that point - you have to assign the returned value to something to force the function to be evaluated. </p> <p> But.... this is probably a big trap for the unwary, so I'll change. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Paul A. Bristow</dc:creator> <pubDate>Fri, 06 Feb 2015 09:46:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10993#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10993#comment:2</guid> <description> <p> I was indeed unwary, and fell straight into the trap :-( </p> <p> The original problem was within this templated function: </p> <pre class="wiki"> template &lt;int N, class T = double&gt; T nth_2deriv(T x) { // return nth root of x using 1st and 2nd derivatives and Halley. //typedef double guess_type; // Works OK with this (and may be accurate enough anyway). typedef T guess_type; // Failed with this with cpp_dec_float_50 only. int exponent; frexp(static_cast&lt;guess_type&gt;(x), &amp;exponent); // Get exponent of z (ignore mantissa). T guess = ldexp(static_cast&lt;guess_type&gt;(1.), exponent / N); // Rough guess is to divide the exponent by n. T min = ldexp(static_cast&lt;guess_type&gt;(1.) / 2, exponent / N); // Minimum possible value is half our guess. T max = ldexp(static_cast&lt;guess_type&gt;(2.), exponent / N); // Maximum possible value is twice our guess. ... </pre><p> Others may appreciate this trap not existing! Thanks. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 06 Feb 2015 20:25:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10993#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10993#comment:3</guid> <description> <p> But the sample code shows frexp obtaining faulty results for the integer exponent argument. This is not a multiprecision type. I don't understand what the exponent obtained in frexp has to do with et_on or et_off. I'm confused here. </p> <p> Chris </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 07 Feb 2015 08:50:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10993#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10993#comment:4</guid> <description> <blockquote class="citation"> <p> But the sample code shows frexp obtaining faulty results for the integer exponent argument. This is not a multiprecision type. I don't understand what the exponent obtained in frexp has to do with et_on or et_off. I'm confused here. </p> </blockquote> <p> The function is never evaluated in the et_on case unless the returned value is assigned to something - so the integer argument remains uninitialized. It's a bug in the expression template code really, will fix shortly. John. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Paul A. Bristow</dc:creator> <pubDate>Sun, 08 Feb 2015 16:35:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10993#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10993#comment:5</guid> <description> <p> I confirm that providing something to take the result of frexp works as predicted. </p> <p> T mantisssa = frexp(static_cast&lt;guess_type&gt;(x), &amp;exponent); </p> <p> This provides an easy workaround for the current release 1.56. </p> <p> (But it is curious the GCC works OK without this when MSVC fails?). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sun, 22 Feb 2015 13:23:27 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10993#comment:6 https://svn.boost.org/trac10/ticket/10993#comment:6 <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/f970a181414751b1de54c66ebec0e40543830450"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/f970a181414751b1de54c66ebec0e40543830450</a> </p> Ticket