Beispiel #1
0
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
}
Beispiel #2
0
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
}
Beispiel #3
0
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
}
Beispiel #4
0
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
}
Beispiel #5
0
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
}
Beispiel #6
0
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
}
Beispiel #7
0
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
}
Beispiel #8
0
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;
}
Beispiel #9
0
CGAL::Gmpfr fabs(const CGAL::Gmpfr &x)
{
    return x.abs();
}
Beispiel #10
0
CGAL::Gmpfr sqrt(const CGAL::Gmpfr &x)
{
    return x.sqrt();
}
Beispiel #11
0
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;
}
Beispiel #12
0
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;
}
Beispiel #13
0
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());
}
Beispiel #14
0
void print(const CGAL::Gmpfr &x)
{
    mpfr_out_str(stderr, 10, 0, x.fr(), GMP_RNDD);
}