If your compiler/architecture allows it, you could use something like long double
, which compiles to an 80-bit float (though I think it aligns to 128 bits, so there's a bit of wasted space) and has more range and precision than a typical double
value. Not all compilers will do that though, and on many compilers, long double
is equivalent to a double
, at 64-bits.
"gmp" is one library you could use for extended precision floats. I generally recommend boost.multiprecision, which includes gmp, though personally, I'd use cpp_bin_float
or cpp_dec_float
for my multiprecision needs (the former is IEEE756 compliant, the latter isn't)
As for how to use them: I haven't used gmp, so I can't comment on its syntax, but cpp_bin_float
is pretty easy to use:
typedef boost::multiprecision::cpp_bin_float_quad quad;
quad a = 34;
quad b = 17.95467;
b += a;
for(int i = 0; i < 10; i++) {
b *= b;
}
std::cout << "This might be rather big: " << b << std::endl;