Macaulay2 Engine
Loading...
Searching...
No Matches
gmp-util.h
Go to the documentation of this file.
1#ifndef _gmp_util_h_
2# define _gmp_util_h_
3
35
36# include "engine-includes.hpp"
37
41
42# if defined(__cplusplus)
43extern "C" {
44# endif
45
46inline void mpz_reallocate_limbs (mpz_ptr _z)
47{
48 int _s = _z->_mp_size;
49 int _as = (_s>0)?_s:-_s;
50 mp_limb_t *_p = (mp_limb_t*) getmem_atomic(_as*sizeof(mp_limb_t));
51 memcpy(_p,_z->_mp_d,_as*sizeof(mp_limb_t));
52 mpz_clear(_z);
53 _z->_mp_d = _p;
54 _z->_mp_size = _s;
55 _z->_mp_alloc = _as;
56}
57
58 inline gmp_QQ moveTo_gmpQQ (mpq_ptr z)
59 {
60 mpz_reallocate_limbs(mpq_numref(z));
61 mpz_reallocate_limbs(mpq_denref(z));
62 return z;
63 }
64
65inline void mpfr_reallocate_limbs (mpfr_ptr _z)
66{
67 __mpfr_struct tmp;
68 tmp = *_z;
69 int limb_size = (_z->_mpfr_prec - 1) / GMP_NUMB_BITS + 1;
70 mp_limb_t *p = (mp_limb_t*) getmem_atomic(limb_size * sizeof(mp_limb_t));
71 memcpy(p, _z->_mpfr_d, limb_size * sizeof(mp_limb_t));
72 mpfr_clear(_z);
73 _z->_mpfr_prec = tmp._mpfr_prec;
74 _z->_mpfr_sign = tmp._mpfr_sign;
75 _z->_mpfr_exp = tmp._mpfr_exp;
76 _z->_mpfr_d = p;
77}
78
79inline void mpfi_reallocate_limbs (mpfi_ptr _z)
80{
81 mpfr_reallocate_limbs(&(_z->left));
82 mpfr_reallocate_limbs(&(_z->right));
83}
84
96 typedef struct {
97 mpfr_srcptr re;
98 mpfr_srcptr im;
99 } CC_struct;
100
113 typedef struct {
114 mpfr_ptr re;
115 mpfr_ptr im;
117
118 // typedef CCmutable_struct* gmp_CCmutable;
119 // typedef CC_struct* gmp_CC;
120
131typedef struct {
132 mpfi_srcptr re;
133 mpfi_srcptr im;
134} CCi_struct;
135
145typedef struct {
146 mpfi_ptr re;
147 mpfi_ptr im;
149
150// typedef CCimutable_struct* gmp_CCimutable;
151// typedef CCi_struct* gmp_CCi;
152
153 inline mpfr_srcptr moveTo_gmpRR (mpfr_ptr _z)
154 {
156 return _z;
157 }
158
159 inline mpfi_srcptr moveTo_gmpRRi (mpfi_ptr _z)
160 {
161 mpfr_reallocate_limbs(&(_z->left));
162 mpfr_reallocate_limbs(&(_z->right));
163 return _z;
164 }
165
167 {
171 return (gmp_CC) a;
172 }
173
175{
177 mpfr_reallocate_limbs(&(a->re->left));
178 mpfr_reallocate_limbs(&(a->re->right));
179 mpfr_reallocate_limbs(&(a->im->left));
180 mpfr_reallocate_limbs(&(a->im->right));
181 return (gmp_CCi) a;
182}
183
184# if defined(__cplusplus)
185 }
186# endif
187
188#endif /* _gmp_util_h_ */
189
190// Local Variables:
191// indent-tabs-mode: nil
192// End:
Engine-wide include prelude — a single point of truth for portability shims.
gmp_CCi moveTo_gmpCCi(gmp_CCimutable _z)
Definition gmp-util.h:174
void mpfi_reallocate_limbs(mpfi_ptr _z)
Definition gmp-util.h:79
gmp_CC moveTo_gmpCC(gmp_CCmutable _z)
Definition gmp-util.h:166
void mpfr_reallocate_limbs(mpfr_ptr _z)
Definition gmp-util.h:65
mpfr_srcptr moveTo_gmpRR(mpfr_ptr _z)
Definition gmp-util.h:153
gmp_QQ moveTo_gmpQQ(mpq_ptr z)
Definition gmp-util.h:58
mpfi_srcptr moveTo_gmpRRi(mpfi_ptr _z)
Definition gmp-util.h:159
void mpz_reallocate_limbs(mpz_ptr _z)
Definition gmp-util.h:46
int p
char * getmem_atomic(size_t n)
Definition m2-mem.cpp:135
struct gmp_CC_struct * gmp_CC
Definition m2-types.h:156
struct gmp_CCmutable_struct * gmp_CCmutable
Definition m2-types.h:159
mpq_srcptr gmp_QQ
Definition m2-types.h:145
struct gmp_CCi_struct * gmp_CCi
Definition m2-types.h:162
struct gmp_CCimutable_struct * gmp_CCimutable
Definition m2-types.h:165
mpfr_srcptr im
Definition gmp-util.h:98
mpfr_srcptr re
Definition gmp-util.h:97
Immutable view of a complex number as a pair of mpfr_srcptr real and imaginary parts.
Definition gmp-util.h:96
mpfi_srcptr im
Definition gmp-util.h:133
mpfi_srcptr re
Definition gmp-util.h:132
Immutable view of a complex interval as a pair of mpfi_srcptr real and imaginary parts.
Definition gmp-util.h:131
Mutable view of a complex interval as a pair of mpfi_ptr real and imaginary parts.
Definition gmp-util.h:145
Mutable view of a complex number as a pair of mpfr_ptr real and imaginary parts.
Definition gmp-util.h:113