示例#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
}
示例#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
}
示例#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
}
示例#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
}
示例#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
}
示例#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
}
示例#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
}
示例#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;
}
示例#9
0
CGAL::Gmpfr fabs(const CGAL::Gmpfr &x)
{
    return x.abs();
}
示例#10
0
CGAL::Gmpfr sqrt(const CGAL::Gmpfr &x)
{
    return x.sqrt();
}
示例#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;
}
示例#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;
}
示例#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());
}
示例#14
0
void print(const CGAL::Gmpfr &x)
{
    mpfr_out_str(stderr, 10, 0, x.fr(), GMP_RNDD);
}