b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | #ifndef _Standard_Real_HeaderFile |
16 | #define _Standard_Real_HeaderFile |
17 | |
18 | #include <float.h> |
19 | #include <math.h> |
ebc93ae7 |
20 | #include <Standard_values.h> |
21 | #include <Standard_math.hxx> |
7fd59977 |
22 | #include <Standard_TypeDef.hxx> |
7fd59977 |
23 | |
24 | class Handle_Standard_Type; |
25 | |
34781c33 |
26 | __Standard_API const Handle_Standard_Type& Standard_Real_Type_(); |
7fd59977 |
27 | |
7fd59977 |
28 | // =============================================== |
29 | // Methods from Standard_Entity class which are redefined: |
30 | // - Hascode |
31 | // - IsEqual |
32 | // - IsSimilar |
33 | // - Shallowcopy |
34 | // - ShallowDump |
35 | // =============================================== |
36 | |
37 | // ================================== |
38 | // Methods implemeted in Standard_Real.cxx |
39 | // ================================== |
40 | //.... Herited from Standard_Storable |
41 | __Standard_API Standard_Integer HashCode (const Standard_Real, const Standard_Integer); |
42 | __Standard_API Standard_Real ShallowCopy (const Standard_Real ); |
43 | |
44 | __Standard_API Standard_Real ACos (const Standard_Real ); |
45 | __Standard_API Standard_Real ACosApprox (const Standard_Real ); |
46 | __Standard_API Standard_Real ASin (const Standard_Real ); |
47 | __Standard_API Standard_Real ATan2 (const Standard_Real , const Standard_Real ); |
48 | __Standard_API Standard_Real NextAfter (const Standard_Real , const Standard_Real ); |
49 | __Standard_API Standard_Real Sign (const Standard_Real , const Standard_Real ); |
50 | __Standard_API Standard_Real ATanh (const Standard_Real ); |
51 | __Standard_API Standard_Real ACosh (const Standard_Real ); |
52 | __Standard_API Standard_Real Log (const Standard_Real ); |
53 | __Standard_API Standard_Real Sqrt (const Standard_Real ); |
54 | |
55 | //class Standard_OStream; |
56 | //void ShallowDump(const Standard_Real, Standard_OStream& ); |
57 | |
58 | //------------------------------------------------------------------- |
59 | // RealSmall : Returns the smallest positive real |
60 | //------------------------------------------------------------------- |
61 | inline Standard_Real RealSmall() |
62 | { return DBL_MIN; } |
63 | |
64 | //------------------------------------------------------------------- |
65 | // Abs : Returns the absolute value of a real |
66 | //------------------------------------------------------------------- |
67 | inline Standard_Real Abs(const Standard_Real Value) |
68 | { return fabs(Value); } |
69 | |
70 | |
71 | //------------------------------------------------------------------- |
72 | // IsEqual : Returns Standard_True if two reals are equal |
73 | //------------------------------------------------------------------- |
74 | inline Standard_Boolean IsEqual (const Standard_Real Value1, |
75 | const Standard_Real Value2) |
76 | { return Abs((Value1 - Value2)) < RealSmall(); } |
77 | |
78 | //------------------------------------------------------------------- |
79 | // IsSimilar : Returns Standard_True if two reals are equal |
80 | //------------------------------------------------------------------- |
81 | inline Standard_Boolean IsSimilar(const Standard_Real One, |
82 | const Standard_Real Two) |
83 | { return IsEqual (One,Two); } |
84 | |
85 | |
86 | |
87 | // *********************************** // |
88 | // Class methods // |
89 | // // |
90 | // Machine-dependant values // |
91 | // Should be taken from include file // |
92 | // *********************************** // |
93 | |
94 | |
95 | //------------------------------------------------------------------- |
96 | // RealDigit : Returns the number of digits of precision in a real |
97 | //------------------------------------------------------------------- |
98 | inline Standard_Integer RealDigits() |
99 | { return DBL_DIG; } |
100 | |
101 | //------------------------------------------------------------------- |
102 | // RealEpsilon : Returns the minimum positive real such that |
103 | // 1.0 + x is not equal to 1.0 |
104 | //------------------------------------------------------------------- |
105 | inline Standard_Real RealEpsilon() |
106 | { return DBL_EPSILON; } |
107 | |
108 | //------------------------------------------------------------------- |
109 | // RealFirst : Returns the minimum negative value of a real |
110 | //------------------------------------------------------------------- |
111 | inline Standard_Real RealFirst() |
112 | { return -DBL_MAX; } |
113 | |
114 | //------------------------------------------------------------------- |
115 | // RealFirst10Exp : Returns the minimum value of exponent(base 10) of |
116 | // a real. |
117 | //------------------------------------------------------------------- |
118 | inline Standard_Integer RealFirst10Exp() |
119 | { return DBL_MIN_10_EXP; } |
120 | |
121 | //------------------------------------------------------------------- |
122 | // RealLast : Returns the maximum value of a real |
123 | //------------------------------------------------------------------- |
124 | inline Standard_Real RealLast() |
125 | { return DBL_MAX; } |
126 | |
127 | //------------------------------------------------------------------- |
128 | // RealLast10Exp : Returns the maximum value of exponent(base 10) of |
129 | // a real. |
130 | //------------------------------------------------------------------- |
131 | inline Standard_Integer RealLast10Exp() |
132 | { return DBL_MAX_10_EXP; } |
133 | |
134 | //------------------------------------------------------------------- |
135 | // RealMantissa : Returns the size in bits of the matissa part of a |
136 | // real. |
137 | //------------------------------------------------------------------- |
138 | inline Standard_Integer RealMantissa() |
139 | { return DBL_MANT_DIG; } |
140 | |
141 | //------------------------------------------------------------------- |
142 | // RealRadix : Returns the radix of exponent representation |
143 | //------------------------------------------------------------------- |
144 | inline Standard_Integer RealRadix() |
145 | { return FLT_RADIX; } |
146 | |
147 | //------------------------------------------------------------------- |
148 | // RealSize : Returns the size in bits of an integer |
149 | //------------------------------------------------------------------- |
150 | inline Standard_Integer RealSize() |
151 | { return BITS(Standard_Real); } |
152 | |
153 | |
154 | |
155 | //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=// |
156 | // End of machine-dependant values // |
157 | //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=// |
158 | |
159 | |
160 | //------------------------------------------------------------------- |
161 | // IntToReal : Converts an integer in a real |
162 | //------------------------------------------------------------------- |
163 | inline Standard_Real IntToReal(const Standard_Integer Value) |
164 | { return Value; } |
165 | |
166 | //------------------------------------------------------------------- |
167 | // ATan : Returns the value of the arc tangent of a real |
168 | //------------------------------------------------------------------- |
169 | inline Standard_Real ATan(const Standard_Real Value) |
170 | { return atan(Value); } |
171 | |
172 | |
173 | //------------------------------------------------------------------- |
174 | // Ceiling : Returns the smallest integer not less than a real |
175 | //------------------------------------------------------------------- |
176 | inline Standard_Real Ceiling (const Standard_Real Value) |
177 | { return ceil(Value); } |
178 | |
179 | //------------------------------------------------------------------- |
180 | // Cos : Returns the cosine of a real |
181 | //------------------------------------------------------------------- |
182 | inline Standard_Real Cos (const Standard_Real Value) |
183 | { return cos(Value); } |
184 | |
185 | //------------------------------------------------------------------- |
186 | // Cosh : Returns the hyperbolic cosine of a real |
187 | //------------------------------------------------------------------- |
188 | inline Standard_Real Cosh (const Standard_Real Value) |
189 | { return cosh(Value); } |
190 | |
191 | |
192 | //------------------------------------------------------------------- |
be53be81 |
193 | // Epsilon : The function returns absolute value of difference |
194 | // between 'Value' and other nearest value of |
195 | // Standard_Real type. |
196 | // Nearest value is choseen in direction of infinity |
197 | // the same sign as 'Value'. |
198 | // If 'Value' is 0 then returns minimal positive value |
199 | // of Standard_Real type. |
7fd59977 |
200 | //------------------------------------------------------------------- |
201 | inline Standard_Real Epsilon (const Standard_Real Value) |
202 | { |
203 | Standard_Real aEpsilon; |
204 | |
205 | if (Value>=0.0){ |
206 | aEpsilon = NextAfter(Value, RealLast()) - Value; |
207 | } else { |
208 | aEpsilon = Value - NextAfter(Value, RealFirst()); |
209 | } |
210 | return aEpsilon; |
211 | } |
212 | |
213 | //------------------------------------------------------------------- |
214 | // Exp : Returns the exponential function of a real |
215 | //------------------------------------------------------------------- |
216 | inline Standard_Real Exp (const Standard_Real Value) |
217 | { return exp(Value); } |
218 | |
219 | //------------------------------------------------------------------- |
220 | // Floor : Return the largest integer not greater than a real |
221 | //------------------------------------------------------------------- |
222 | inline Standard_Real Floor (const Standard_Real Value) |
223 | { return floor(Value); } |
224 | |
225 | //------------------------------------------------------------------- |
226 | // IntegerPart : Returns the integer part of a real |
227 | //------------------------------------------------------------------- |
228 | inline Standard_Real IntegerPart (const Standard_Real Value) |
229 | { return ( (Value>0) ? floor(Value) : ceil(Value) ); } |
230 | |
231 | |
232 | //------------------------------------------------------------------- |
233 | // Log10 : Returns the base-10 logarithm of a real |
234 | //------------------------------------------------------------------- |
235 | inline Standard_Real Log10 (const Standard_Real Value) |
236 | { return log10(Value); } |
237 | |
238 | //------------------------------------------------------------------- |
239 | // Max : Returns the maximum value of two reals |
240 | //------------------------------------------------------------------- |
241 | inline Standard_Real Max (const Standard_Real Val1, |
242 | const Standard_Real Val2) |
243 | { |
244 | return Val1 >= Val2 ? Val1 : Val2; |
245 | } |
246 | |
247 | //------------------------------------------------------------------- |
248 | // Min : Returns the minimum value of two reals |
249 | //------------------------------------------------------------------- |
250 | inline Standard_Real Min (const Standard_Real Val1, |
251 | const Standard_Real Val2) |
252 | { |
253 | return Val1 <= Val2 ? Val1 : Val2; |
254 | } |
255 | |
256 | //------------------------------------------------------------------- |
257 | // Pow : Returns a real to a given power |
258 | //------------------------------------------------------------------- |
259 | inline Standard_Real Pow (const Standard_Real Value, const Standard_Real P) |
260 | { return pow(Value,P); } |
261 | |
262 | //------------------------------------------------------------------- |
263 | // RealPart : Returns the fractional part of a real. |
264 | //------------------------------------------------------------------- |
265 | inline Standard_Real RealPart (const Standard_Real Value) |
266 | { return fabs(IntegerPart(Value) - Value); } |
267 | |
268 | //------------------------------------------------------------------- |
269 | // RealToInt : Returns the real converted to nearest valid integer. |
270 | // If input value is out of valid range for integers, |
271 | // minimal or maximal possible integer is returned. |
272 | //------------------------------------------------------------------- |
273 | inline Standard_Integer RealToInt (const Standard_Real Value) |
274 | { |
275 | // Note that on WNT under MS VC++ 8.0 conversion of double value less |
276 | // than INT_MIN or greater than INT_MAX to integer will cause signal |
277 | // "Floating point multiple trap" (OCC17861) |
278 | return Value < INT_MIN ? INT_MIN |
279 | : Value > INT_MAX ? INT_MAX |
280 | : (Standard_Integer)Value; |
281 | } |
282 | |
283 | //------------------------------------------------------------------- |
284 | // Round : Returns the nearest integer of a real |
285 | //------------------------------------------------------------------- |
286 | inline Standard_Real Round (const Standard_Real Value) |
287 | { return IntegerPart(Value + (Value > 0 ? 0.5 : -0.5)); } |
288 | |
289 | //------------------------------------------------------------------- |
290 | // Sin : Returns the sine of a real |
291 | //------------------------------------------------------------------- |
292 | inline Standard_Real Sin (const Standard_Real Value) |
293 | { return sin(Value); } |
294 | |
295 | //------------------------------------------------------------------- |
296 | // Sinh : Returns the hyperbolic sine of a real |
297 | //------------------------------------------------------------------- |
298 | inline Standard_Real Sinh(const Standard_Real Value) |
299 | { return sinh(Value); } |
300 | |
301 | //------------------------------------------------------------------- |
302 | // ASinh : Returns the hyperbolic arc sine of a real |
303 | //------------------------------------------------------------------- |
304 | inline Standard_Real ASinh(const Standard_Real Value) |
305 | { return asinh(Value); } |
306 | |
307 | //------------------------------------------------------------------- |
308 | // Square : Returns a real to the power 2 |
309 | //------------------------------------------------------------------- |
310 | inline Standard_Real Square(const Standard_Real Value) |
311 | { return Value * Value; } |
312 | |
313 | //------------------------------------------------------------------- |
314 | // Tan : Returns the tangent of a real |
315 | //------------------------------------------------------------------- |
316 | inline Standard_Real Tan (const Standard_Real Value) |
317 | { return tan(Value); } |
318 | |
319 | //------------------------------------------------------------------- |
320 | // Tanh : Returns the hyperbolic tangent of a real |
321 | //------------------------------------------------------------------- |
322 | inline Standard_Real Tanh (const Standard_Real Value) |
323 | { return tanh(Value); } |
324 | |
325 | #endif |