// this file implements the routines required by gmpfrxx.h // it is modeled on mpfr-2.2.1/out_str.c // gmp-4.2.1/mpz/set_f.c // gmp-4.2.1/mpq/set_f.c // (written by Jon Wilkening on Aug 8, 2007) #include "gmpfrxx.h" using namespace std; // MpFrC is a dummy class holding the static members of mpfr_class mpfr_rnd_t MpFrC::rnd = GMP_RNDN; int MpFrC::base = 10; istream & operator>>(istream &s, mpfr_ptr a) { string tmp; s >> tmp; mpfr_set_str(a, tmp.c_str(), mpfr_class::get_base(), mpfr_class::get_rnd()); // a = tmp.c_str(); return s; } // modeled on mpfr-2.2.1/out_str.c ostream & operator<<(ostream &os, mpfr_srcptr a) { char *s, *t, *s0; mp_exp_t e; // for debugging: // mpfr_out_str(stdout, 10, 0, a, RND); printf("\n"); if (mpfr_nan_p(a)) { os << "@NaN@"; return os; } if (mpfr_inf_p(a)) { if (MPFR_SIGN(a) > 0) os << "@Inf@"; else os << "-@Inf@"; return os; } if (mpfr_zero_p(a)) { if (MPFR_SIGN(a) > 0) os << "0"; else os << "-0"; return os; } s = mpfr_get_str (NULL, &e, mpfr_class::get_base(), 0, a, mpfr_class::get_rnd()); t = mpfr_get_str (NULL, &e, mpfr_class::get_base(), os.precision(), a, mpfr_class::get_rnd()); if (strlen(s) s = "101001", e = 2 s = mpfr_get_str (NULL, &e, 2, 0, u, GMP_RNDN); sz = strlen(s); t = s+sz; while (*(--t) == '0') *t = '\0'; // trim trailing zeros sz = strlen(s); bits = (*s == '-') ? sz-1 : sz; // bits>0 since u!=0 if (e>=bits) { e = sz+e-bits; // no denominator needed t = (char *) malloc((e+1)*sizeof(char)); strcpy(t,s); for (k=sz; k