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