94 double a1 = mpfr_get_d(&a.
re, MPFR_RNDN);
95 double b1 = mpfr_get_d(&a.
im, MPFR_RNDN);
96 return static_cast<unsigned int>(12347. * a1 + 865800. * b1);
106 return mpfr_cmp_si(&f.
re, 0) == 0 && mpfr_cmp_si(&f.
im, 0) == 0;
111 return mpfr_cmp(&f.
re, &g.
re) == 0 && mpfr_cmp(&f.
im, &g.
im) == 0;
116 int cmp_re = mpfr_cmp(&f.
re, &g.
re);
117 if (cmp_re < 0)
return -1;
118 if (cmp_re > 0)
return 1;
119 int cmp_im = mpfr_cmp(&f.
im, &g.
im);
120 if (cmp_im < 0)
return -1;
121 if (cmp_im > 0)
return 1;
159 mpfr_set(&
result.re, &a.
re, MPFR_RNDN);
160 mpfr_set(&
result.im, &a.
im, MPFR_RNDN);
165 mpfr_set(&
result.re, &a.
re, MPFR_RNDN);
166 mpfr_set(&
result.im, &a.
im, MPFR_RNDN);
171 mpfr_set_si(&
result.re, 0, MPFR_RNDN);
172 mpfr_set_si(&
result.im, 0, MPFR_RNDN);
184 mpfr_set_si(&
result.re, a, MPFR_RNDN);
185 mpfr_set_si(&
result.im, 0, MPFR_RNDN);
196 mpfr_set_z(&
result.re, a, MPFR_RNDN);
197 mpfr_set_si(&
result.im, 0, MPFR_RNDN);
202 mpfr_set_q(&
result.re, a, MPFR_RNDN);
203 mpfr_set_si(&
result.im, 0, MPFR_RNDN);
209 mpfr_set(&
result.re, a, MPFR_RNDN);
210 mpfr_set_si(&
result.im, 0, MPFR_RNDN);
215 mpfr_set(&
result.re, a->re, MPFR_RNDN);
216 mpfr_set(&
result.im, a->im, MPFR_RNDN);
221 mpfr_set_d(&
result.re, a, MPFR_RNDN);
222 mpfr_set_si(&
result.im, 0, MPFR_RNDN);
227 mpfr_set_d(&
result.re, re, MPFR_RNDN);
228 mpfr_set_d(&
result.im, im, MPFR_RNDN);
233 mpfr_set(&
result.re, re, MPFR_RNDN);
234 mpfr_set(&
result.im, im, MPFR_RNDN);
241 mpfr_neg(&
result.re, &a.
re, MPFR_RNDN);
242 mpfr_neg(&
result.im, &a.
im, MPFR_RNDN);
252 if (mpfr_cmpabs(&a.re, &a.im) >= 0)
259 mpfr_div(
p, &a.im, &a.re, MPFR_RNDN);
260 mpfr_mul(denom,
p, &a.im, MPFR_RNDN);
261 mpfr_add(denom, denom, &a.re, MPFR_RNDN);
262 mpfr_si_div(&
result.re, 1, denom, MPFR_RNDN);
263 mpfr_div(&
result.im,
p, denom, MPFR_RNDN);
273 mpfr_div(
p, &a.re, &a.im, MPFR_RNDN);
274 mpfr_mul(denom,
p, &a.re, MPFR_RNDN);
275 mpfr_add(denom, denom, &a.im, MPFR_RNDN);
276 mpfr_si_div(&
result.im, 1, denom, MPFR_RNDN);
278 mpfr_div(&
result.re,
p, denom, MPFR_RNDN);
289 mpfr_add(&
result.re, &a.
re, &b.
re, MPFR_RNDN);
290 mpfr_add(&
result.im, &a.
im, &b.
im, MPFR_RNDN);
314 mpfr_sub(&
result.re, &a.
re, &b.
re, MPFR_RNDN);
315 mpfr_sub(&
result.im, &a.
im, &b.
im, MPFR_RNDN);
337 mpfr_mul(tmp, &a.
re, &b, MPFR_RNDN);
338 mpfr_set(&
result.value().re, tmp, MPFR_RNDN);
341 mpfr_mul(tmp, &a.
im, &b, MPFR_RNDN);
342 mpfr_set(&
result.value().im, tmp, MPFR_RNDN);
355 mpfr_mul(tmp, &a.
re, &b.
re, MPFR_RNDN);
356 mpfr_set(&
result.value().re, tmp, MPFR_RNDN);
357 mpfr_mul(tmp, &a.
im, &b.
im, MPFR_RNDN);
358 mpfr_sub(&
result.value().re, &
result.value().re, tmp, MPFR_RNDN);
361 mpfr_mul(tmp, &a.
re, &b.
im, MPFR_RNDN);
362 mpfr_set(&
result.value().im, tmp, MPFR_RNDN);
363 mpfr_mul(tmp, &a.
im, &b.
re, MPFR_RNDN);
364 mpfr_add(&
result.value().im, &
result.value().im, tmp, MPFR_RNDN);
378 mpfr_div(tmp, &a.
re, &b, MPFR_RNDN);
379 mpfr_set(&
result.value().re, tmp, MPFR_RNDN);
381 mpfr_div(tmp, &a.
im, &b, MPFR_RNDN);
382 mpfr_set(&
result.value().im, tmp, MPFR_RNDN);
397 if (mpfr_cmpabs(&b.
re, &b.
im) >= 0)
409 mpfr_div(
p, &b.
im, &b.
re, MPFR_RNDN);
410 mpfr_mul(denom,
p, &b.
im, MPFR_RNDN);
411 mpfr_add(denom, denom, &b.
re, MPFR_RNDN);
413 mpfr_mul(&
result.value().re,
p, &a.
im, MPFR_RNDN);
414 mpfr_add(&
result.value().re, &
result.value().re, &a.
re, MPFR_RNDN);
415 mpfr_div(&
result.value().re, &
result.value().re, denom, MPFR_RNDN);
417 mpfr_mul(&
result.value().im,
p, &a.
re, MPFR_RNDN);
418 mpfr_neg(&
result.value().im, &
result.value().im, MPFR_RNDN);
419 mpfr_add(&
result.value().im, &
result.value().im, &a.
im, MPFR_RNDN);
420 mpfr_div(&
result.value().im, &
result.value().im, denom, MPFR_RNDN);
429 mpfr_div(
p, &b.
re, &b.
im, MPFR_RNDN);
430 mpfr_mul(denom,
p, &b.
re, MPFR_RNDN);
431 mpfr_add(denom, denom, &b.
im, MPFR_RNDN);
433 mpfr_mul(&
result.value().re,
p, &a.
re, MPFR_RNDN);
434 mpfr_add(&
result.value().re, &
result.value().re, &a.
im, MPFR_RNDN);
435 mpfr_div(&
result.value().re, &
result.value().re, denom, MPFR_RNDN);
437 mpfr_mul(&
result.value().im,
p, &a.
im, MPFR_RNDN);
438 mpfr_sub(&
result.value().im, &
result.value().im, &a.
re, MPFR_RNDN);
439 mpfr_div(&
result.value().im, &
result.value().im, denom, MPFR_RNDN);
449 ARingRRR::Element
s(
mRRR);
484 mult(curr_pow, curr_pow, curr_pow);
500 mpfr_swap(&a.
re, &b.
re);
501 mpfr_swap(&a.
im, &b.
im);
505 const ElementType& a,
508 bool p_parens =
false)
const;
545 ERROR(
"cannot map CC value to ring type");
556 mpfr_set(
result->re, &a.
re, MPFR_RNDN);
557 mpfr_set(
result->im, &a.
im, MPFR_RNDN);
563 mpfr_set(&
result.re, &a, MPFR_RNDN);
564 mpfr_set_si(&
result.im, 0, MPFR_RNDN);
579 mpfr_set(&c.
re, &a, MPFR_RNDN);
583 mpfr_set(&c.
im, &a, MPFR_RNDN);
587 mpfr_set(&
result.re, re, MPFR_RNDN);
588 mpfr_set(&
result.im, im, MPFR_RNDN);
598 mRRR.zeroize_tiny(epsilon, a.
re);
599 mRRR.zeroize_tiny(epsilon, a.
im);
603 ARingRRR::Element n(
mRRR);
605 if (mpfr_cmp(&n.value(), norm) > 0)
mRRR.set(*norm, n);
M2::ARingRRR — arbitrary-precision real numbers backed by MPFR.
Shared base of the aring framework (namespace M2) that unifies the engine's coefficient rings.
Append-only GC-backed byte buffer used throughout the engine for text output.
void addMultipleTo(ElementType &result, const RealElementType &a, const ElementType &b) const
void set_from_long(ElementType &result, long a) const
bool is_zero(const ElementType &f) const
void add(ElementType &result, const ElementType &a, const ElementType &b) const
bool set_from_BigReal(ElementType &result, gmp_RR a) const
bool set_from_complex_mpfr(ElementType &result, mpfr_srcptr re, const mpfr_srcptr im) const
void abs(ARingRRR::ElementType &result, const ElementType &a) const
gmp_CC toBigComplex(const ElementType &a) const
bool is_unit(const ElementType &f) const
unsigned int computeHashValue(const ElementType &a) const
ARingCCC(unsigned long precision)
size_t characteristic() const
void subtract(ElementType &result, const ElementType &a, const ElementType &b) const
void text_out(buffer &o) const
void set_from_BigReals(ElementType &result, gmp_RR re, gmp_RR im) const
void random(ElementType &result) const
bool set_from_complex_double(ElementType &result, double re, double im) const
void init(ElementType &result) const
void negate(ElementType &result, const ElementType &a) const
bool is_equal(const ElementType &f, const ElementType &g) const
void increase_norm(gmp_RRmutable norm, const ElementType &a) const
void set_from_mpz(ElementType &result, mpz_srcptr a) const
RealRingType::ElementType RealElementType
unsigned long get_precision() const
int compare_elems(const ElementType &f, const ElementType &g) const
void eval(const RingMap *map, ElementType &f, int first_var, ring_elem &result) const
const RealRingType & real_ring() const
void mult(ElementType &res, const ElementType &a, const RealElementType &b) const
bool set_from_RRR(ElementType &result, const ARingRRR::ElementType &a) const
const ElementType & from_ring_elem_const(const ring_elem &a) const
bool set_from_mpq(ElementType &result, mpq_srcptr a) const
void swap(ElementType &a, ElementType &b) const
static const RingID ringID
void power_mpz(ElementType &result, const ElementType &a, mpz_srcptr n) const
void mult(ElementType &res, const ElementType &a, const ElementType &b) const
void from_ring_elem(ElementType &result, const ring_elem &a) const
void subtract_multiple(ElementType &result, const ElementType &a, const ElementType &b) const
void power(ElementType &result, const ElementType &a, int n) const
void set_zero(ElementType &result) const
static void clear(ElementType &result)
void elem_text_out(buffer &o, const ElementType &a, bool p_one=true, bool p_plus=false, bool p_parens=false) const
void init_set(ElementType &result, const ElementType &a) const
void divide(ElementType &res, const ElementType &a, const ElementType &b) const
void set_imaginary_part(ElementType &c, ARingRRR::ElementType &a) const
bool set_from_double(ElementType &result, double a) const
const ARingRRR::ElementType & realPartReference(const ElementType &a) const
void zeroize_tiny(gmp_RR epsilon, ElementType &a) const
void set_from_doubles(ElementType &result, double re, double im) const
void syzygy(const ElementType &a, const ElementType &b, ElementType &x, ElementType &y) const
void copy(ElementType &result, const ElementType &a) const
const ARingRRR::ElementType & imaginaryPartReference(const ElementType &a) const
bool set_from_BigComplex(ElementType &result, gmp_CC a) const
void set(ElementType &result, const ElementType &a) const
void to_ring_elem(ring_elem &result, const ElementType &a) const
void set_real_part(ElementType &c, ARingRRR::ElementType &a) const
void abs_squared(ARingRRR::ElementType &result, const ElementType &a) const
void addMultipleTo(ElementType &result, const ElementType &a, const ElementType &b) const
void set_var(ElementType &result, int v) const
void divide(ElementType &res, const ElementType &a, const RealElementType &b) const
void invert(ElementType &result, const ElementType &a) const
aring-style adapter for arbitrary-precision real numbers, backed by MPFR.
A base class for simple ARings.
virtual bool from_BigComplex(gmp_CC z, ring_elem &result) const
virtual ring_elem from_long(long n) const =0
const Ring * get_ring() const
Engine-side ring homomorphism: stores, for each source-ring variable, the target-ring element it maps...
static std::pair< bool, int > get_si(mpz_srcptr n)
gmp_CC moveTo_gmpCC(gmp_CCmutable _z)
void mpfr_reallocate_limbs(mpfr_ptr _z)
Inline helpers that move GMP / MPFR / MPFI limbs from malloc-managed storage into the bdwgc heap.
VALGRIND_MAKE_MEM_DEFINED & result(result)
#define getmemstructtype(S)
struct gmp_CC_struct * gmp_CC
struct gmp_CCmutable_struct * gmp_CCmutable
void randomMpfr(mpfr_t result)
Engine-boundary C API for the engine's PRNG and rational / real / complex random draws.
ring_elem — the universal value type carried by every Ring* in the engine.
RingMap — engine representation of a ring homomorphism.