Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
number_utils.h
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // Copyright (c) 1999 The CGAL Consortium
4 
5 // This software and related documentation is part of the Computational
6 // Geometry Algorithms Library (CGAL).
7 // This software and documentation is provided "as-is" and without warranty
8 // of any kind. In no event shall the CGAL Consortium be liable for any
9 // damage of any kind.
10 //
11 // Every use of CGAL requires a license.
12 //
13 // Academic research and teaching license
14 // - For academic research and teaching purposes, permission to use and copy
15 // the software and its documentation is hereby granted free of charge,
16 // provided that it is not a component of a commercial product, and this
17 // notice appears in all copies of the software and related documentation.
18 //
19 // Commercial licenses
20 // - A commercial license is available through Algorithmic Solutions, who also
21 // markets LEDA (http://www.algorithmic-solutions.de).
22 // - Commercial users may apply for an evaluation license by writing to
23 // Algorithmic Solutions (contact@algorithmic-solutions.com).
24 //
25 // The CGAL Consortium consists of Utrecht University (The Netherlands),
26 // ETH Zurich (Switzerland), Free University of Berlin (Germany),
27 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
28 // (Germany), Max-Planck-Institute Saarbrucken (Germany), RISC Linz (Austria),
29 // and Tel-Aviv University (Israel).
30 //
31 // ----------------------------------------------------------------------
32 //
33 // release : CGAL-2.2
34 // release_date : 2000, September 30
35 //
36 // source : number_utils.fw
37 // file : include/CGAL/number_utils.h
38 // package : Number_types (3.4)
39 // revision : 3.4
40 // revision_date : 13 Jul 2000
41 // author(s) : Stefan Schirra
42 //
43 //
44 // coordinator : MPI, Saarbruecken (<Stefan.Schirra>)
45 // email : contact@cgal.org
46 // www : http://www.cgal.org
47 //
48 // ======================================================================
49 
50 
51 #ifndef CGAL_NUMBER_UTILS_H
52 #define CGAL_NUMBER_UTILS_H
53 
54 #include <CGAL/config.h>
55 #include <CGAL/enum.h>
56 #include <CGAL/kernel_basic.h>
57 #include <algorithm>
58 
59 namespace CGAL {
60 
61 template <class NT>
62 inline
63 bool
64 is_zero(const NT& x)
65 {
66 #ifndef CGAL_NO_NTS_NAMESPACE
67  bool is_zero_is_obsolete__qualify_call_by_CGAL_NTS;
68 #endif // CGAL_NO_NTS_NAMESPACE
69  return x == NT(0);
70 }
71 
72 template <class NT>
73 inline
74 bool
75 is_one(const NT& x)
76 {
77 #ifndef CGAL_NO_NTS_NAMESPACE
78  bool is_one_is_obsolete__qualify_call_by_CGAL_NTS;
79 #endif // CGAL_NO_NTS_NAMESPACE
80  return x == NT(1);
81 }
82 
83 template <class NT>
84 inline
85 bool
86 is_negative(const NT& x)
87 {
88 #ifndef CGAL_NO_NTS_NAMESPACE
89  bool is_negative_is_obsolete__qualify_call_by_CGAL_NTS;
90 #endif // CGAL_NO_NTS_NAMESPACE
91  return x < NT(0);
92 }
93 
94 template <class NT>
95 inline
96 bool
97 is_positive(const NT& x)
98 {
99 #ifndef CGAL_NO_NTS_NAMESPACE
100  bool is_positive_is_obsolete__qualify_call_by_CGAL_NTS;
101 #endif // CGAL_NO_NTS_NAMESPACE
102  return NT(0) < x;
103 }
104 
105 template <class NT>
107 Sign
108 sign(const NT& x)
109 {
110 #ifndef CGAL_NO_NTS_NAMESPACE
111  bool sign_is_obsolete__qualify_call_by_CGAL_NTS;
112 #endif // CGAL_NO_NTS_NAMESPACE
113  return (x < NT(0)) ? NEGATIVE : (NT(0) < x) ? POSITIVE : ZERO;
114 }
115 
116 template <class NT>
118 Sign
119 lexicographical_sign(const NT& x, const NT& y)
120 {
121 #ifndef CGAL_NO_NTS_NAMESPACE
122  bool lexicographical_sign_is_obsolete__qualify_call_by_CGAL_NTS;
123 #endif // CGAL_NO_NTS_NAMESPACE
124  return (x == NT(0)) ? CGAL::sign(y) : CGAL::sign(x);
125 }
126 
127 template <class NT>
129 NT
130 abs(const NT& x)
131 {
132 #ifndef CGAL_NO_NTS_NAMESPACE
133  bool abs_is_obsolete__qualify_call_by_CGAL_NTS;
134 #endif // CGAL_NO_NTS_NAMESPACE
135  return (x < NT(0)) ? -x: x;
136 }
137 
138 // for min and max see <CGAL/basic.h>
139 
140 template <class NT>
143 compare(const NT& n1, const NT& n2)
144 {
145 #ifndef CGAL_NO_NTS_NAMESPACE
146  bool compare_is_obsolete__qualify_call_by_CGAL_NTS;
147 #endif // CGAL_NO_NTS_NAMESPACE
148  if (n1 < n2)
149  {
150  return SMALLER ;
151  }
152  return (n2 < n1) ? LARGER : EQUAL;
153 }
154 
155 template <class NT>
156 inline
157 NT
158 square( const NT& n)
159 {
160 #ifndef CGAL_NO_NTS_NAMESPACE
161  bool square_is_obsolete__qualify_call_by_CGAL_NTS;
162 #endif // CGAL_NO_NTS_NAMESPACE
163  return n*n;
164 }
165 
166 
167 #ifndef CGAL_NO_NTS_NAMESPACE
168 namespace NTS {
169 
170 template <class NT>
171 inline
172 bool
173 is_zero(const NT& x)
174 { return x == NT(0); }
175 
176 template <class NT>
177 inline
178 bool
179 is_one(const NT& x)
180 { return x == NT(1); }
181 
182 template <class NT>
183 inline
184 bool
185 is_negative(const NT& x)
186 { return x < NT(0); }
187 
188 template <class NT>
189 inline
190 bool
191 is_positive(const NT& x)
192 { return NT(0) < x; }
193 
194 template <class NT>
196 Sign
197 sign(const NT& x)
198 { return (x < NT(0)) ? NEGATIVE : (NT(0) < x) ? POSITIVE : ZERO; }
199 
200 template <class NT>
202 Sign
203 lexicographical_sign(const NT& x, const NT& y)
204 { return (x == NT(0)) ? CGAL_NTS sign(y) : CGAL_NTS sign(x); }
205 
206 template <class NT>
208 NT
209 abs(const NT& x)
210 { return (x < NT(0)) ? -x: x; }
211 
212 template <class NT>
214 const NT&
215 min(const NT& x, const NT& y)
216 { return (y < x) ? y : x; }
217 
218 template <class NT>
220 const NT&
221 max(const NT& x, const NT& y)
222 { return (x < y) ? y : x; }
223 
224 template <class NT>
227 compare(const NT& n1, const NT& n2)
228 {
229  if (n1 < n2)
230  {
231  return SMALLER ;
232  }
233  return (n2 < n1) ? LARGER : EQUAL;
234 }
235 
236 template <class NT>
237 inline
238 NT
239 square( const NT& n)
240 { return n*n; }
241 
242 #if 0
243 template <class NT>
244 inline
245 double
246 to_double( const NT& n)
247 { return CGAL::to_double(n); }
248 
249 template <class NT>
250 inline
251 NT
252 sqrt( const NT& n)
253 { return CGAL::sqrt(n); }
254 
255 template <class NT>
256 inline
257 bool
258 is_valid( const NT& n)
259 { return CGAL::is_valid(n); }
260 
261 template <class NT>
262 inline
263 bool
264 is_finite( const NT& n)
265 { return CGAL::is_finite(n); }
266 
267 template <class NT>
268 inline
269 bool
270 is_integral( const NT& n)
271 { return CGAL::is_integral(n); }
272 
273 #endif
274 
275 } // namespace NTS
276 
277 #endif // CGAL_NO_NTS_NAMESPACE
278 
279 } // namespace CGAL
280 
281 #endif // CGAL_NUMBER_UTILS_H
CGAL_KERNEL_INLINE Comparison_result compare(const NT &n1, const NT &n2)
Definition: number_utils.h:227
bool is_negative(const NT &x)
Definition: number_utils.h:185
CGAL_BEGIN_NAMESPACE double to_double(double d)
Definition: double.h:68
bool is_one(const NT &x)
Definition: number_utils.h:75
CGAL_KERNEL_INLINE NT abs(const NT &x)
Definition: number_utils.h:130
Definition: enum.h:59
void int int REAL REAL * y
Definition: read.cpp:74
bool is_one(const NT &x)
Definition: number_utils.h:179
CGAL_KERNEL_INLINE NT abs(const NT &x)
Definition: number_utils.h:209
bool is_zero(const NT &x)
Definition: number_utils.h:64
CGAL_KERNEL_INLINE const NT & min(const NT &x, const NT &y)
Definition: number_utils.h:215
#define CGAL_KERNEL_INLINE
Definition: kernel_basic.h:54
double sqrt(double d)
Definition: double.h:73
bool is_negative(const NT &x)
Definition: number_utils.h:86
Definition: enum.h:96
bool is_integral(const double d)
Definition: double.h:78
bool is_zero(const NT &x)
Definition: number_utils.h:173
Sign
Definition: enum.h:57
CGAL_KERNEL_INLINE Sign sign(const NT &x)
Definition: number_utils.h:108
NT square(const NT &n)
Definition: number_utils.h:158
bool is_positive(const NT &x)
Definition: number_utils.h:191
CGAL_KERNEL_INLINE Sign lexicographical_sign(const NT &x, const NT &y)
Definition: number_utils.h:203
Definition: enum.h:61
void int int REAL * x
Definition: read.cpp:74
CGAL_KERNEL_INLINE const NT & max(const NT &x, const NT &y)
Definition: number_utils.h:221
const NT & n
bool is_positive(const NT &x)
Definition: number_utils.h:97
bool is_finite(double d)
Definition: double.h:190
Comparison_result
Definition: enum.h:94
Definition: enum.h:98
bool is_valid(double d)
Definition: double.h:185
CGAL_KERNEL_INLINE Sign lexicographical_sign(const NT &x, const NT &y)
Definition: number_utils.h:119
Definition: enum.h:97
Definition: enum.h:60
CGAL_KERNEL_INLINE Comparison_result compare(const NT &n1, const NT &n2)
Definition: number_utils.h:143
#define CGAL_NTS
NT square(const NT &n)
Definition: number_utils.h:239
CGAL_KERNEL_INLINE Sign sign(const NT &x)
Definition: number_utils.h:197