29 ap_coeff_init(&c, AP_COEFF_SCALAR);
32 inline coeff::coeff(
const coeff& x)
34 ap_coeff_init(&c, x.
c.discr);
43 ap_coeff_init(&c, AP_COEFF_SCALAR);
47 inline coeff::coeff(
int x)
49 ap_coeff_init(&c, AP_COEFF_SCALAR);
50 ap_coeff_set_scalar_int(&c, x);
53 inline coeff::coeff(
long x)
55 ap_coeff_init(&c, AP_COEFF_SCALAR);
56 ap_coeff_set_scalar_int(&c, x);
59 inline coeff::coeff(
double x)
61 ap_coeff_init(&c, AP_COEFF_SCALAR);
62 ap_coeff_set_scalar_double(&c, x);
65 inline coeff::coeff(
const frac& x)
67 ap_coeff_init(&c, AP_COEFF_SCALAR);
68 ap_coeff_set_scalar_frac(&c, x.
num, x.
den);
71 inline coeff::coeff(
const mpq_class& x)
73 ap_coeff_init(&c, AP_COEFF_SCALAR);
74 ap_coeff_set_scalar_mpq(&c,
const_cast<mpq_class&
>(x).get_mpq_t());
77 inline coeff::coeff(mpfr_t x)
79 ap_coeff_init(&c, AP_COEFF_SCALAR);
80 ap_coeff_set_scalar_mpfr(&c,x);
88 ap_coeff_init(&c, AP_COEFF_INTERVAL);
89 ap_coeff_set_interval(&c,
95 ap_coeff_init(&c, AP_COEFF_INTERVAL);
96 ap_coeff_set_interval_scalar(&c,
101 inline coeff::coeff(
int inf,
int sup)
103 ap_coeff_init(&c, AP_COEFF_INTERVAL);
104 ap_coeff_set_interval_int(&c, inf, sup);
107 inline coeff::coeff(
long inf,
long sup)
109 ap_coeff_init(&c, AP_COEFF_INTERVAL);
110 ap_coeff_set_interval_int(&c, inf, sup);
113 inline coeff::coeff(
double inf,
double sup)
115 ap_coeff_init(&c, AP_COEFF_INTERVAL);
116 ap_coeff_set_interval_double(&c, inf, sup);
119 inline coeff::coeff(
const frac& inf,
const frac& sup)
121 ap_coeff_init(&c, AP_COEFF_INTERVAL);
122 ap_coeff_set_interval_frac(&c, inf.
num, inf.
den, sup.
num, sup.
den);
125 inline coeff::coeff(
const mpq_class& inf,
const mpq_class& sup)
127 ap_coeff_init(&c, AP_COEFF_INTERVAL);
128 ap_coeff_set_interval_mpq(&c,
129 const_cast<mpq_class&
>(inf).get_mpq_t(),
130 const_cast<mpq_class&
>(sup).get_mpq_t());
133 inline coeff::coeff(mpfr_t inf, mpfr_t sup)
135 ap_coeff_init(&c, AP_COEFF_INTERVAL);
136 ap_coeff_set_interval_mpfr(&c,inf,sup);
139 inline coeff::coeff(
top t)
141 ap_coeff_init(&c, AP_COEFF_INTERVAL);
142 ap_coeff_set_interval_top(&c);
147 ap_coeff_init(&c, AP_COEFF_INTERVAL);
148 ap_coeff_set_interval_int(&c, 1, -1);
155 inline coeff::~coeff()
172 ap_coeff_set_scalar(&c,
const_cast<ap_scalar_t*
>(x.
get_ap_scalar_t()));
176 inline coeff& coeff::operator= (
int x)
178 ap_coeff_set_scalar_int(&c, x);
182 inline coeff& coeff::operator= (
long x)
184 ap_coeff_set_scalar_int(&c, x);
188 inline coeff& coeff::operator= (
double x)
190 ap_coeff_set_scalar_double(&c, x);
196 ap_coeff_set_scalar_frac(&c, x.
num, x.
den);
200 inline coeff& coeff::operator= (
const mpq_class& x)
202 ap_coeff_set_scalar_mpq(&c,
const_cast<mpq_class&
>(x).get_mpq_t());
206 inline coeff& coeff::operator= (mpfr_t x)
208 ap_coeff_set_scalar_mpfr(&c, x);
220 ap_coeff_set_interval_top(&c);
226 ap_coeff_set_interval_int(&c, 1, -1);
235 inline ap_coeff_discr_t coeff::get_discr()
const
243 return reinterpret_cast<scalar&
>(*c.val.scalar);
246 inline const scalar& coeff::get_scalar()
const
249 return reinterpret_cast<const scalar&
>(*c.val.scalar);
254 if (c.discr!=AP_COEFF_INTERVAL)
throw(
bad_discriminant(
"coeff::get_interval"));
255 return reinterpret_cast<interval&
>(*c.val.interval);
260 if (c.discr!=AP_COEFF_INTERVAL)
throw(
bad_discriminant(
"coeff::get_interval"));
261 return reinterpret_cast<const interval&
>(*c.val.interval);
273 ap_coeff_set_scalar(&c,
const_cast<ap_scalar_t*
>(x.
get_ap_scalar_t()));
279 ap_coeff_set_scalar_int(&c, x);
285 ap_coeff_set_scalar_int(&c, x);
291 ap_coeff_set_scalar_double(&c, x);
297 ap_coeff_set_scalar_frac(&c, x.
num, x.
den);
301 inline coeff&coeff::set(
const mpq_class& x)
303 ap_coeff_set_scalar_mpq(&c,
const_cast<mpq_class&
>(x).get_mpq_t());
309 ap_coeff_set_scalar_mpfr(&c, x);
322 ap_coeff_set_interval_scalar(&c,
328 inline coeff&coeff::set(
int inf,
int sup)
330 ap_coeff_set_interval_int(&c, inf, sup);
334 inline coeff&coeff::set(
long inf,
long sup)
336 ap_coeff_set_interval_int(&c, inf, sup);
340 inline coeff&coeff::set(
double inf,
double sup)
342 ap_coeff_set_interval_double(&c, inf, sup);
348 ap_coeff_set_interval_frac(&c, inf.
num, inf.
den, sup.
num, sup.
den);
352 inline coeff&coeff::set(
const mpq_class& inf,
const mpq_class& sup)
354 ap_coeff_set_interval_mpq(&c,
355 const_cast<mpq_class&
>(inf).get_mpq_t(),
356 const_cast<mpq_class&
>(sup).get_mpq_t());
360 inline coeff&coeff::set(mpfr_t inf, mpfr_t sup)
362 ap_coeff_set_interval_mpfr(&c, inf, sup);
368 ap_coeff_set_interval_top(&c);
374 ap_coeff_set_interval_int(&c, 1, -1);
381 inline void swap(coeff& a, coeff &b)
383 ap_coeff_swap(&a.c, &b.c);
391 inline std::ostream&
operator<< (std::ostream& os,
const coeff& s)
394 case AP_COEFF_SCALAR:
return os << *(reinterpret_cast<scalar*>(s.c.val.scalar));
395 case AP_COEFF_INTERVAL:
return os << *(reinterpret_cast<interval*>(s.c.val.interval));
400 inline void coeff::print(FILE* stream)
const
402 ap_coeff_fprint(stream,
const_cast<ap_coeff_t*
>(&c));
409 inline bool coeff::is_zero()
const
411 return ap_coeff_zero(
const_cast<ap_coeff_t*
>(&c));
414 inline int cmp(
const coeff& a,
const coeff& b)
416 return ap_coeff_cmp(
const_cast<ap_coeff_t*
>(&a.c),
const_cast<ap_coeff_t*
>(&b.c));
446 return ap_coeff_equal(
const_cast<ap_coeff_t*
>(&a.c),
const_cast<ap_coeff_t*
>(&b.c));
451 return !ap_coeff_equal(
const_cast<ap_coeff_t*
>(&a.c),
const_cast<ap_coeff_t*
>(&b.c));
460 inline void coeff::reduce()
467 ap_coeff_neg(&c, &c);
475 inline long coeff::hash()
const
477 return ap_coeff_hash(
const_cast<ap_coeff_t*
>(&c));
483 inline const ap_coeff_t* coeff::get_ap_coeff_t()
const
488 inline ap_coeff_t* coeff::get_ap_coeff_t()