Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
double.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 : Double.fw
37 // file : include/CGAL/double.h
38 // package : Number_types (3.4)
39 // revision : 3.4
40 // revision_date : 13 Jul 2000
41 // author(s) : Geert-Jan Giezeman
42 //
43 // coordinator : MPI, Saarbruecken (<Stefan.Schirra>)
44 // email : contact@cgal.org
45 // www : http://www.cgal.org
46 //
47 // ======================================================================
48 
49 
50 #ifndef CGAL_DOUBLE_H
51 #define CGAL_DOUBLE_H 1
52 
53 #include <CGAL/basic.h>
54 #ifndef CGAL_TAGS_H
55 #include <CGAL/tags.h>
56 #endif // CGAL_TAGS_H
57 #include <cmath>
58 #include <CGAL/IEEE_754_unions.h>
59 #ifdef __sgi
60 #include <fp_class.h>
61 #endif // __sgi
62 
64 
65 
66 inline
67 double
68 to_double(double d)
69 { return d; }
70 
71 inline
72 double
73 sqrt(double d)
74 { return std::sqrt(d); }
75 
76 inline
77 bool
78 is_integral (const double d)
79 { return ceil(d) == d; }
80 
81 inline
84 { return Number_tag(); }
85 
86 #ifdef OLD_FINITE_VALID
87 extern
88 bool
89 is_finite(double d);
90 
91 extern
92 bool
93 is_valid(double d);
94 
95 #else
96 
97 #ifdef __sgi
98 
99 // double
100 inline
101 bool is_finite(double d)
102 {
103  switch (fp_class_d(d)) {
104  case FP_POS_NORM:
105  case FP_NEG_NORM:
106  case FP_POS_ZERO:
107  case FP_NEG_ZERO:
108  case FP_POS_DENORM:
109  case FP_NEG_DENORM:
110  return true;
111  case FP_SNAN:
112  case FP_QNAN:
113  case FP_POS_INF:
114  case FP_NEG_INF:
115  return false;
116  }
117  return false; // NOT REACHED
118 }
119 
120 inline
121 bool is_valid(double d)
122 {
123  switch (fp_class_d(d)) {
124  case FP_POS_NORM:
125  case FP_NEG_NORM:
126  case FP_POS_ZERO:
127  case FP_NEG_ZERO:
128  case FP_POS_INF:
129  case FP_NEG_INF:
130  case FP_POS_DENORM:
131  case FP_NEG_DENORM:
132  return true;
133  case FP_SNAN:
134  case FP_QNAN:
135  return false;
136  }
137  return false; // NOT REACHED
138 }
139 
140 #else
141 #if defined(_MSC_VER) || defined(CGAL_MASK_FINITE_VALID) || defined(__BORLANDC__)
142 
143 #define CGAL_EXPONENT_DOUBLE_MASK 0x7ff00000
144 #define CGAL_MANTISSA_DOUBLE_MASK 0x000fffff
145 
146 inline
147 bool
148 is_finite_by_mask_double(unsigned int h)
149 {
150  unsigned int e = h & CGAL_EXPONENT_DOUBLE_MASK;
151  return ( ( e ^ CGAL_EXPONENT_DOUBLE_MASK ) != 0 );
152 }
153 
154 inline
155 bool
156 is_nan_by_mask_double(unsigned int h, unsigned int l)
157 {
158  if ( is_finite_by_mask_double(h) ) return false;
159  return ( (( h & CGAL_MANTISSA_DOUBLE_MASK ) != 0) || (( l & 0xffffffff ) != 0));
160 }
161 
162 inline
163 bool
164 is_finite( const double& dble)
165 {
166  double d = dble;
167  IEEE_754_double* p = reinterpret_cast<IEEE_754_double*>(&d);
168  return is_finite_by_mask_double( p->c.H );
169 }
170 
171 inline
172 bool
173 is_valid( const double& dble)
174 {
175  double d = dble;
176  IEEE_754_double* p = reinterpret_cast<IEEE_754_double*>(&d);
177  return ! ( is_nan_by_mask_double( p->c.H, p->c.L ));
178 }
179 
180 
181 #else
182 
183 inline
184 bool
185 is_valid(double d)
186 { return (d == d); }
187 
188 inline
189 bool
190 is_finite(double d)
191 { return (d == d) && (is_valid(d-d)); }
192 
193 #endif // MSC_VER || ...
194 #endif // __sgi
195 
196 #endif // OLD_FINITE_VALID
197 
198 inline
200 io_tag(double)
201 { return io_Operator(); }
202 
203 #ifndef CGAL_NO_NTS_NAMESPACE
204 namespace NTS {
205 #ifndef CGAL_NUMBER_UTILS_H
206 template <class NT> NT abs(const NT &x);
207 #endif // CGAL_NUMBER_UTILS_H
208 
210 inline
211 double
212 abs(const double& d)
213 { return CGAL_CLIB_STD::fabs(d); }
214 
215 
216 } // namespace NTS
217 #else
218 #ifndef CGAL_NUMBER_UTILS_H
219 template <class NT> NT abs(const NT &x);
220 #endif // CGAL_NUMBER_UTILS_H
221 
223 inline
224 double
225 abs(const double& d)
226 { return CGAL_CLIB_STD::fabs(d); }
227 
228 
229 #endif // CGAL_NO_NTS_NAMESPACE
230 
232 
233 #endif // CGAL_DOUBLE_H
io_Operator io_tag(double)
Definition: double.h:200
CGAL_BEGIN_NAMESPACE double to_double(double d)
Definition: double.h:68
const NT & d
double sqrt(double d)
Definition: double.h:73
bool is_integral(const double d)
Definition: double.h:78
#define CGAL_TEMPLATE_NULL
Definition: config.h:126
void int int REAL * x
Definition: read.cpp:74
bool is_finite(double d)
Definition: double.h:190
struct IEEE_754_double::@32 c
NT abs(const NT &x)
Definition: number_utils.h:130
bool is_valid(double d)
Definition: double.h:185
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
Number_tag number_type_tag(double)
Definition: double.h:83
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87