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