1 #ifndef realroot_ARITHM_GMP_H
2 #define realroot_ARITHM_GMP_H
4 #include <realroot/config.hpp>
7 #include <realroot/sign.hpp>
32 inline long int bit_size(
const ZZ& z) {
return mpz_sizeinbase(z.get_mpz_t(),2);}
43 template<>
struct hasgcd_<ZZ> {
typedef meta::true_t
T; };
51 inline ZZ
gcd(
const ZZ & a,
const ZZ &
b)
54 mpz_gcd(r.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
58 inline ZZ
lcm(
const ZZ & a,
const ZZ &
b) {
return (a*b)/
gcd(a,b); }
61 inline int sign(
const QQ& a) {
return sgn(a); }
62 inline int sign(
const RR& a) {
return sgn(a); }
64 inline QQ
Size(
const QQ & r) {
return abs(r); };
65 inline ZZ
Size(
const ZZ & z ) {
return abs(z); };
67 inline ZZ
size(
const ZZ & z ) {
return abs(z); };
68 inline QQ
size(
const QQ & r) {
return abs(r); };
71 inline int compare(
const QQ& a,
const QQ&
b) {
return cmp(a, b); }
72 inline int compare(
const RR& a,
const RR&
b) {
return cmp(a, b); }
79 inline double to_double(
const QQ& a) {
return a.get_d(); }
80 inline double to_double(
const ZZ & z ) {
return z.get_d(); };
81 inline double to_double(
const RR& a) {
return a.get_d(); }
83 inline QQ
to_FT(
const ZZ& a,
const ZZ&
b = 1)
89 inline QQ
to_FT(
const QQ& a,
const QQ&
b = 1) {
return a; }
95 inline ZZ
numerator(
const QQ& a) {
return a.get_num(); }
98 inline ZZ
pow(
const ZZ& a,
unsigned n)
101 mpz_pow_ui(r.get_mpz_t(), a.get_mpz_t(), n);
105 inline RR
fracpart(
const RR& r) {
return r - trunc(r); }
114 mpf_set_default_prec(l);
123 mpf_set_prec(b.get_mpf_t(),l);
139 inline void assign(QQ & x,
char *s) { mpq_set_str(x.get_mpq_t(), s, 10);}
141 inline void assign(ZZ& z,
char * s) { mpz_set_str(z.get_mpz_t(), s, 10); }
142 inline void assign(ZZ& z,
int n) { mpz_set_si(z.get_mpz_t(),n); }
143 inline void assign(ZZ& z,
double d ) { z = (int)d; };
144 inline void assign(ZZ& x,
const ZZ& r) { mpz_set(x.get_mpz_t(),r.get_mpz_t()); }
145 inline void assign(
int& x,
const ZZ& r) { x = mpz_get_si(r.get_mpz_t()); }
146 inline void assign(
long int& x,
const ZZ& r) { x = mpz_get_si(r.get_mpz_t()); }
147 inline void assign(
double & r,
const ZZ & z ) { r = z.get_d(); };
149 inline void assign(ZZ& x,
const QQ& r) { x= r.get_num(); x/=r.get_den();}
150 inline void assign(QQ& x,
const ZZ& r) { mpq_set_z(x.get_mpq_t(), r.get_mpz_t());}
151 inline void assign(QQ & q,
double d ) { q = d; };
152 inline void assign(RR & r,
double d ) { r = d; };
153 inline void assign(
double & d,
const QQ & x )
156 mp_rnd_t round=GMP_RNDU;
163 mpfr_t r; mpfr_init2(r,53);
164 mpfr_set_q(r, x.get_mpq_t(), round);
165 d = mpfr_get_d(r,round);
171 inline void assign(
double & r,
const RR & z ) { r = z.get_d(); };
172 inline void assign(RR& r,
char* s) { mpf_set_str(r.get_mpf_t(),s,10); }
173 inline void assign(RR& x,
const RR& r) { mpf_set(x.get_mpf_t(),r.get_mpf_t()); }
175 inline double convert(
const QQ & q, meta::As<double> ) {
return q.get_d(); };
176 inline double convert(
const ZZ & z, meta::As<double> ) {
return z.get_d(); };
177 inline double convert(
const RR & r, meta::As<double> ) {
return r.get_d(); };
225 template<>
struct cast_helper<QQ,ZZ> {
static inline QQ
cv(
const ZZ& x) { QQ r;mpq_set_z(r.get_mpq_t(),x.get_mpz_t());
return r; } };
227 template<>
struct cast_helper<double,ZZ> {
static inline double cv(
const ZZ& x) {
return x.get_d(); } };
229 template<>
struct cast_helper<double,RR> {
static inline double cv(
const RR& x) {
return x.get_d(); } };
mpz_class integer
Definition: GMPXX.hpp:19
texp::rationalof< C >::T to_FT(const C &a, const C &b)
Definition: contfrac_intervaldata.hpp:93
T pow(const T &a, int i)
Definition: binomials.hpp:12
const C & b
Definition: Interval_glue.hpp:25
void Precision(unsigned long l)
Definition: GMPXX.hpp:112
const T & upper() const
Definition: Interval.hpp:99
QQ Size(const QQ &r)
Definition: GMPXX.hpp:64
MP swap(const MP &P, int var_i, int var_j)
Definition: sparse_monomials.hpp:988
bool with_plus_sign(const ZZ &c)
Definition: GMP.hpp:62
double gcd(const double &, const double &)
Definition: GMP.hpp:90
GMP::floating RR
Definition: GMP.hpp:39
static double cv(const QQ &x)
Definition: GMPXX.hpp:228
Definition: texp_structureof.hpp:13
static QQ cv(const ZZ &x)
Definition: GMPXX.hpp:225
int get_rnd()
Definition: rounding_mode.hpp:22
double to_double(const RR &a)
Definition: GMP.hpp:66
int compare(const QQ &a, const QQ &b)
Definition: GMPXX.hpp:71
double convert(const QQ &q, meta::As< double >)
Definition: GMPXX.hpp:175
Definition: rounding_mode.hpp:71
const T & lower() const
Definition: Interval.hpp:98
GMP::rational QQ
Definition: GMP.hpp:37
RR fracpart(const RR &r)
Definition: GMPXX.hpp:105
double ieee
Definition: GMPXX.hpp:22
mpf_class floating
Definition: GMPXX.hpp:21
double to_XT(const ZZ &a)
Definition: GMP.hpp:69
ZZ numerator(const QQ &a)
Definition: GMPXX.hpp:95
long int bit_size(const ZZ &z)
Definition: GMPXX.hpp:32
ZZ isqrt(const ZZ &a)
Definition: GMPXX.hpp:104
int sgn(FT a)
Sign of a.
Definition: solver_mv_monomial_tests.hpp:416
static double cv(const RR &x)
Definition: GMPXX.hpp:229
ZZ size(const ZZ &z)
Definition: GMPXX.hpp:67
void abs(Interval< C, r > &x, const Interval< C, r > &a)
Definition: Interval_fcts.hpp:185
scalar< T > sqrt(const scalar< T > &b)
Definition: scalar.hpp:501
ZZ denominator(const QQ &a)
Definition: GMPXX.hpp:96
const C & c
Definition: Interval_glue.hpp:45
mpq_class rational
Definition: GMPXX.hpp:20
int sign(const QQ &a)
Definition: GMP.hpp:60
void assign(A &a, const B &b)
Generic definition of the assignement function.
Definition: assign.hpp:97
Definition: scalar.hpp:24
Numerical kernel based on gmp.
Definition: GMP.hpp:26
GMP::integer ZZ
Definition: GMP.hpp:38
Definition: GMPXX.hpp:223
ZZ lcm(const ZZ &a, const ZZ &b)
Definition: GMPXX.hpp:58
static double cv(const ZZ &x)
Definition: GMPXX.hpp:227