Boost C++ Libraries: Ticket #12408: cpp_dec_float_50 x = x*x*x gives wrong result!!! https://svn.boost.org/trac10/ticket/12408 <p> I'm a beginner with C++ and with boost so I won't be surprised if I'm making some blunder but in case there's a real problem here, here goes: Using the multiprecision cpp_dec_float_50 I get a enormous error when I cube a variable. I'm using Microsoft VS2015 Community and making a console program (since my attempts at using boost with a cli program failed miserably). The core code (I think) is #include &lt;boost/multiprecision/cpp_dec_float.hpp&gt; using boost::multiprecision::cpp_dec_float_50; <em> both at the global level = before main(){... I set f2 to this and then use the line f2 = f2*f2*f2; </em>to compute (f2)³ when f2 = 1.0335055959... I get the new f2 as 1.140909... which isn't even close to the correct value of 1.10392227... When I use a temporary variable, f3, it works just fine f3= f2*f2*f2 <em> f3 = 1.1039... It is probably some error the compiler is making, I don't know. This is obviously a worrisome bug. Simple arithmetic shouldn't give results that are off by 3% !! I'm not skilled enough in VS2015 to know what else to tell you about the switches that are or are not selected; I compile and run in the VS IDE. </em>===================================== here's the entire program (stub) <em> I've shortened 1.03559... but I still get the wrong value. #include &lt;iomanip&gt; #include &lt;iostream&gt; #include &lt;boost/multiprecision/cpp_dec_float.hpp&gt; </em></p> <p> using boost::multiprecision::cpp_dec_float_50; </p> <p> int main() { </p> <blockquote> <p> cpp_dec_float_50 f2 = (cpp_dec_float_50)(1.03559); f2 = f2*f2*f2; std::cout &lt;&lt; "f2 = " &lt;&lt; f2 &lt;&lt; std::endl; </p> </blockquote> <p> <em> gives me 1.15.... which is wrong should be 1.1106... </em> it is actually the value of f2*f2*f2*f2, or close to it. </p> <blockquote> <p> return 0; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12408 Trac 1.4.3 Dave Nalepa <denalepa1@…> Tue, 23 Aug 2016 11:47:24 GMT <link>https://svn.boost.org/trac10/ticket/12408#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12408#comment:1</guid> <description> <p> #include &lt;iomanip&gt; </p> <p> #include &lt;iostream&gt; </p> <p> #include &lt;boost/multiprecision/cpp_dec_float.hpp&gt; </p> <p> using boost::multiprecision::cpp_dec_float_50; </p> <p> int main() </p> <p> { </p> <blockquote> <p> cpp_dec_float_50 f2 = (cpp_dec_float_50)(1.03559); </p> </blockquote> <blockquote> <p> f2 = f2*f2*f2; </p> </blockquote> <blockquote> <p> std::cout &lt;&lt; "f2 = " &lt;&lt; f2 &lt;&lt; std::endl; </p> </blockquote> <blockquote> <p> return 0; </p> </blockquote> <p> } </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Michel Morin</dc:creator> <pubDate>Fri, 26 Aug 2016 13:35:27 GMT</pubDate> <title>component changed; owner set https://svn.boost.org/trac10/ticket/12408#comment:2 https://svn.boost.org/trac10/ticket/12408#comment:2 <ul> <li><strong>owner</strong> set to <span class="trac-author">John Maddock</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">multiprecision</span> </li> </ul> Ticket John Maddock Sat, 27 Aug 2016 17:45:19 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12408#comment:3 https://svn.boost.org/trac10/ticket/12408#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> Confirmed. Fixed in <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/6e3f814cecf18adffe517a3e5820afa29dcc8f86"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/6e3f814cecf18adffe517a3e5820afa29dcc8f86</a> </p> Ticket