문제

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