精度长双倍比双重差

Bla*_*bla 1 c++ double-precision long-double

当我使用时,long double我的精确度比使用时更差double. 在源代码中3.14159265358979323846264L写这个是好的long double const还是我应该添加其他东西L

编辑我解决了这个问题.我更准确地改变算法.

Mar*_*ork 5

你的精确度不会太差.

发生的事情是,当您打印出数字时,流库会截断显示的值.使用std :: setprecision获取特定的精度.

double        x = 1.0/3;
long double   y = 1.0/6;

// Prints out the precision
std::cout << "Limit: " << std::numeric_limits<double>::digits10 << "\n";
std::cout << "Limit: " << std::numeric_limits<long double>::digits10 << "\n";

// prints the numbers with max precision.
std::cout << std::setprecision(std::numeric_limits<double>::digits10) << x << "\n";
std::cout << std::setprecision(std::numeric_limits<long double>::digits10) << y << "\n";
Run Code Online (Sandbox Code Playgroud)