1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _Standard_ShortReal_HeaderFile
16 #define _Standard_ShortReal_HeaderFile
21 #include <Standard_values.h>
22 #include <Standard_TypeDef.hxx>
24 // *********************************** //
27 // Machine-dependant values //
28 // Should be taken from include file //
29 // *********************************** //
31 //-------------------------------------------------------------------
32 // ShortRealSmall : Returns the smallest positive ShortReal
33 //-------------------------------------------------------------------
34 inline Standard_ShortReal ShortRealSmall()
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); }
44 { return float( fabs (Value) ) ; }
47 //-------------------------------------------------------------------
48 // ShortRealDigit : Returns the number of digits of precision in a ShortReal
49 //-------------------------------------------------------------------
50 inline Standard_Integer ShortRealDigits()
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; }
60 //-------------------------------------------------------------------
61 // ShortRealFirst : Returns the minimum negative value of a ShortReal
62 //-------------------------------------------------------------------
63 inline Standard_ShortReal ShortRealFirst()
64 { Standard_ShortReal MaxFloatTmp = -FLT_MAX;
67 //-------------------------------------------------------------------
68 // ShortRealFirst10Exp : Returns the minimum value of exponent(base 10) of
70 //-------------------------------------------------------------------
71 inline Standard_Integer ShortRealFirst10Exp()
72 { return FLT_MIN_10_EXP; }
74 //-------------------------------------------------------------------
75 // ShortRealLast : Returns the maximum value of a ShortReal
76 //-------------------------------------------------------------------
77 inline Standard_ShortReal ShortRealLast()
80 //-------------------------------------------------------------------
81 // ShortRealLast10Exp : Returns the maximum value of exponent(base 10) of
83 //-------------------------------------------------------------------
84 inline Standard_Integer ShortRealLast10Exp()
85 { return FLT_MAX_10_EXP; }
87 //-------------------------------------------------------------------
88 // ShortRealMantissa : Returns the size in bits of the matissa part of a
90 //-------------------------------------------------------------------
91 inline Standard_Integer ShortRealMantissa()
92 { return FLT_MANT_DIG; }
94 //-------------------------------------------------------------------
95 // ShortRealRadix : Returns the radix of exponent representation
96 //-------------------------------------------------------------------
97 inline Standard_Integer ShortRealRadix()
100 //-------------------------------------------------------------------
101 // ShortRealSize : Returns the size in bits of an integer
102 //-------------------------------------------------------------------
103 inline Standard_Integer ShortRealSize()
104 { return BITS(Standard_ShortReal); }
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)
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)
132 // ===============================================
133 // Methods from Standard_Entity class which are redefined:
136 // ===============================================
138 // ==================================
139 // Methods implemeted in Standard_ShortReal.cxx
140 // ==================================
142 //! Computes a hash code for the given short real, in the range [1, theUpperBound]
143 //! @param theShortReal the short real value which hash code is to be computed
144 //! @param theUpperBound the upper bound of the range a computing hash code must be within
145 //! @return a computed hash code, in the range [1, theUpperBound]
146 Standard_EXPORT Standard_Integer HashCode (Standard_ShortReal theShortReal, Standard_Integer theUpperBound);
148 //-------------------------------------------------------------------
149 // IsEqual : Returns Standard_True if two ShortReals are equal
150 //-------------------------------------------------------------------
151 inline Standard_Boolean IsEqual (const Standard_ShortReal Value1,
152 const Standard_ShortReal Value2)
153 { return Abs((Value1 - Value2)) < ShortRealSmall(); }