void RingZZ::elem_text_out(buffer &o, const ring_elem ap, bool p_one, bool p_plus, bool p_parens) const { mpz_ptr a = ap.get_mpz(); #warning "possible overflow in large int situations" char s[1000]; char *str; bool is_neg = (mask_mpz_cmp_si(a, 0) == -1); bool is_one = (mask_mpz_cmp_si(a, 1) == 0 || mask_mpz_cmp_si(a, -1) == 0); int size = static_cast<int>(mpz_sizeinbase(a, 10)) + 2; char *allocstr = (size > 1000 ? newarray_atomic(char,size) : s); if (!is_neg && p_plus) o << '+'; if (is_one) { if (is_neg) o << '-'; if (p_one) o << '1'; } else { str = mpz_get_str(allocstr, 10, a); o << str; } if (size > 1000) deletearray(allocstr); }
void RingZZ::syzygy(const ring_elem a, const ring_elem b, ring_elem &x, ring_elem &y) const { // First check the special cases a = 0, b = 1, -1. Other cases: use gcd. if (RingZZ::is_zero(a)) { x = RingZZ::from_int(1); y = RingZZ::from_int(0); return; } mpz_ptr bb = b.get_mpz(); if (mpz_cmp_ui(bb,1) == 0) { x = RingZZ::from_int(1); y = RingZZ::negate(a); return; } if (mask_mpz_cmp_si(bb,-1) == 0) { x = RingZZ::from_int(1); y = RingZZ::copy(a); return; } ring_elem g = RingZZ::gcd(a,b); y = RingZZ::divide(a,g); x = RingZZ::divide(b,g); RingZZ::remove(g); if (mpz_sgn(x.get_mpz()) > 0) RingZZ::internal_negate_to(y); else RingZZ::internal_negate_to(x); }
bool QQ::lift(const Ring *Rg, const ring_elem f, ring_elem &result) const { // Rg = ZZ ---> QQ // f is an element of QQ if (Rg->is_ZZ()) { gmp_QQ h = MPQ_VAL(f); if (mask_mpz_cmp_si(mpq_denref(h),1) == 0) { result = globalZZ->RingZZ::from_int(mpq_numref(h)); return true; } } return false; }
bool RingZZ::is_unit(const ring_elem f) const { mpz_ptr a = f.get_mpz(); return (mask_mpz_cmp_si(a, 1)==0 || mask_mpz_cmp_si(a, -1)==0); }