Ilyas Hamadouche(deleted)
|
Can I use long double without losing precision?
|
Ilyas Hamadouche(deleted)
12/31/2018 7:29 AM
post119377
|
Can I use long double without losing precision?
std::istringstream is losing precision when converting a string to long double.
Some people told me it is because an 80-bit double (long double) is not large enough to store the number. Is this issue
related to QNX itself or some compiling flags are missing?
To demonstrate the problem, I wrote this code:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
int main(){
long double convertedNumber;
std::string numberString ("5.94865747678615882510631e+4931");
//From string to long double
std::istringstream iss(numberString);
iss >> convertedNumber;
std::cout<< std::setprecision(30) << numberString << "\n";
std::cout<< std::setprecision(30) << convertedNumber << "\n";
return 0;
}
The output is always:
5.94865747678615882510631e+4931
5.9486574767861588254e+4931
Compiled with:
QCC -V5.4.0,gcc_ntox86_64 main.cpp -o qnxTest -std=gnu++14
|
|
|