00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __MMX_BALL_HPP
00014 #define __MMX_BALL_HPP
00015 #include <numerix/ball_rounded.hpp>
00016 #include <numerix/ball_rough.hpp>
00017 #include <numerix/ball_infinities.hpp>
00018 namespace mmx {
00019 #define Ball_variant(C) typename ball_variant_helper<C>::BV
00020 #define TMPL_DEF template<typename C, \
00021 typename R=Default_radius_type(C), \
00022 typename V=Ball_variant(C) >
00023 #define TMPL template<typename C,typename R,typename V>
00024 #define Ball ball<C,R,V>
00025 #define Abs_ball ball<Abs_type(C),R,Abs_type(V) >
00026
00027
00028
00029
00030
00031 TMPL_DEF
00032 class ball {
00033 MMX_ALLOCATORS
00034 private:
00035 C c;
00036 R r;
00037
00038 public:
00039 typedef implementation<ball_rounding,V> Rnd;
00040 typedef Round_up(R) Up;
00041
00042 inline ball () {}
00043 template<typename T> ball (const T& c2):
00044 c (as<C> (c2)), r (0) {
00045 Rnd::add_additive_error (*this); }
00046 template<typename CT, typename RT, typename VT>
00047 inline ball (const ball<CT,RT,VT>& z):
00048 c (as<C> (center (z))), r (as<R> (radius (z))) {
00049 XVERIFY (r >= 0, "negative radius", r);
00050
00051 Rnd::add_additive_error (*this); }
00052 inline ball (const C& x):
00053 c (x), r (0) {}
00054 inline ball (const C& c2, const R& r2):
00055 c (c2), r (r2) {
00056 XVERIFY (r >= 0, "negative radius", r); }
00057 inline ball (const C& c2, const R& r2, bool adjust):
00058 c (c2), r (r2) {
00059 XVERIFY (r >= 0, "negative radius", r);
00060 if (adjust) Rnd::add_additive_error (*this); }
00061 inline ball (const Real_type(Ball)& x, const Real_type(Ball)& y):
00062 c (gaussian (center (x), center (y))),
00063 r (Up::hypot (radius (x), radius (y))) {
00064 XVERIFY (r >= 0, "negative radius", r);
00065 Rnd::add_additive_error (*this); }
00066 friend C center LESSGTR (const Ball& z);
00067 friend R radius LESSGTR (const Ball& z);
00068 friend C& center LESSGTR (Ball& z);
00069 friend R& radius LESSGTR (Ball& z);
00070 inline Ball& operator <<= (const xint& shift);
00071 inline Ball& operator >>= (const xint& shift);
00072 };
00073
00074 template<> struct symbolic_type_information<ball<floating<> > > {
00075 static const nat id= SYMBOLIC_BALL; };
00076
00077 UNARY_RETURN_TYPE(TMPL,center_op,Ball,C);
00078 UNARY_RETURN_TYPE(TMPL,radius_op,Ball,R);
00079 UNARY_RETURN_TYPE(TMPL,abs_op,Ball,Abs_ball);
00080 TMPL struct rounding_helper<Ball >: public rounding_helper<R> {};
00081 TMPL struct projective_helper<Ball >: public projective_helper<C> {};
00082
00083
00084
00085
00086
00087 template<typename C, typename R, typename V, typename C2, typename R2>
00088 struct make_ball_helper<Ball,C2,R2> {
00089 static inline Ball val (const C2& c, const R2& r) {
00090 return Ball (c, r); }
00091 };
00092
00093 template<typename C, typename R, typename V, typename C2>
00094 struct make_interval_helper<Ball,C2> {
00095 static inline Ball val (const C2& l, const C2& r) {
00096 typedef Round_up(C2) Up;
00097 VERIFY (l <= r, "bad interval");
00098 C2 cc= decexp2 (l+r, 1);
00099 R rr= next_above (as<R> (max (Up::sub (r, cc), Up::sub (cc, l))));
00100 return Ball (cc, rr);
00101 }
00102 };
00103
00104 TMPL inline C center (const Ball& z) { return z.c; }
00105 TMPL inline R radius (const Ball& z) { return z.r; }
00106 TMPL inline C& center (Ball& z) { return z.c; }
00107 TMPL inline R& radius (Ball& z) { return z.r; }
00108
00109 TMPL inline C lower (const Ball& z) {
00110 typedef implementation<ball_rounding,V> Rnd;
00111 return Rnd::lower (z); }
00112 TMPL inline C upper (const Ball& z) {
00113 typedef implementation<ball_rounding,V> Rnd;
00114 return Rnd::upper (z); }
00115 TMPL inline R abs_down (const Ball& z) {
00116 typedef implementation<ball_rounding,V> Rnd;
00117 return Rnd::abs_down (z); }
00118 TMPL inline R abs_up (const Ball& z) {
00119 typedef implementation<ball_rounding,V> Rnd;
00120 return Rnd::abs_up (z); }
00121 TMPL inline R bnd_down (const Ball& z) {
00122 typedef implementation<ball_rounding,V> Rnd;
00123 return Rnd::bnd_down (z); }
00124 TMPL inline R bnd_up (const Ball& z) {
00125 typedef implementation<ball_rounding,V> Rnd;
00126 return Rnd::bnd_up (z); }
00127
00128
00129
00130
00131
00132 TMPL inline void add_rounding_error (Ball& z) {
00133 typedef implementation<ball_rounding,V> Rnd;
00134 Rnd::add_rounding_error (z); }
00135 TMPL inline void add_additive_error (Ball& z) {
00136 typedef implementation<ball_rounding,V> Rnd;
00137 Rnd::add_additive_error (z); }
00138 TMPL inline void add_multiplicative_error (Ball& z) {
00139 typedef implementation<ball_rounding,V> Rnd;
00140 Rnd::add_multiplicative_error (z); }
00141 TMPL inline void add_elementary_error (Ball& z) {
00142 typedef implementation<ball_rounding,V> Rnd;
00143 Rnd::add_elementary_error (z); }
00144
00145 TMPL inline Ball copy (const Ball& z) {
00146 return Ball (copy (center (z)), copy (radius (z))); }
00147 TMPL inline Ball duplicate (const Ball& z) {
00148 return Ball (duplicate (center (z)), duplicate (radius (z))); }
00149 TMPL inline bool is_exact_zero (const Ball& z) {
00150 return is_exact_zero (center (z)) && is_exact_zero (radius (z)); }
00151
00152 template<typename Op, typename C, typename R, typename V> nat
00153 unary_hash (const Ball& x) {
00154 nat h= Op::op (center (x));
00155 return (h<<3) ^ (h<<11) ^ (h>>29) ^ Op::op (radius (x));
00156 }
00157
00158 template<typename Op, typename C, typename R, typename V> bool
00159 binary_test (const Ball& x1, const Ball& x2) {
00160 return Op::op (center (x1), center (x2)) &&
00161 Op::op (radius (x1), radius (x2));
00162 }
00163
00164 EXACT_IDENTITY_OP_SUGAR(TMPL,Ball)
00165 HARD_IDENTITY_OP_SUGAR(TMPL,Ball)
00166
00167 TMPL syntactic
00168 flatten (const Ball& z) {
00169 return syn ("ball", flatten (center (z)), flatten (radius (z)));
00170 }
00171
00172 TMPL syntactic
00173 flatten (const Ball& z, xnat dd) {
00174 return syn ("ball", flatten (center (z), dd), flatten (radius (z), dd));
00175 }
00176
00177 TMPL syntactic
00178 flatten_range (const Ball& z) {
00179 mmx_local_bit_precision tmp (precision (center (z)));
00180 if (is_nan (z)) return Nan (syntactic);
00181 if (is_fuzz (z)) return Fuzz (syntactic);
00182 if (is_exact_zero (z)) return 0;
00183 return flatten_range (lower (z), upper (z));
00184 }
00185
00186 TMPL syntactic
00187 flatten_range (const Ball& z, xnat dd) {
00188 mmx_local_bit_precision tmp (precision (center (z)));
00189 if (is_nan (z)) return Nan (syntactic);
00190 if (is_fuzz (z)) return Fuzz (syntactic);
00191 if (is_exact_zero (z)) return 0;
00192 return flatten_range (lower (z), upper (z), dd);
00193 }
00194
00195 template<typename R, typename V> inline syntactic
00196 flatten (const ball<double,R,V>& z) {
00197 return flatten_range (z); }
00198 template<typename R, typename V> inline syntactic
00199 flatten (const ball<double,R,V>& z, xnat dd) {
00200 return flatten_range (z, dd); }
00201 template<typename FV, typename R, typename V> inline syntactic
00202 flatten (const ball<floating<FV>,R,V>& z) {
00203 return flatten_range (z); }
00204 template<typename FV, typename R, typename V> inline syntactic
00205 flatten (const ball<floating<FV>,R,V>& z, xnat dd) {
00206 return flatten_range (z, dd); }
00207
00208 TMPL
00209 struct binary_helper<Ball >: public void_binary_helper<Ball > {
00210 static inline string short_type_name () {
00211 return "Ba" * Short_type_name (C) * Short_type_name (R); }
00212 static inline generic full_type_name () {
00213 return gen ("Ball", Full_type_name (C), Full_type_name (R)); }
00214 static inline generic disassemble (const Ball& z) {
00215 return gen_vec (as<generic> (center (z)), as<generic> (radius (z))); }
00216 static inline Ball assemble (const generic& v) {
00217 return Ball (as<C> (vector_access (v, 0)),
00218 as<R> (vector_access (v, 1))); }
00219 static inline void write (const port& out, const Ball& z) {
00220 binary_write<C> (out, center (z));
00221 binary_write<R> (out, radius (z)); }
00222 static inline Ball read (const port& in) {
00223 C c= binary_read<C> (in);
00224 R r= binary_read<R> (in);
00225 return Ball (c, r, false); }
00226 };
00227
00228 template<typename TC, typename TR, typename TV,
00229 typename FC, typename FR, typename FV> inline void
00230 set_as (ball<TC,TR,TV>& r, const ball<FC,FR,FV>& z) {
00231 typedef implementation<ball_rounding,TV> Rnd;
00232 set_as (center (r), center (z));
00233 set_as (radius (r), radius (z));
00234 Rnd::add_additive_error (r);
00235 }
00236
00237 template<typename TC, typename TR, typename TV, typename F> inline void
00238 set_as (ball<TC,TR,TV>& r, const F& z) {
00239 typedef implementation<ball_rounding,TV> Rnd;
00240 set_as (center (r), z);
00241 set_as (radius (r), 0);
00242 Rnd::add_additive_error (r);
00243 }
00244
00245
00246
00247
00248
00249 TMPL inline bool
00250 is_zero (const Ball& z) {
00251 return !is_nan (center (z)) && !is_nan (radius (z)) &&
00252 abs_down (z) == 0;
00253 }
00254
00255 TMPL inline bool
00256 is_non_zero (const Ball& z) {
00257 return is_nan (center (z)) || is_nan (radius (z)) ||
00258 abs_down (z) != 0;
00259 }
00260
00261 TMPL inline bool
00262 is_negative_or_zero (const Ball& z) {
00263 return !is_nan (center (z)) && bnd_down (z) <= 0;
00264 }
00265
00266 TMPL inline bool
00267 is_negative (const Ball& z) {
00268 return !is_nan (center (z)) && bnd_up (z) < 0;
00269 }
00270
00271 TMPL inline bool
00272 is_positive_or_zero (const Ball& z) {
00273 return !is_nan (center (z)) && bnd_up (z) >= 0;
00274 }
00275
00276 TMPL inline bool
00277 is_positive (const Ball& z) {
00278 return !is_nan (center (z)) && bnd_down (z) > 0;
00279 }
00280
00281 TMPL bool
00282 operator == (const Ball& z1, const Ball& z2) {
00283 if (is_nan (z1) || is_nan (z2)) return is_nan (z1) && is_nan (z2);
00284 Ball d= z1 - z2;
00285 return abs_down (d) == 0;
00286 }
00287
00288 TMPL bool
00289 operator != (const Ball& z1, const Ball& z2) {
00290 if (is_nan (z1) || is_nan (z2)) return !(is_nan (z1) && is_nan (z2));
00291 Ball d= z1 - z2;
00292 return abs_down (d) != 0;
00293 }
00294
00295 TMPL inline bool
00296 operator <= (const Ball& z1, const Ball& z2) {
00297 return is_negative_or_zero (z1 - z2);
00298 }
00299
00300 TMPL inline bool
00301 operator < (const Ball& z1, const Ball& z2) {
00302 return is_negative (z1 - z2);
00303 }
00304
00305 TMPL inline bool
00306 operator >= (const Ball& z1, const Ball& z2) {
00307 return is_positive_or_zero (z1 - z2);
00308 }
00309
00310 TMPL inline bool
00311 operator > (const Ball& z1, const Ball& z2) {
00312 return is_positive (z1 - z2);
00313 }
00314
00315 TMPL inline bool
00316 included (const Ball& b1, const Ball& b2) {
00317
00318 return radius (b1 - Ball (center (b2))) <= radius (b2);
00319 }
00320
00321 TMPL nat
00322 hash (const Ball& z) {
00323 (void) z;
00324
00325 return 123123123;
00326 }
00327
00328 EQUAL_INT_SUGAR(TMPL,Ball);
00329 COMPARE_INT_SUGAR(TMPL,Ball);
00330 EQUAL_SCALAR_SUGAR(TMPL,Ball,C);
00331 COMPARE_SCALAR_SUGAR(TMPL,Ball,C);
00332 EQUAL_SCALAR_SUGAR_BIS(TMPL,Ball,C);
00333 COMPARE_SCALAR_SUGAR_BIS(TMPL,Ball,C);
00334
00335
00336
00337
00338
00339 TMPL inline void set_default (Ball& x) { x= Ball (Default (C), 0); }
00340 TMPL inline void set_nan (Ball& x) { x= Ball (Nan (C), 0); }
00341 TMPL inline void set_maximal (Ball& x) { x= Ball (Maximal (C), 0); }
00342 TMPL inline void set_minimal (Ball& x) { x= Ball (Minimal (C), 0); }
00343 TMPL inline void set_infinity (Ball& x) { x= Ball (Infinity (C), 0); }
00344 TMPL inline void set_fuzz (Ball& x) { x= Ball (0, Infinity (R)); }
00345 TMPL inline void set_smallest (Ball& x) { x= Ball (Smallest (C), 0); }
00346 TMPL inline void set_largest (Ball& x) { x= Ball (Largest (C), 0); }
00347 TMPL inline void set_accuracy (Ball& x) { x= Ball (Accuracy (C), 0); }
00348 TMPL inline void set_log2 (Ball& x) { x= Ball (Log2 (C), 0, true); }
00349 TMPL inline void set_pi (Ball& x) { x= Ball (Pi (C), 0, true); }
00350 TMPL inline void set_euler (Ball& x) { x= Ball (Euler (C), 0, true); }
00351 TMPL inline void set_imaginary (Ball& x) {
00352 x= Ball (Real_type (Ball) (0), Real_type (Ball) (1)); }
00353 TMPL inline Ball times_infinity (const Ball& x) {
00354 return x * infinity_cst<Ball > (); }
00355
00356
00357
00358
00359
00360 TMPL inline Ball
00361 operator - (const Ball& z) {
00362 typedef implementation<ball_additive,V> Impl;
00363 Ball d; Impl::neg (d, z); return d;
00364 }
00365
00366 TMPL inline Ball
00367 operator + (const Ball& z1, const Ball& z2) {
00368 typedef implementation<ball_additive,V> Impl;
00369 Ball d; Impl::add (d, z1, z2); return d;
00370 }
00371
00372 TMPL inline Ball
00373 operator + (const Ball& z1, const C& z2) {
00374 typedef implementation<ball_additive,V> Impl;
00375 Ball d; Impl::add (d, z1, z2); return d;
00376 }
00377
00378 TMPL inline Ball
00379 operator + (const C& z1, const Ball& z2) {
00380 typedef implementation<ball_additive,V> Impl;
00381 Ball d; Impl::add (d, z1, z2); return d;
00382 }
00383
00384 TMPL inline Ball
00385 operator - (const Ball& z1, const Ball& z2) {
00386 typedef implementation<ball_additive,V> Impl;
00387 Ball d; Impl::sub (d, z1, z2); return d;
00388 }
00389
00390 TMPL inline Ball
00391 operator - (const Ball& z1, const C& z2) {
00392 typedef implementation<ball_additive,V> Impl;
00393 Ball d; Impl::sub (d, z1, z2); return d;
00394 }
00395
00396 TMPL inline Ball
00397 operator - (const C& z1, const Ball& z2) {
00398 typedef implementation<ball_additive,V> Impl;
00399 Ball d; Impl::sub (d, z1, z2); return d;
00400 }
00401
00402 TMPL inline Ball
00403 operator * (const Ball& z1, const Ball& z2) {
00404 typedef implementation<ball_multiplicative,V> Impl;
00405 Ball d; Impl::mul (d, z1, z2); return d;
00406 }
00407
00408 TMPL inline Ball
00409 operator * (const Ball& z1, const C& z2) {
00410 typedef implementation<ball_multiplicative,V> Impl;
00411 Ball d; Impl::mul (d, z1, z2); return d;
00412 }
00413
00414 TMPL inline Ball
00415 operator * (const C& z1, const Ball& z2) {
00416 typedef implementation<ball_multiplicative,V> Impl;
00417 Ball d; Impl::mul (d, z1, z2); return d;
00418 }
00419
00420 TMPL inline Ball
00421 square (const Ball& z) {
00422 typedef implementation<ball_multiplicative,V> Impl;
00423 Ball d; Impl::square (d, z); return d;
00424 }
00425
00426 TMPL inline Ball
00427 invert (const Ball& z) {
00428 typedef implementation<ball_multiplicative,V> Impl;
00429 Ball d; Impl::invert (d, z); return d;
00430 }
00431
00432 TMPL inline Ball
00433 operator / (const Ball& z1, const Ball& z2) {
00434 typedef implementation<ball_multiplicative,V> Impl;
00435 Ball d; Impl::div (d, z1, z2); return d;
00436 }
00437
00438 TMPL inline Ball
00439 operator / (const Ball& z1, const C& z2) {
00440 typedef implementation<ball_multiplicative,V> Impl;
00441 Ball d; Impl::div (d, z1, z2); return d;
00442 }
00443
00444 TMPL inline Ball
00445 operator / (const C& z1, const Ball& z2) {
00446 typedef implementation<ball_multiplicative,V> Impl;
00447 Ball d; Impl::div (d, z1, z2); return d;
00448 }
00449
00450 ARITH_INT_SUGAR(TMPL,Ball);
00451
00452
00453
00454
00455
00456 template<typename V> struct ball_complex;
00457
00458 template<typename C, typename Real, typename V>
00459 struct elementary_variant {
00460 typedef ball_complex<V> EV;
00461 };
00462
00463 template<typename C, typename V>
00464 struct elementary_variant<C,C,V> {
00465 typedef V EV;
00466 };
00467
00468 #define Elementary_variant(C,V) \
00469 typename elementary_variant<C,Real_type(C),V>::EV
00470
00471 TMPL inline Ball
00472 sqrt (const Ball& z) {
00473 typedef Elementary_variant(C,V) EV;
00474 typedef implementation<ball_root,EV> Impl;
00475 Ball d; Impl::sqrt (d, z); return d;
00476 }
00477
00478 TMPL inline Ball
00479 hypot (const Ball& x, const Ball& y) {
00480 typedef Elementary_variant(C,V) EV;
00481 typedef implementation<ball_root,EV> Impl;
00482 Ball d; Impl::hypot (d, x, y); return d;
00483 }
00484
00485 TMPL inline Ball
00486 exp (const Ball& z) {
00487 typedef Elementary_variant(C,V) EV;
00488 typedef implementation<ball_elementary,EV> Impl;
00489 Ball d; Impl::exp (d, z); return d;
00490 }
00491
00492 TMPL inline Ball
00493 log (const Ball& z) {
00494 typedef Elementary_variant(C,V) EV;
00495 typedef implementation<ball_elementary,EV> Impl;
00496 Ball d; Impl::log (d, z); return d;
00497 }
00498
00499 TMPL inline Ball
00500 pow (const Ball& z, const Ball& y) {
00501 typedef Elementary_variant(C,V) EV;
00502 typedef implementation<ball_elementary,EV> Impl;
00503 Ball d; Impl::pow (d, z, y); return d;
00504 }
00505
00506 TMPL inline Ball
00507 pow (const Ball& z, const int& y) {
00508 typedef Elementary_variant(C,V) EV;
00509 typedef implementation<ball_elementary,EV> Impl;
00510 Ball d; Impl::pow (d, z, Ball (y)); return d;
00511 }
00512
00513 TMPL inline Ball
00514 pow (const int& z, const Ball& y) {
00515 typedef Elementary_variant(C,V) EV;
00516 typedef implementation<ball_elementary,EV> Impl;
00517 Ball d; Impl::pow (d, Ball (z), y); return d;
00518 }
00519
00520 TMPL inline Ball
00521 cos (const Ball& z) {
00522 typedef Elementary_variant(C,V) EV;
00523 typedef implementation<ball_elementary,EV> Impl;
00524 Ball d; Impl::cos (d, z); return d;
00525 }
00526
00527 TMPL inline Ball
00528 sin (const Ball& z) {
00529 typedef Elementary_variant(C,V) EV;
00530 typedef implementation<ball_elementary,EV> Impl;
00531 Ball d; Impl::sin (d, z); return d;
00532 }
00533
00534 TMPL inline Ball
00535 tan (const Ball& z) {
00536 typedef Elementary_variant(C,V) EV;
00537 typedef implementation<ball_elementary,EV> Impl;
00538 Ball d; Impl::tan (d, z); return d;
00539 }
00540
00541 TMPL inline Ball
00542 cosh (const Ball& z) {
00543 typedef Elementary_variant(C,V) EV;
00544 typedef implementation<ball_elementary,EV> Impl;
00545 Ball d; Impl::cosh (d, z); return d;
00546 }
00547
00548 TMPL inline Ball
00549 sinh (const Ball& z) {
00550 typedef Elementary_variant(C,V) EV;
00551 typedef implementation<ball_elementary,EV> Impl;
00552 Ball d; Impl::sinh (d, z); return d;
00553 }
00554
00555 TMPL inline Ball
00556 tanh (const Ball& z) {
00557 typedef Elementary_variant(C,V) EV;
00558 typedef implementation<ball_elementary,EV> Impl;
00559 Ball d; Impl::tanh (d, z); return d;
00560 }
00561
00562 TMPL inline Ball
00563 acos (const Ball& z) {
00564 typedef Elementary_variant(C,V) EV;
00565 typedef implementation<ball_elementary,EV> Impl;
00566 Ball d; Impl::acos (d, z); return d;
00567 }
00568
00569 TMPL inline Ball
00570 asin (const Ball& z) {
00571 typedef Elementary_variant(C,V) EV;
00572 typedef implementation<ball_elementary,EV> Impl;
00573 Ball d; Impl::asin (d, z); return d;
00574 }
00575
00576 TMPL inline Ball
00577 atan (const Ball& z) {
00578 typedef Elementary_variant(C,V) EV;
00579 typedef implementation<ball_elementary,EV> Impl;
00580 Ball d; Impl::atan (d, z); return d;
00581 }
00582
00583 TMPL inline Ball
00584 atan2 (const Ball& y, const Ball& x) {
00585 typedef Elementary_variant(C,V) EV;
00586 typedef implementation<ball_elementary,EV> Impl;
00587 Ball d; Impl::atan2 (d, y, x); return d;
00588 }
00589
00590 INV_TRIGO_SUGAR(TMPL,Ball)
00591 INV_HYPER_SUGAR(TMPL,Ball)
00592 ARG_HYPER_SUGAR(TMPL,Ball)
00593
00594
00595
00596
00597
00598 TMPL inline Abs_ball
00599 abs (const Ball& z) {
00600 typedef implementation<ball_abs,V> Impl;
00601 Abs_ball d; Impl::abs (d, z); return d;
00602 }
00603
00604 TMPL inline Ball
00605 min (const Ball& z1, const Ball& z2) {
00606 typedef implementation<ball_ordered,V> Impl;
00607 Ball d; Impl::min (d, z1, z2); return d;
00608 }
00609
00610 TMPL inline Ball
00611 max (const Ball& z1, const Ball& z2) {
00612 typedef implementation<ball_ordered,V> Impl;
00613 Ball d; Impl::max (d, z1, z2); return d;
00614 }
00615
00616 TMPL inline Ball
00617 floor (const Ball& z) {
00618 typedef implementation<ball_ordered,V> Impl;
00619 Ball d; Impl::floor (d, z); return d;
00620 }
00621
00622 TMPL inline Ball
00623 trunc (const Ball& z) {
00624 typedef implementation<ball_ordered,V> Impl;
00625 Ball d; Impl::trunc (d, z); return d;
00626 }
00627
00628 TMPL inline Ball
00629 ceil (const Ball& z) {
00630 typedef implementation<ball_ordered,V> Impl;
00631 Ball d; Impl::ceil (d, z); return d;
00632 }
00633
00634 TMPL inline Ball
00635 round (const Ball& z) {
00636 typedef implementation<ball_ordered,V> Impl;
00637 Ball d; Impl::round (d, z); return d;
00638 }
00639
00640
00641
00642
00643
00644 TMPL inline bool is_finite (const Ball& z) {
00645 return is_finite (center (z)) && is_finite (radius (z)); }
00646 TMPL inline bool is_infinite (const Ball& z) {
00647 return is_infinite (center (z)) && is_finite (radius (z)); }
00648 TMPL inline bool is_fuzz (const Ball& z) {
00649 return !is_nan (center (z)) && is_infinite (radius (z)); }
00650 TMPL inline bool is_nan (const Ball& z) {
00651 return is_nan (center (z)) || is_nan (radius (z)); }
00652 TMPL inline bool is_reliable (const Ball& z) {
00653 (void) z; return true; }
00654
00655 TMPL inline Ball change_precision (const Ball& z, xnat prec) {
00656 return Ball (change_precision (center (z), prec), radius (z)); }
00657 TMPL inline xnat precision (const Ball& x) {
00658 return precision (center (x)); }
00659 TMPL inline Abs_ball additive_error (const Ball& x) {
00660 return Abs_ball (additive_error (center (x))); }
00661 TMPL inline Abs_ball multiplicative_error (const Ball& x) {
00662 return Abs_ball (multiplicative_error (center (x))); }
00663 TMPL inline Abs_ball elementary_error (const Ball& x) {
00664 return Abs_ball (elementary_error (center (x))); }
00665
00666 TMPL inline xint exponent (const Ball& z) {
00667 return max (exponent (center (z)), exponent (radius (z))); }
00668 TMPL inline double magnitude (const Ball& z) {
00669 return max (magnitude (center (z)), magnitude (radius (z))); }
00670 TMPL inline Ball operator << (const Ball& z, const xint& shift) {
00671 typedef implementation<ball_shift,V> Impl;
00672 Ball d; Impl::shiftl (d, z, shift); return d; }
00673 TMPL inline Ball operator >> (const Ball& z, const xint& shift) {
00674 typedef implementation<ball_shift,V> Impl;
00675 Ball d; Impl::shiftr (d, z, shift); return d; }
00676 TMPL inline Ball& Ball::operator <<= (const xint& shift) {
00677 typedef implementation<ball_shift,V> Impl;
00678 Impl::shiftl (*this, shift); return *this; }
00679 TMPL inline Ball& Ball::operator >>= (const xint& shift) {
00680 typedef implementation<ball_shift,V> Impl;
00681 Impl::shiftr (*this, shift); return *this; }
00682
00683 TMPL inline Ball next_above (const Ball& z) {
00684 return Ball (next_above (upper (z)), promote (0, radius (z))); }
00685 TMPL inline Ball next_below (const Ball& z) {
00686 return Ball (next_below (lower (z)), promote (0, radius (z))); }
00687
00688 TMPL inline Ball sharpen (const Ball& z) {
00689 return Ball (center (z)); }
00690 TMPL inline Ball blur (const Ball& z, const R& r) {
00691 typedef Round_up(R) Up;
00692 return Ball (center (z), Up::add (radius (z), r)); }
00693 template<typename C, typename R, typename V, typename K> inline Ball
00694 blur (const Ball& z, const ball<K,R,V>& r) {
00695 typedef Round_up(R) Up;
00696 return Ball (center (z), Up::add (radius (z), abs_up (r))); }
00697
00698
00699
00700
00701
00702 #define mmx_ball(R,C) ball<C >
00703
00704 template<typename R, typename C> inline ball<C>
00705 make_mmx_ball (const C& c, const R& r) {
00706 return ball<C> (c, as<Default_radius_type(C) > (r), true);
00707 }
00708
00709 template<typename C> inline ball<C>
00710 make_mmx_ball (const C& c) {
00711 return ball<C> (c, as<Default_radius_type(C) > (promote (0, abs (c))));
00712 }
00713
00714 template<typename C> inline Abs_type(C)
00715 mmx_radius (const ball<C>& z) {
00716 return as<Abs_type(C) > (radius (z));
00717 }
00718
00719 #undef TMPL_DEF
00720 #undef TMPL
00721 #undef Ball
00722 #undef Abs_ball
00723 }
00724 #endif // __MMX_BALL_HPP