void ARingCC::elem_text_out(buffer &o, const ElementType &ap, bool p_one, bool p_plus, bool p_parens) const { ElementType& ap1 = const_cast<ElementType&>(ap); gmp_CC_struct g; g.re = getmemstructtype(gmp_RR); g.im = getmemstructtype(gmp_RR); mpfr_init2(g.re,53); mpfr_init2(g.im,53); mpfr_set_d(g.re, ap1.re, GMP_RNDN); mpfr_set_d(g.im, ap1.im, GMP_RNDN); M2_string s = p_parens ? (*gmp_tonetCCparenpointer)(&g) : (*gmp_tonetCCpointer)(&g); mpfr_clear(g.im); mpfr_clear(g.re); delete g.re; delete g.im; bool prepend_plus = p_plus && (s->array[0] != '-'); bool strip_last = !p_one && ( (s->len == 1 && s->array[0] == '1') || (s->len == 2 && s->array[1] == '1' && s->array[0] == '-')); if (prepend_plus) o << "+"; if (strip_last) o.put(s->array, s->len-1); else o.put(s->array, s->len); }
gmp_RRorNull IM2_RingElement_to_BigReal(const RingElement *a) { const Ring *R = a->get_ring(); gmp_RR result; void *b; double *c; const M2::ConcreteRing<M2::ARingRRR> *R1; switch (R->ringID()) { case M2::ring_RR: result = getmemstructtype(gmp_RR); mpfr_init2(result, 53); b = static_cast<void *>(a->get_value().poly_val); c = static_cast<double *>(b); mpfr_set_d(result, *c, GMP_RNDN); return result; case M2::ring_RRR: R1 = dynamic_cast<const M2::ConcreteRing<M2::ARingRRR> *>(a->get_ring()); result = getmemstructtype(gmp_RR); mpfr_init2(result, R1->get_precision()); b = a->get_value().poly_val; mpfr_set(result, static_cast<gmp_RR>(b), GMP_RNDN); return result; default: if (!a->get_ring()->is_RRR()) { ERROR("expected an element of RRR"); return 0; } return a->get_value().mpfr_val; } }
gmp_CC toBigComplex(const ElementType& a) const { gmp_CC result = getmemstructtype(gmp_CC); result->re = getmemstructtype(gmp_RR); result->im = getmemstructtype(gmp_RR); mpfr_init2(result->re,get_precision()); mpfr_init2(result->im,get_precision()); mpfr_set_d(result->re, a.re, GMP_RNDN); mpfr_set_d(result->im, a.im, GMP_RNDN); return result; }
void to_ring_elem(ring_elem &result, const ElementType& a) const { gmp_QQ b = getmemstructtype(gmp_QQ); mpq_init(b); mpq_set(b,&a); result.poly_val = reinterpret_cast<Nterm*>(b); }
//////////////////////////// // to/from ringelem //////// //////////////////////////// // These simply repackage the element as either a ringelem or an 'ElementType'. // No reinitialization is done. // Do not take the same element and store it as two different ring_elem's!! void to_ring_elem(ring_elem &result, const ElementType &a) const { complex* res = getmemstructtype(complex_struct_ptr); init(*res); set(*res, a); result.poly_val = reinterpret_cast<Nterm*>(res); }
//////////////////////////// // to/from ringelem //////// //////////////////////////// // These simply repackage the element as either a ringelem or an 'ElementType'. // No reinitialization is done. // Do not take the same element and store it as two different ring_elem's!! void to_ring_elem(ring_elem &result, const ElementType &a) const { mpfr_ptr res = getmemstructtype(mpfr_ptr); mpfr_init2(res,mPrecision); mpfr_set(res, &a, GMP_RNDN); result = MPF_RINGELEM(res); }
void to_ring_elem(ring_elem& result, const ElementType& a) const { mpz_ptr b = getmemstructtype(mpz_ptr); mpz_init(b); mpz_set(b, &a); result.poly_val = reinterpret_cast<Nterm*>(b); }
mpz_ptr RingZZ::new_elem() const { mpz_ptr result = getmemstructtype(mpz_ptr); mpz_init(result); return result; }
gmp_QQ QQ::new_elem() const { gmp_QQ result = getmemstructtype(gmp_QQ); mpq_init(result); return result; }