33 #ifdef OGDF_INCLUDE_CGAL
35 # include <CGAL/CORE_Expr.h>
36 # include <CGAL/Gmpfr.h>
37 # include <CGAL/Gmpq.h>
38 # include <CGAL/gmpxx.h>
41 # ifndef OGDF_GEOMETRIC_MPFR_NUMBER_OF_DIGITS
43 # define OGDF_GEOMETRIC_MPFR_NUMBER_OF_DIGITS 77 // equals 256 bits
47 # ifndef OGDF_GEOMETRIC_MPFR_EQUALITY_THRESHOLD
48 # define OGDF_GEOMETRIC_MPFR_EQUALITY_THRESHOLD 1e-20
58 inline double cast(
const T& a) {
60 return CGAL::to_double(a);
64 inline double cast(
const double& a) {
68 inline mpfr_rnd_t std_rnd_to_mpfr_rnd(
const std::float_round_style& e) {
70 case std::round_indeterminate:
73 case std::round_toward_zero:
75 case std::round_to_nearest:
77 case std::round_toward_infinity:
79 case std::round_toward_neg_infinity:
88 inline const T const_pi() {
93 inline const CGAL::Gmpfr const_pi() {
95 mpfr_const_pi(y.fr(), std_rnd_to_mpfr_rnd(CGAL::Gmpfr::get_default_rndmode()));
100 inline const T approx_sqrt(
const T& v) {
101 return (T)sqrt(CGAL::to_double(v));
104 inline const mpz_class approx_sqrt(
const mpz_class& v) {
return sqrt(v); }
106 inline const mpq_class approx_sqrt(
const mpq_class& v) {
107 return mpq_class(approx_sqrt(v.get_num()), approx_sqrt(v.get_den()));
110 inline const CGAL::Gmpfr approx_sqrt(
const CGAL::Gmpfr& v) {
112 mpfr_sqrt(y.fr(), v.fr(), std_rnd_to_mpfr_rnd(CGAL::Gmpfr::get_default_rndmode()));
116 inline const CORE::Expr approx_sqrt(
const CORE::Expr& v) {
return CGAL::sqrt(v); }
119 inline const T acos(
const T& v) {
120 return (T)std::acos(CGAL::to_double(v));
124 inline const CGAL::Gmpfr acos(
const CGAL::Gmpfr& v) {
126 mpfr_acos(y.fr(), v.fr(), std_rnd_to_mpfr_rnd(CGAL::Gmpfr::get_default_rndmode()));
131 inline const CORE::Expr acos(
const CORE::Expr& v) {
132 return std::acos(CGAL::to_double(v));
139 inline bool isEqual(
const t& a,
const t& b) {
144 inline bool isEqual(
const double& a,
const double& b) {
145 return fabs(a - b) < OGDF_GEOMETRIC_MPFR_EQUALITY_THRESHOLD;
149 inline bool isEqual(
const CGAL::Gmpfr& a,
const CGAL::Gmpfr& b) {
150 return abs(a - b) < OGDF_GEOMETRIC_MPFR_EQUALITY_THRESHOLD;
154 inline bool isLessEqual(
const T& a,
const T& b) {
155 return (a < b) || isEqual(a, b);
159 inline bool isLess(
const T& a,
const T& b) {
160 return (a < b) && !isEqual(a, b);
164 inline bool isGreaterEqual(
const T& a,
const T& b) {
165 return (a > b) || isEqual(a, b);
169 inline bool isGreater(
const T& a,
const T& b) {
170 return (a > b) && !isEqual(a, b);
174 inline bool isZero(
const T& a) {
175 return isEqual(a, (T)0.0);
181 inline std::ostream&
operator<<(std::ostream& os,
const CGAL::Gmpq& p) {
183 os << CGAL::to_double(p);
187 inline std::ostream&
operator<<(std::ostream& os,
const CORE::Expr& p) {
189 os << CGAL::to_double(p);