Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
float.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 : Float.fw
37 // file : include/CGAL/float.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_FLOAT_H
51 #define CGAL_FLOAT_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
62 
64 
65 inline
66 double
67 to_double(float f)
68 { return (double)f; }
69 
70 inline
73 { return Number_tag(); }
74 
75 #ifdef OLD_FINITE_VALID
76 extern
77 bool
78 is_finite(float d);
79 
80 extern
81 bool
82 is_valid(float d);
83 
84 #else
85 #ifdef __sgi
86 
87 inline
88 bool is_finite(float f)
89 {
90  switch (fp_class_f(f)) {
91  case FP_POS_NORM:
92  case FP_NEG_NORM:
93  case FP_POS_ZERO:
94  case FP_NEG_ZERO:
95  case FP_POS_DENORM:
96  case FP_NEG_DENORM:
97  return true;
98  case FP_SNAN:
99  case FP_QNAN:
100  case FP_POS_INF:
101  case FP_NEG_INF:
102  return false;
103  }
104  return false; // NOT REACHED
105 }
106 
107 inline
108 bool is_valid(float d)
109 {
110  switch (fp_class_f(d)) {
111  case FP_POS_NORM:
112  case FP_NEG_NORM:
113  case FP_POS_ZERO:
114  case FP_NEG_ZERO:
115  case FP_POS_INF:
116  case FP_NEG_INF:
117  case FP_POS_DENORM:
118  case FP_NEG_DENORM:
119  return true;
120  case FP_SNAN:
121  case FP_QNAN:
122  return false;
123  }
124  return false; // NOT REACHED
125 }
126 
127 #else
128 #if defined(_MSC_VER) || defined(CGAL_MASK_FINITE_VALID) || defined(__BORLANDC__)
129 
130 #define CGAL_EXPONENT_FLOAT_MASK 0x7f800000
131 #define CGAL_MANTISSA_FLOAT_MASK 0x007fffff
132 
133 inline
134 bool
135 is_finite_by_mask_float(unsigned int u)
136 {
137  unsigned int e = u & CGAL_EXPONENT_FLOAT_MASK;
138  return ( (e ^ CGAL_EXPONENT_FLOAT_MASK) != 0);
139 }
140 
141 inline
142 bool
143 is_nan_by_mask_float(unsigned int u)
144 {
145  if ( is_finite_by_mask_float(u) ) return false;
146  // unsigned int m = u & CGAL_MANTISSA_FLOAT_MASK;
147  return ( (u & CGAL_MANTISSA_FLOAT_MASK) != 0);
148 }
149 
150 inline
151 bool
152 is_finite( const float& flt)
153 {
154  float f = flt;
155  IEEE_754_float* p = reinterpret_cast<IEEE_754_float*>(&f);
156  return is_finite_by_mask_float( p->c );
157 }
158 
159 inline
160 bool
161 is_valid( const float& flt)
162 {
163  float f = flt;
164  IEEE_754_float* p = reinterpret_cast<IEEE_754_float*>(&f);
165  return !is_nan_by_mask_float( p->c );
166 }
167 
168 
169 
170 #else
171 
172 inline
173 bool
174 is_valid(float d)
175 { return (d == d); }
176 
177 inline
178 bool
179 is_finite(float d)
180 { return (d == d) && (is_valid(d-d)); }
181 
182 #endif // MSC_VER || ...
183 #endif // __sgi
184 
185 #endif // OLD_FINITE_VALID
186 
187 inline
189 io_tag(float)
190 { return io_Operator(); }
191 
193 
194 #endif // CGAL_FLOAT_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
bool is_finite(double d)
Definition: double.h:190
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