With Java's BigDecimal, it's possible to have unlimited precision and specified rounding & scale with a string constructor.

I've seen GNU's GMP, boost's multiprecision, and MPFR, but none seem to have theses characteristics.

Can any of them do this? If so, how? If not, how can this be done?

有帮助吗?

解决方案

GMP is designed to have arbitrary precision with support for C++ using the gmpxx.h header, and corresponding library. If you're building GMP from scratch, use --enable-cxx flag during configure.

To construct an object from std::string, simply use the constructor, for example,

#include <gmpxx.h>

const std::string longNumber = "12345678901234567890";

mpz_class n(longNumber);

More details are available here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top