19 std::ostream& operator << (std::ostream& os, const scalar<MPQ>&
b);
31 {mpq_init(&
rep());mpq_set_si(&
rep(),si,1);}
35 {mpq_init(&
rep());mpq_set_ui(&
rep(),si,1);}
41 mpz_init_set_str(&tmp,
string, base);
43 mpq_set_z(&
rep(),&tmp);
48 {mpq_init(&
rep());mpq_set_si(&
rep(),sl,1);}
52 {mpq_init(&
rep());mpq_set_ui(&
rep(),ul,1);}
57 mpz_init_set(&
rep()._mp_num, &rhs.
rep()._mp_num);
58 mpz_init_set(&
rep()._mp_den, &rhs.
rep()._mp_den);
65 mpq_set_d(&
rep(), rhs);
75 mpq_set(&
rep(), &rhs.
rep());
82 return mpq_cmp(&
rep(), &rhs.
rep()) == 0;
88 return mpq_cmp_ui(&
rep(), sl, 1) == 0;
94 return mpq_cmp_ui(&
rep(), (
long) si, 1) == 0;
100 return mpq_cmp_ui(&
rep(), ul, 1) == 0;
107 return mpq_cmp(&
rep(), &rhs.
rep()) != 0;
113 return mpq_cmp_ui(&
rep(), sl,1) != 0;
119 return mpq_cmp_ui(&
rep(), (
long) si,1) != 0;
125 return mpq_cmp_ui(&
rep(), ul,1) != 0;
131 return mpq_cmp(&
rep(), &rhs.
rep()) > 0;
137 return mpq_cmp_ui(&
rep(), sl, 1) > 0;
143 return mpq_cmp_ui(&
rep(), (
long) si, 1) > 0;
149 return mpq_cmp_ui(&
rep(), ul,1) > 0;
155 return mpq_cmp(&
rep(), &rhs.
rep()) >= 0;
161 return mpq_cmp_ui(&
rep(), sl, 1) >= 0;
168 return mpq_cmp_ui(&
rep(), (
long) si, 1) >= 0;
174 return mpq_cmp_ui(&
rep(), ul, 1) >= 0;
181 return mpq_cmp(&
rep(), &rhs.
rep()) < 0;
186 return mpq_cmp_ui(&
rep(), sl, 1) < 0;
193 return mpq_cmp_ui(&
rep(), (
long) si, 1) < 0;
199 return mpq_cmp_ui(&
rep(), ul, 1) < 0;
207 return mpq_cmp(&
rep(), &rhs.
rep()) <= 0;
213 return mpq_cmp_ui(&
rep(), sl,1) <= 0;
220 return mpq_cmp_ui(&
rep(), (
long) si, 1) <= 0;
226 return mpq_cmp_ui(&
rep(), ul, 1) <= 0;
233 mpq_set_ui(&
rep(), ul, 1);
return *
this;
239 mpq_set_si(&
rep(), sl, 1);
return *
this;
245 mpq_set_si(&
rep(), ul, 1);
return *
this;
253 mpq_swap(&tmp.
rep(),&
rep());
388 mpq_add(&result.
rep(), &a1.
rep(), &a2.
rep());
397 mpq_sub(&result.
rep(), &a1.
rep(), &a2.
rep());
413 mpq_mul(&result.
rep(), &a1.
rep(), &a2.
rep());
444 mpq_div(&result.
rep(), &a1.
rep(), &a2.
rep());
473 std::ostream& operator << (std::ostream& os, const scalar<MPQ>&
b)
475 mpq_out_str(stdout, 10, &
b.rep());
480 return mpq_get_str(NULL,10,&b.
rep());
484 char * str= mpq_get_str(NULL,10,&b.
rep());
485 return std::string(str);
488 template<
class OSTREAM>
inline void
496 std::string s;is >> s;
498 mpz_init_set_str(&tmp,s.c_str(), 10);
500 mpq_set_z(&b.
rep(),&tmp);
506 template<>
inline void
509 if (
rep()._mp_num._mp_size < 0)
rep()._mp_num._mp_size = -
rep()._mp_num._mp_size;
515 rep()._mp_num._mp_size = -
rep()._mp_num._mp_size;
return *
this;
525 return mpq_cmp(&b1.
rep(), &b2.
rep());
530 return mpq_cmp_ui(&b.
rep(), ul, 1);
536 return mpq_cmp_ui(&b.
rep(), sl, 1);
545 mpq_clear(&dd.
rep());
547 mpz_set_str(mpq_numref(&dd.
rep()),s,10);
558 d = mpq_get_d(&x.
rep());
566 template<
typename T,
typename F>
struct as_helper;
574 #endif // //SCL_MPQ_H
bool operator>(const scalar< T > &rhs) const
scalar< T > & operator+=(const scalar< T > &rhs)
scalar()
Definition: scalar.hpp:37
const C & b
Definition: Interval_glue.hpp:25
scalar< T > & operator=(const scalar< T > &rhs)
bool operator>=(const scalar< T > &rhs) const
QQ Size(const QQ &r)
Definition: GMPXX.hpp:64
Definition: assign.hpp:48
T & rep()
Definition: scalar.hpp:30
R & rep(R &r)
Definition: shared_object.hpp:180
extended< NT > operator-(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:132
extended< NT > operator/(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:111
scalar< T > & operator-=(const scalar< T > &rhs)
double to_double(const RR &a)
Definition: GMP.hpp:66
int compare(const QQ &a, const QQ &b)
Definition: GMPXX.hpp:71
std::string to_string(int x)
to_string convert int to std::string In C++11, it should use std::to_string
Definition: assign.hpp:24
extended< NT > operator+(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:122
MP_RAT MPQ
Definition: scalar_rational.hpp:17
bool operator<(const scalar< T > &rhs) const
bool operator<=(const scalar< T > &rhs) const
bool operator!=(const scalar< T > &rhs) const
Interval< T, r > min(const Interval< T, r > &a, const Interval< T, r > &b)
Definition: Interval_fcts.hpp:130
scalar< T > & operator*=(const scalar< T > &rhs)
ZZ numerator(const QQ &a)
Definition: GMPXX.hpp:95
double rceil(double x)
Definition: scalar.hpp:536
scalar< T > & operator/=(const scalar< T > &rhs)
char * as_charp(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:444
void abs(Interval< C, r > &x, const Interval< C, r > &a)
Definition: Interval_fcts.hpp:185
void print(OSTREAM &os, const Interval< T, r > &a)
Definition: Interval.hpp:135
bool operator==(const scalar< T > &rhs) const
MP_INT MPZ
Definition: scalar_integer.hpp:18
static double cv(const scalar< MPQ > &x)
Definition: scalar_rational.hpp:569
ZZ denominator(const QQ &a)
Definition: GMPXX.hpp:96
std::istream & operator>>(std::istream &is, scalar< MPF > &b)
Definition: scalar_floating.hpp:453
void convert(scalar< MPF > &n, char *s)
Definition: scalar_floating.hpp:433
void assign(A &a, const B &b)
Generic definition of the assignement function.
Definition: assign.hpp:97
Interval< T, r > max(const Interval< T, r > &a, const Interval< T, r > &b)
Definition: Interval_fcts.hpp:135
double rfloor(double x)
Definition: scalar.hpp:535
extended< NT > operator*(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:101
double as_double(const RR &a)
Definition: GMP.hpp:67
Definition: scalar.hpp:24
~scalar()
Definition: scalar.hpp:55
#define assert(expr, msg)
Definition: shared_object.hpp:57