bool Complex::is_canonical(const mpq_class &real, const mpq_class &imaginary) { mpq_class re = real; mpq_class im = imaginary; re.canonicalize(); im.canonicalize(); // If 'im' is 0, it should not be Complex: if (im.get_num() == 0) return false; // if 'real' or `imaginary` are not in canonical form: if (re.get_num() != real.get_num()) return false; if (re.get_den() != real.get_den()) return false; if (im.get_num() != imaginary.get_num()) return false; if (im.get_den() != imaginary.get_den()) return false; return true; }
Teuchos::RCP<Number> Rational::from_mpq(const mpq_class i) { // If the result is an Integer, return an Integer: if (i.get_den() == 1) { return rcp(new Integer(i.get_num())); } else { return rcp(new Rational(i)); } }
mpf_class MpfFromMpq(Signal &sig, const mpq_class &num) { mpf_class numer = num.get_num(); mpf_class denom = num.get_den(); if (denom == 0) { Operator::SetError_DivideByZero(sig); return mpf_class(0); } return numer / denom; }
bool Rational::is_canonical(const mpq_class &i) { mpq_class x = i; x.canonicalize(); // If 'x' is an integer, it should not be Rational: if (x.get_den() == 1) return false; // if 'i' is not in canonical form: if (x.get_num() != i.get_num()) return false; if (x.get_den() != i.get_den()) return false; return true; }
void serialize(Archive & ar, mpq_class & t, unsigned int version) { ar & t.get_num(); ar & t.get_den(); }
mpq_class getNextConvergent(int n, mpq_class c1, mpq_class c2) const { int a = (*this)[n]; return mpq_class(c1.get_num() + a * c2.get_num(), c1.get_den() + a * c2.get_den()); }
int convert_high_precision_type<int>(const mpq_class& v) { mpz_class num = v.get_num(); mpz_class den = v.get_den(); num /= den; return num.get_si(); };