1

当我使用时,long double我得到的精度比使用double. 3.14159265358979323846264Llong double const在源代码中编写好还是我应该添加其他内容L

编辑我解决了这个问题。我将算法更改为更精确。

4

1 回答 1

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";
于 2011-10-25T15:57:52.587 回答