Pregunta

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?

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top