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_ShortReal_HeaderFile |
16 | #define _Standard_ShortReal_HeaderFile |
17 | |
d8d01f6e |
18 | #include <cmath> |
7fd59977 |
19 | #include <float.h> |
7fd59977 |
20 | |
ebc93ae7 |
21 | #include <Standard_values.h> |
7fd59977 |
22 | #include <Standard_TypeDef.hxx> |
7fd59977 |
23 | |
7fd59977 |
24 | // *********************************** // |
25 | // Class methods // |
26 | // // |
27 | // Machine-dependant values // |
28 | // Should be taken from include file // |
29 | // *********************************** // |
30 | |
31 | //------------------------------------------------------------------- |
32 | // ShortRealSmall : Returns the smallest positive ShortReal |
33 | //------------------------------------------------------------------- |
34 | inline Standard_ShortReal ShortRealSmall() |
35 | { return FLT_MIN; } |
36 | |
37 | //------------------------------------------------------------------- |
38 | // Abs : Returns the absolute value of a ShortReal |
39 | //------------------------------------------------------------------- |
40 | inline Standard_ShortReal Abs(const Standard_ShortReal Value) |
41 | #if defined (__alpha) || defined(DECOSF1) |
42 | { return fabsf(Value); } |
43 | #else |
44 | { return float( fabs (Value) ) ; } |
45 | #endif |
46 | |
47 | //------------------------------------------------------------------- |
48 | // ShortRealDigit : Returns the number of digits of precision in a ShortReal |
49 | //------------------------------------------------------------------- |
50 | inline Standard_Integer ShortRealDigits() |
51 | { return FLT_DIG; } |
52 | |
53 | //------------------------------------------------------------------- |
54 | // ShortRealEpsilon : Returns the minimum positive ShortReal such that |
55 | // 1.0 + x is not equal to 1.0 |
56 | //------------------------------------------------------------------- |
57 | inline Standard_ShortReal ShortRealEpsilon() |
58 | { return FLT_EPSILON; } |
59 | |
60 | //------------------------------------------------------------------- |
61 | // ShortRealFirst : Returns the minimum negative value of a ShortReal |
62 | //------------------------------------------------------------------- |
63 | inline Standard_ShortReal ShortRealFirst() |
64 | { Standard_ShortReal MaxFloatTmp = -FLT_MAX; |
65 | return MaxFloatTmp; } |
66 | |
67 | //------------------------------------------------------------------- |
68 | // ShortRealFirst10Exp : Returns the minimum value of exponent(base 10) of |
69 | // a ShortReal. |
70 | //------------------------------------------------------------------- |
71 | inline Standard_Integer ShortRealFirst10Exp() |
72 | { return FLT_MIN_10_EXP; } |
73 | |
74 | //------------------------------------------------------------------- |
75 | // ShortRealLast : Returns the maximum value of a ShortReal |
76 | //------------------------------------------------------------------- |
77 | inline Standard_ShortReal ShortRealLast() |
78 | { return FLT_MAX; } |
79 | |
80 | //------------------------------------------------------------------- |
81 | // ShortRealLast10Exp : Returns the maximum value of exponent(base 10) of |
82 | // a ShortReal. |
83 | //------------------------------------------------------------------- |
84 | inline Standard_Integer ShortRealLast10Exp() |
85 | { return FLT_MAX_10_EXP; } |
86 | |
87 | //------------------------------------------------------------------- |
88 | // ShortRealMantissa : Returns the size in bits of the matissa part of a |
89 | // ShortReal. |
90 | //------------------------------------------------------------------- |
91 | inline Standard_Integer ShortRealMantissa() |
92 | { return FLT_MANT_DIG; } |
93 | |
94 | //------------------------------------------------------------------- |
95 | // ShortRealRadix : Returns the radix of exponent representation |
96 | //------------------------------------------------------------------- |
97 | inline Standard_Integer ShortRealRadix() |
98 | { return FLT_RADIX; } |
99 | |
100 | //------------------------------------------------------------------- |
101 | // ShortRealSize : Returns the size in bits of an integer |
102 | //------------------------------------------------------------------- |
103 | inline Standard_Integer ShortRealSize() |
104 | { return BITS(Standard_ShortReal); } |
105 | |
106 | //------------------------------------------------------------------- |
107 | // Max : Returns the maximum value of two ShortReals |
108 | //------------------------------------------------------------------- |
109 | inline Standard_ShortReal Max (const Standard_ShortReal Val1, |
110 | const Standard_ShortReal Val2) |
111 | { |
112 | if (Val1 >= Val2) { |
113 | return Val1; |
114 | } else { |
115 | return Val2; |
116 | } |
117 | } |
118 | |
119 | //------------------------------------------------------------------- |
120 | // Min : Returns the minimum value of two ShortReals |
121 | //------------------------------------------------------------------- |
122 | inline Standard_ShortReal Min (const Standard_ShortReal Val1, |
123 | const Standard_ShortReal Val2) |
124 | { |
125 | if (Val1 <= Val2) { |
126 | return Val1; |
127 | } else { |
128 | return Val2; |
129 | } |
130 | } |
131 | |
132 | // =============================================== |
133 | // Methods from Standard_Entity class which are redefined: |
134 | // - Hascode |
135 | // - IsEqual |
7fd59977 |
136 | // =============================================== |
137 | |
138 | // ================================== |
139 | // Methods implemeted in Standard_ShortReal.cxx |
140 | // ================================== |
7fd59977 |
141 | __Standard_API Standard_Integer HashCode (const Standard_ShortReal, const Standard_Integer); |
7fd59977 |
142 | |
143 | //------------------------------------------------------------------- |
144 | // IsEqual : Returns Standard_True if two ShortReals are equal |
145 | //------------------------------------------------------------------- |
146 | inline Standard_Boolean IsEqual (const Standard_ShortReal Value1, |
147 | const Standard_ShortReal Value2) |
148 | { return Abs((Value1 - Value2)) < ShortRealSmall(); } |
149 | |
7fd59977 |
150 | #endif |
151 | |
152 | |