Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1
31#pragma once
32
33#ifdef OGDF_INCLUDE_CGAL
34
35# include <CGAL/CORE_Expr.h>
36# include <CGAL/Gmpfr.h>
37# include <CGAL/Gmpq.h>
38# include <CGAL/gmpxx.h>
39# include <mpfr.h>
40
41# ifndef OGDF_GEOMETRIC_MPFR_NUMBER_OF_DIGITS
42
43# define OGDF_GEOMETRIC_MPFR_NUMBER_OF_DIGITS 77 // equals 256 bits
44
45# endif
46
47# ifndef OGDF_GEOMETRIC_MPFR_EQUALITY_THRESHOLD
48# define OGDF_GEOMETRIC_MPFR_EQUALITY_THRESHOLD 1e-20
49# endif
50
51
52namespace ogdf {
53namespace internal {
54namespace gcm {
55namespace tools {
56
57template<typename T>
58inline double cast(const T& a) {
59 //return a.to_double();
60 return CGAL::to_double(a);
61}
62
63template<>
64inline double cast(const double& a) {
65 return a;
66}
67
68inline mpfr_rnd_t std_rnd_to_mpfr_rnd(const std::float_round_style& e) {
69 switch (e) {
70 case std::round_indeterminate:
71 OGDF_ASSERT(false);
72 return MPFR_RNDZ;
73 case std::round_toward_zero:
74 return MPFR_RNDZ;
75 case std::round_to_nearest:
76 return MPFR_RNDN;
77 case std::round_toward_infinity:
78 return MPFR_RNDU;
79 case std::round_toward_neg_infinity:
80 return MPFR_RNDD;
81 default:
82 OGDF_ASSERT(false);
83 return MPFR_RNDZ;
84 }
85}
86
87template<typename T>
88inline const T const_pi() {
89 return CGAL_PI;
90}
91
92template<>
93inline const CGAL::Gmpfr const_pi() {
94 CGAL::Gmpfr y;
95 mpfr_const_pi(y.fr(), std_rnd_to_mpfr_rnd(CGAL::Gmpfr::get_default_rndmode()));
96 return y;
97}
98
99template<typename T>
100inline const T approx_sqrt(const T& v) {
101 return (T)sqrt(CGAL::to_double(v));
102}
103
104inline const mpz_class approx_sqrt(const mpz_class& v) { return sqrt(v); }
105
106inline const mpq_class approx_sqrt(const mpq_class& v) {
107 return mpq_class(approx_sqrt(v.get_num()), approx_sqrt(v.get_den()));
108}
109
110inline const CGAL::Gmpfr approx_sqrt(const CGAL::Gmpfr& v) {
111 CGAL::Gmpfr y;
112 mpfr_sqrt(y.fr(), v.fr(), std_rnd_to_mpfr_rnd(CGAL::Gmpfr::get_default_rndmode()));
113 return y;
114}
115
116inline const CORE::Expr approx_sqrt(const CORE::Expr& v) { return CGAL::sqrt(v); }
117
118template<typename T>
119inline const T acos(const T& v) {
120 return (T)std::acos(CGAL::to_double(v));
121}
122
123template<>
124inline const CGAL::Gmpfr acos(const CGAL::Gmpfr& v) {
125 CGAL::Gmpfr y;
126 mpfr_acos(y.fr(), v.fr(), std_rnd_to_mpfr_rnd(CGAL::Gmpfr::get_default_rndmode()));
127 return y;
128}
129
130template<>
131inline const CORE::Expr acos(const CORE::Expr& v) {
132 return std::acos(CGAL::to_double(v));
133}
134
135// DIGITS
136
137
138template<typename t>
139inline bool isEqual(const t& a, const t& b) {
140 return a == b;
141}
142
143template<>
144inline bool isEqual(const double& a, const double& b) {
146}
147
148template<>
149inline bool isEqual(const CGAL::Gmpfr& a, const CGAL::Gmpfr& b) {
150 return abs(a - b) < OGDF_GEOMETRIC_MPFR_EQUALITY_THRESHOLD;
151}
152
153template<typename T>
154inline bool isLessEqual(const T& a, const T& b) {
155 return (a < b) || isEqual(a, b);
156}
157
158template<typename T>
159inline bool isLess(const T& a, const T& b) {
160 return (a < b) && !isEqual(a, b);
161}
162
163template<typename T>
164inline bool isGreaterEqual(const T& a, const T& b) {
165 return (a > b) || isEqual(a, b);
166}
167
168template<typename T>
169inline bool isGreater(const T& a, const T& b) {
170 return (a > b) && !isEqual(a, b);
171}
172
173template<typename T>
174inline bool isZero(const T& a) {
175 return isEqual(a, (T)0.0);
176}
177
178}
179} // namespace
180
181inline std::ostream& operator<<(std::ostream& os, const CGAL::Gmpq& p) {
182 os.precision(20);
183 os << CGAL::to_double(p);
184 return os;
185}
186
187inline std::ostream& operator<<(std::ostream& os, const CORE::Expr& p) {
188 os.precision(20);
189 os << CGAL::to_double(p);
190 return os;
191}
192
193}
194}
195
196#endif
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:978