Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-18 10:08:57

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