Subject: [Boost-bugs] [Boost C++ Libraries] #12408: cpp_dec_float_50 x = x*x*x gives wrong result!!!
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-08-23 11:42:26
#12408: cpp_dec_float_50 x = x*x*x gives wrong result!!!
---------------------------------------+------------------------------
Reporter: Dave Nalepa <denalepa1@â¦> | Type: Bugs
Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.61.0
Severity: Problem | Keywords:
---------------------------------------+------------------------------
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 <boost/multiprecision/cpp_dec_float.hpp>
using boost::multiprecision::cpp_dec_float_50;
// both at the global level = before main(){...
I set f2 to this and then use the line
f2 = f2*f2*f2; //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 // 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.
//===================================== here's the entire program (stub)
// I've shortened 1.03559... but I still get the wrong value.
#include <iomanip>
#include <iostream>
#include <boost/multiprecision/cpp_dec_float.hpp>
using boost::multiprecision::cpp_dec_float_50;
int main()
{
cpp_dec_float_50 f2 = (cpp_dec_float_50)(1.03559);
f2 = f2*f2*f2;
std::cout << "f2 = " << f2 << std::endl;
// gives me 1.15.... which is wrong should be 1.1106...
// it is actually the value of f2*f2*f2*f2, or close to it.
return 0;
}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12408> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC