decimal r_rand(const decimal& min,const decimal& max) { #ifdef USE_CGAL CGAL::Gmpfr m; mpfr_urandom(m.fr(),state,MPFR_RNDN); return r_round_preference((min>max)?decimal(m)*(min-max)+max:decimal(m)*(max-min)+min,true); #else return (min>max)?r_rand()*(min-max)+max:r_rand()*(max-min)+min; #endif }
decimal r_pi(bool round) { #ifdef USE_CGAL CGAL::Gmpfr m; mpfr_const_pi(m.fr(),MPFR_RNDN); return r_round_preference(decimal(m),round); #else return r_round_preference(M_PI,round); #endif }
decimal r_floor(const decimal& a) { #ifdef USE_CGAL CGAL::Gmpfr m; CGAL::Gmpfr n=to_gmpfr(a); mpfr_floor(m.fr(),n.fr()); return decimal(m); #else return floor(a); #endif }
decimal r_log10(const decimal& a,bool round) { #ifdef USE_CGAL CGAL::Gmpfr m; CGAL::Gmpfr n=to_gmpfr(a); mpfr_log10(m.fr(),n.fr(),MPFR_RNDN); return r_round_preference(decimal(m),round); #else return r_round_preference(log10(a),round); #endif }
decimal r_pow(const decimal& a,const decimal& e,bool round) { #ifdef USE_CGAL CGAL::Gmpfr m; CGAL::Gmpfr n=to_gmpfr(a); CGAL::Gmpfr o=to_gmpfr(e); mpfr_pow(m.fr(),n.fr(),o.fr(),MPFR_RNDN); return r_round_preference(decimal(m),round); #else return pow(a,e); #endif }
decimal r_mod(const decimal& a,const decimal& b) { #ifdef USE_CGAL CGAL::Gmpfr m; CGAL::Gmpfr n=to_gmpfr(a); CGAL::Gmpfr o=to_gmpfr(b); mpfr_fmod(m.fr(),n.fr(),o.fr(),MPFR_RNDN); return decimal(m); #else return fmod(a,b); #endif }
decimal r_atan2(const decimal& a,const decimal& b,bool round) { #ifdef USE_CGAL CGAL::Gmpfr m; CGAL::Gmpfr n=to_gmpfr(a); CGAL::Gmpfr o=to_gmpfr(b); mpfr_atan2(m.fr(),n.fr(),o.fr(),MPFR_RNDN); return r_round_preference(decimal(m),round); #else return r_round_preference(atan2(a,b),round); #endif }
decimal r_round(const decimal& a,int places) { #ifdef USE_CGAL CGAL::Gmpfr m; CGAL::Gmpfr n(10.0); CGAL::Gmpfr o(places); mpfr_pow(m.fr(),n.fr(),o.fr(),MPFR_RNDN); decimal f(m); #else decimal f=pow(10.0,places); #endif return r_round(a*f)/f; }
CGAL::Gmpfr fabs(const CGAL::Gmpfr &x) { return x.abs(); }
CGAL::Gmpfr sqrt(const CGAL::Gmpfr &x) { return x.sqrt(); }
CGAL::Gmpfr atan2(const CGAL::Gmpfr &y, const CGAL::Gmpfr &x) { CGAL::Gmpfr result(0, std::max(gmp_result_precision(y), gmp_result_precision(x))); mpfr_atan2(result.fr(), y.fr(), x.fr(), gmp_rounding_mode(CGAL::Gmpfr::get_default_rndmode())); return result; }
CGAL::Gmpfr atan(const CGAL::Gmpfr &x) { CGAL::Gmpfr result(0, gmp_result_precision(x)); mpfr_atan(result.fr(), x.fr(), gmp_rounding_mode(CGAL::Gmpfr::get_default_rndmode())); return result; }
CGAL::Gmpfr::Precision_type gmp_result_precision(const CGAL::Gmpfr &x) { return (x.get_precision() > CGAL::Gmpfr::get_default_precision() ? x.get_precision() : CGAL::Gmpfr::get_default_precision()); }
void print(const CGAL::Gmpfr &x) { mpfr_out_str(stderr, 10, 0, x.fr(), GMP_RNDD); }