bool try_convert(long& ret, const mpz_class& val) { if (!val.fits_slong_p()) { return false; } ret = val.get_si(); return true; }
inline void convert(const mpz_class& v1, long int& v2) { // TODO: Better precision exception information. if (!v1.fits_slong_p()) { throw PrecisionException(0); } v2 = v1.get_si(); }
bool try_convert(long long& ret, const mpz_class& val) { if (val.fits_slong_p()) { ret = val.get_si(); return true; } if (sizeof(long long)==sizeof(long)) { return false; } mpz_class quot; ret = mpz_fdiv_q_ui(quot.get_mpz_t(), val.get_mpz_t(), LONG_MAX); //returns remainder if (!quot.fits_slong_p()){ return false; } ret += ((long long) quot.get_si())*((long long) LONG_MAX); return true; }