Ben*_*ley 21
该Boost.Multiprecision库有一个叫做基于十进制浮点模板类cpp_dec_float,以便您可以指定任何你想要的精确度.
#include <iostream>
#include <iomanip>
#include <boost/multiprecision/cpp_dec_float.hpp>
int main()
{
namespace mp = boost::multiprecision;
// here I'm using a predefined type that stores 100 digits,
// but you can create custom types very easily with any level
// of precision you want.
typedef mp::cpp_dec_float_100 decimal;
decimal tiny("0.0000000000000000000000000000000000000000000001");
decimal huge("100000000000000000000000000000000000000000000000");
decimal a = tiny;
while (a != huge)
{
std::cout.precision(100);
std::cout << std::fixed << a << '\n';
a *= 10;
}
}
Run Code Online (Sandbox Code Playgroud)
是:
C++有任意精度库.
一个很好的例子是GNU Multiple Precision算术库.
| 归档时间: |
|
| 查看次数: |
16756 次 |
| 最近记录: |