Opened 6 years ago
Closed 6 years ago
#12408 closed Bugs (fixed)
cpp_dec_float_50 x = x*x*x gives wrong result!!!
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | To Be Determined | Component: | multiprecision |
Version: | Boost 1.61.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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;
}
Change History (3)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
Component: | None → multiprecision |
---|---|
Owner: | set to |
comment:3 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
#include <iomanip>
#include <iostream>
#include <boost/multiprecision/cpp_dec_float.hpp>
using boost::multiprecision::cpp_dec_float_50;
int main()
{
}