|
||||
File indexing completed on 2024-11-15 09:48:39
0001 // Copyright (c) 1998-1999 Matra Datavision 0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0003 // 0004 // This file is part of Open CASCADE Technology software library. 0005 // 0006 // This library is free software; you can redistribute it and/or modify it under 0007 // the terms of the GNU Lesser General Public License version 2.1 as published 0008 // by the Free Software Foundation, with special exception defined in the file 0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0010 // distribution for complete text of the license and disclaimer of any warranty. 0011 // 0012 // Alternatively, this file may be used under the terms of Open CASCADE 0013 // commercial license or contractual agreement. 0014 0015 #ifndef _Standard_Real_HeaderFile 0016 #define _Standard_Real_HeaderFile 0017 0018 #include <cmath> 0019 #include <float.h> 0020 #include <Standard_values.h> 0021 #include <Standard_math.hxx> 0022 #include <Standard_TypeDef.hxx> 0023 0024 // =============================================== 0025 // Methods from Standard_Entity class which are redefined: 0026 // - Hascode 0027 // - IsEqual 0028 // =============================================== 0029 0030 // ================================== 0031 // Methods implemented in Standard_Real.cxx 0032 // ================================== 0033 0034 //! Computes a hash code for the given real, in the range [1, theUpperBound] 0035 //! @param theReal the real value which hash code is to be computed 0036 //! @param theUpperBound the upper bound of the range a computing hash code must be within 0037 //! @return a computed hash code, in the range [1, theUpperBound] 0038 Standard_EXPORT Standard_Integer HashCode (Standard_Real theReal, Standard_Integer theUpperBound); 0039 0040 Standard_EXPORT Standard_Real ACos (const Standard_Real ); 0041 Standard_EXPORT Standard_Real ACosApprox (const Standard_Real ); 0042 Standard_EXPORT Standard_Real ASin (const Standard_Real ); 0043 Standard_EXPORT Standard_Real ATan2 (const Standard_Real , const Standard_Real ); 0044 Standard_EXPORT Standard_Real NextAfter (const Standard_Real , const Standard_Real ); 0045 0046 //! Returns |a| if b >= 0; -|a| if b < 0. 0047 Standard_EXPORT Standard_Real Sign(const Standard_Real a, const Standard_Real b); 0048 0049 Standard_EXPORT Standard_Real ATanh (const Standard_Real ); 0050 Standard_EXPORT Standard_Real ACosh (const Standard_Real ); 0051 Standard_EXPORT Standard_Real Sinh (const Standard_Real ); 0052 Standard_EXPORT Standard_Real Cosh (const Standard_Real ); 0053 Standard_EXPORT Standard_Real Log (const Standard_Real ); 0054 Standard_EXPORT Standard_Real Sqrt (const Standard_Real ); 0055 0056 //------------------------------------------------------------------- 0057 // RealSmall : Returns the smallest positive real 0058 //------------------------------------------------------------------- 0059 inline Standard_Real RealSmall() 0060 { return DBL_MIN; } 0061 0062 //------------------------------------------------------------------- 0063 // Abs : Returns the absolute value of a real 0064 //------------------------------------------------------------------- 0065 inline Standard_Real Abs(const Standard_Real Value) 0066 { return fabs(Value); } 0067 0068 0069 //------------------------------------------------------------------- 0070 // IsEqual : Returns Standard_True if two reals are equal 0071 //------------------------------------------------------------------- 0072 inline Standard_Boolean IsEqual (const Standard_Real Value1, 0073 const Standard_Real Value2) 0074 { return Abs((Value1 - Value2)) < RealSmall(); } 0075 0076 // *********************************** // 0077 // Class methods // 0078 // // 0079 // Machine-dependent values // 0080 // Should be taken from include file // 0081 // *********************************** // 0082 0083 0084 //------------------------------------------------------------------- 0085 // RealDigit : Returns the number of digits of precision in a real 0086 //------------------------------------------------------------------- 0087 inline Standard_Integer RealDigits() 0088 { return DBL_DIG; } 0089 0090 //------------------------------------------------------------------- 0091 // RealEpsilon : Returns the minimum positive real such that 0092 // 1.0 + x is not equal to 1.0 0093 //------------------------------------------------------------------- 0094 inline Standard_Real RealEpsilon() 0095 { return DBL_EPSILON; } 0096 0097 //------------------------------------------------------------------- 0098 // RealFirst : Returns the minimum negative value of a real 0099 //------------------------------------------------------------------- 0100 inline Standard_Real RealFirst() 0101 { return -DBL_MAX; } 0102 0103 //------------------------------------------------------------------- 0104 // RealFirst10Exp : Returns the minimum value of exponent(base 10) of 0105 // a real. 0106 //------------------------------------------------------------------- 0107 inline Standard_Integer RealFirst10Exp() 0108 { return DBL_MIN_10_EXP; } 0109 0110 //------------------------------------------------------------------- 0111 // RealLast : Returns the maximum value of a real 0112 //------------------------------------------------------------------- 0113 inline Standard_Real RealLast() 0114 { return DBL_MAX; } 0115 0116 //------------------------------------------------------------------- 0117 // RealLast10Exp : Returns the maximum value of exponent(base 10) of 0118 // a real. 0119 //------------------------------------------------------------------- 0120 inline Standard_Integer RealLast10Exp() 0121 { return DBL_MAX_10_EXP; } 0122 0123 //------------------------------------------------------------------- 0124 // RealMantissa : Returns the size in bits of the matissa part of a 0125 // real. 0126 //------------------------------------------------------------------- 0127 inline Standard_Integer RealMantissa() 0128 { return DBL_MANT_DIG; } 0129 0130 //------------------------------------------------------------------- 0131 // RealRadix : Returns the radix of exponent representation 0132 //------------------------------------------------------------------- 0133 inline Standard_Integer RealRadix() 0134 { return FLT_RADIX; } 0135 0136 //------------------------------------------------------------------- 0137 // RealSize : Returns the size in bits of an integer 0138 //------------------------------------------------------------------- 0139 inline Standard_Integer RealSize() 0140 { return BITS(Standard_Real); } 0141 0142 0143 0144 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=// 0145 // End of machine-dependent values // 0146 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=// 0147 0148 0149 //------------------------------------------------------------------- 0150 // IntToReal : Converts an integer in a real 0151 //------------------------------------------------------------------- 0152 inline Standard_Real IntToReal(const Standard_Integer Value) 0153 { return Value; } 0154 0155 //------------------------------------------------------------------- 0156 // ATan : Returns the value of the arc tangent of a real 0157 //------------------------------------------------------------------- 0158 inline Standard_Real ATan(const Standard_Real Value) 0159 { return atan(Value); } 0160 0161 0162 //------------------------------------------------------------------- 0163 // Ceiling : Returns the smallest integer not less than a real 0164 //------------------------------------------------------------------- 0165 inline Standard_Real Ceiling (const Standard_Real Value) 0166 { return ceil(Value); } 0167 0168 //------------------------------------------------------------------- 0169 // Cos : Returns the cosine of a real 0170 //------------------------------------------------------------------- 0171 inline Standard_Real Cos (const Standard_Real Value) 0172 { return cos(Value); } 0173 0174 0175 //------------------------------------------------------------------- 0176 // Epsilon : The function returns absolute value of difference 0177 // between 'Value' and other nearest value of 0178 // Standard_Real type. 0179 // Nearest value is chosen in direction of infinity 0180 // the same sign as 'Value'. 0181 // If 'Value' is 0 then returns minimal positive value 0182 // of Standard_Real type. 0183 //------------------------------------------------------------------- 0184 inline Standard_Real Epsilon (const Standard_Real Value) 0185 { 0186 Standard_Real aEpsilon; 0187 0188 if (Value>=0.0){ 0189 aEpsilon = NextAfter(Value, RealLast()) - Value; 0190 } else { 0191 aEpsilon = Value - NextAfter(Value, RealFirst()); 0192 } 0193 return aEpsilon; 0194 } 0195 0196 //------------------------------------------------------------------- 0197 // Exp : Returns the exponential function of a real 0198 //------------------------------------------------------------------- 0199 inline Standard_Real Exp (const Standard_Real Value) 0200 { return exp(Value); } 0201 0202 //------------------------------------------------------------------- 0203 // Floor : Return the largest integer not greater than a real 0204 //------------------------------------------------------------------- 0205 inline Standard_Real Floor (const Standard_Real Value) 0206 { return floor(Value); } 0207 0208 //------------------------------------------------------------------- 0209 // IntegerPart : Returns the integer part of a real 0210 //------------------------------------------------------------------- 0211 inline Standard_Real IntegerPart (const Standard_Real Value) 0212 { return ( (Value>0) ? floor(Value) : ceil(Value) ); } 0213 0214 0215 //------------------------------------------------------------------- 0216 // Log10 : Returns the base-10 logarithm of a real 0217 //------------------------------------------------------------------- 0218 inline Standard_Real Log10 (const Standard_Real Value) 0219 { return log10(Value); } 0220 0221 //------------------------------------------------------------------- 0222 // Max : Returns the maximum value of two reals 0223 //------------------------------------------------------------------- 0224 inline Standard_Real Max (const Standard_Real Val1, 0225 const Standard_Real Val2) 0226 { 0227 return Val1 >= Val2 ? Val1 : Val2; 0228 } 0229 0230 //------------------------------------------------------------------- 0231 // Min : Returns the minimum value of two reals 0232 //------------------------------------------------------------------- 0233 inline Standard_Real Min (const Standard_Real Val1, 0234 const Standard_Real Val2) 0235 { 0236 return Val1 <= Val2 ? Val1 : Val2; 0237 } 0238 0239 //------------------------------------------------------------------- 0240 // Pow : Returns a real to a given power 0241 //------------------------------------------------------------------- 0242 inline Standard_Real Pow (const Standard_Real Value, const Standard_Real P) 0243 { return pow(Value,P); } 0244 0245 //------------------------------------------------------------------- 0246 // RealPart : Returns the fractional part of a real. 0247 //------------------------------------------------------------------- 0248 inline Standard_Real RealPart (const Standard_Real Value) 0249 { return fabs(IntegerPart(Value) - Value); } 0250 0251 //------------------------------------------------------------------- 0252 // RealToInt : Returns the real converted to nearest valid integer. 0253 // If input value is out of valid range for integers, 0254 // minimal or maximal possible integer is returned. 0255 //------------------------------------------------------------------- 0256 inline Standard_Integer RealToInt (const Standard_Real theValue) 0257 { 0258 // Note that on WNT under MS VC++ 8.0 conversion of double value less 0259 // than INT_MIN or greater than INT_MAX to integer will cause signal 0260 // "Floating point multiple trap" (OCC17861) 0261 return theValue < static_cast<Standard_Real>(INT_MIN) 0262 ? static_cast<Standard_Integer>(INT_MIN) 0263 : (theValue > static_cast<Standard_Real>(INT_MAX) 0264 ? static_cast<Standard_Integer>(INT_MAX) 0265 : static_cast<Standard_Integer>(theValue)); 0266 } 0267 0268 // ======================================================================= 0269 // function : RealToShortReal 0270 // purpose : Converts Standard_Real value to the nearest valid 0271 // Standard_ShortReal. If input value is out of valid range 0272 // for Standard_ShortReal, minimal or maximal 0273 // Standard_ShortReal is returned. 0274 // ======================================================================= 0275 inline Standard_ShortReal RealToShortReal (const Standard_Real theVal) 0276 { 0277 return theVal < -FLT_MAX ? -FLT_MAX 0278 : theVal > FLT_MAX ? FLT_MAX 0279 : (Standard_ShortReal)theVal; 0280 } 0281 0282 //------------------------------------------------------------------- 0283 // Round : Returns the nearest integer of a real 0284 //------------------------------------------------------------------- 0285 inline Standard_Real Round (const Standard_Real Value) 0286 { return IntegerPart(Value + (Value > 0 ? 0.5 : -0.5)); } 0287 0288 //------------------------------------------------------------------- 0289 // Sin : Returns the sine of a real 0290 //------------------------------------------------------------------- 0291 inline Standard_Real Sin (const Standard_Real Value) 0292 { return sin(Value); } 0293 0294 0295 //------------------------------------------------------------------- 0296 // ASinh : Returns the hyperbolic arc sine of a real 0297 //------------------------------------------------------------------- 0298 inline Standard_Real ASinh(const Standard_Real Value) 0299 #if defined(__QNX__) 0300 { return std::asinh(Value); } 0301 #else 0302 { return asinh(Value); } 0303 #endif 0304 0305 //------------------------------------------------------------------- 0306 // Square : Returns a real to the power 2 0307 //------------------------------------------------------------------- 0308 inline Standard_Real Square(const Standard_Real Value) 0309 { return Value * Value; } 0310 0311 //------------------------------------------------------------------- 0312 // Tan : Returns the tangent of a real 0313 //------------------------------------------------------------------- 0314 inline Standard_Real Tan (const Standard_Real Value) 0315 { return tan(Value); } 0316 0317 //------------------------------------------------------------------- 0318 // Tanh : Returns the hyperbolic tangent of a real 0319 //------------------------------------------------------------------- 0320 inline Standard_Real Tanh (const Standard_Real Value) 0321 { return tanh(Value); } 0322 0323 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |