Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:59:18

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 <algorithm>
0019 #include <cmath>
0020 #include <climits>
0021 #include <float.h>
0022 
0023 #ifdef _MSC_VER
0024   #ifndef _USE_MATH_DEFINES
0025     #define _USE_MATH_DEFINES
0026   #endif
0027   #include <math.h>
0028 #endif
0029 
0030 #include <Standard_TypeDef.hxx>
0031 
0032 //! Returns the value of the arc cosine of a @p theValue.
0033 Standard_DEPRECATED("This function duplicates std::acos and will be removed in future releases. "
0034                     "Use std::acos instead.")
0035 inline double ACos(const double theValue)
0036 {
0037   return std::acos(theValue);
0038 }
0039 
0040 //! Returns the approximate value of the arc cosine @p theValue.
0041 //! The max error is about 1 degree near Value=0.
0042 //! NOTE: Avoid using this function in new code, it presumably slower then std::acos.
0043 Standard_DEPRECATED("Deprecated, use std::acos instead")
0044 Standard_EXPORT double ACosApprox(const double theValue);
0045 
0046 //! Returns the value of the arc sine of a @p theValue.
0047 Standard_DEPRECATED("This function duplicates std::asin and will be removed in future releases. "
0048                     "Use std::asin instead.")
0049 inline double ASin(const double theValue)
0050 {
0051   return std::asin(theValue);
0052 }
0053 
0054 //! Computes the arc tangent of @p theX divided by @p theY using the signs of both
0055 //! arguments to determine the quadrant of the return value.
0056 Standard_DEPRECATED("This function duplicates std::atan2 and will be removed in future releases. "
0057                     "Use std::atan2 instead.")
0058 inline double ATan2(const double theX, const double theY)
0059 {
0060   return std::atan2(theX, theY);
0061 }
0062 
0063 //! Returns the value of the hyperbolic arc tangent of @p theValue.
0064 Standard_DEPRECATED("This function duplicates std::atanh and will be removed in future releases. "
0065                     "Use std::atanh instead.")
0066 inline double ATanh(const double theValue)
0067 {
0068   return std::atanh(theValue);
0069 }
0070 
0071 //! Returns the value of the hyperbolic arc cosine of @p theValue.
0072 Standard_DEPRECATED("This function duplicates std::acosh and will be removed in future releases. "
0073                     "Use std::acosh instead.")
0074 inline double ACosh(const double theValue)
0075 {
0076   return std::acosh(theValue);
0077 }
0078 
0079 //! Returns the hyperbolic cosine of a double @p theValue.
0080 Standard_DEPRECATED("This function duplicates std::cosh and will be removed in future releases. "
0081                     "Use std::cosh instead.")
0082 inline double Cosh(const double theValue)
0083 {
0084   return std::cosh(theValue);
0085 }
0086 
0087 //! Returns the hyperbolic sine of a double @p theValue.
0088 Standard_DEPRECATED("This function duplicates std::sinh and will be removed in future releases. "
0089                     "Use std::sinh instead.")
0090 inline double Sinh(const double theValue)
0091 {
0092   return std::sinh(theValue);
0093 }
0094 
0095 //! Computes the natural (base-e) logarithm of number @p theValue.
0096 Standard_DEPRECATED("This function duplicates std::log and will be removed in future releases. "
0097                     "Use std::log instead.")
0098 inline double Log(const double theValue)
0099 {
0100   return std::log(theValue);
0101 }
0102 
0103 //! Returns the square root of a double @p theValue.
0104 Standard_DEPRECATED("This function duplicates std::sqrt and will be removed in future releases. "
0105                     "Use std::sqrt instead.")
0106 inline double Sqrt(const double theValue)
0107 {
0108   return std::sqrt(theValue);
0109 }
0110 
0111 //! Returns the next representable value of a double @p theValue
0112 //! in the direction of @p theDirection. Equivalent to std::nextafter.
0113 Standard_DEPRECATED(
0114   "This function duplicates std::nextafter and will be removed in future releases. "
0115   "Use std::nextafter instead.")
0116 inline double NextAfter(const double theValue, const double theDirection)
0117 {
0118   return std::nextafter(theValue, theDirection);
0119 }
0120 
0121 //! Composes a floating point value with the magnitude of @p theMagnitude
0122 //! and the sign of @p theSign. Equivalent to std::copysign.
0123 Standard_DEPRECATED(
0124   "This function duplicates std::copysign and will be removed in future releases. "
0125   "Use std::copysign instead.")
0126 inline double Sign(const double theMagnitude, const double theSign)
0127 {
0128   return std::copysign(theMagnitude, theSign);
0129 }
0130 
0131 //! Returns the minimum positive double value greater than zero.
0132 [[nodiscard]] constexpr double RealSmall()
0133 {
0134   return DBL_MIN;
0135 }
0136 
0137 //! Returns the absolute value of a double @p Value.
0138 //! Equivalent to std::abs.
0139 Standard_DEPRECATED("This function duplicates std::abs and will be removed in future releases. "
0140                     "Use std::abs instead.")
0141 inline double Abs(const double theValue)
0142 {
0143   return std::abs(theValue);
0144 }
0145 
0146 //! Returns Standard_True if two doubles are equal within the precision
0147 //! defined by RealSmall().
0148 [[nodiscard]] inline bool IsEqual(const double theValue1, const double theValue2)
0149 {
0150   return std::abs(theValue1 - theValue2) < RealSmall();
0151 }
0152 
0153 //! Returns the number of digits of precision in a double.
0154 [[nodiscard]] constexpr int RealDigits()
0155 {
0156   return DBL_DIG;
0157 }
0158 
0159 //! Returns the minimum positive double such that
0160 //! 1.0 + RealEpsilon() != 1.0.
0161 [[nodiscard]] constexpr double RealEpsilon()
0162 {
0163   return DBL_EPSILON;
0164 }
0165 
0166 //! Returns the minimum value of a double.
0167 [[nodiscard]] constexpr double RealFirst()
0168 {
0169   return -DBL_MAX;
0170 }
0171 
0172 //! Returns the minimum value of exponent(base 10) of a double.
0173 [[nodiscard]] constexpr int RealFirst10Exp()
0174 {
0175   return DBL_MIN_10_EXP;
0176 }
0177 
0178 //! Returns the maximum value of a double.
0179 [[nodiscard]] constexpr double RealLast()
0180 {
0181   return DBL_MAX;
0182 }
0183 
0184 //! Returns the maximum value of exponent(base 10) of a double.
0185 [[nodiscard]] constexpr int RealLast10Exp()
0186 {
0187   return DBL_MAX_10_EXP;
0188 }
0189 
0190 //! Returns the size in bits of the mantissa part of a double.
0191 [[nodiscard]] constexpr int RealMantissa()
0192 {
0193   return DBL_MANT_DIG;
0194 }
0195 
0196 //! Returns the radix of a double.
0197 [[nodiscard]] constexpr int RealRadix()
0198 {
0199   return FLT_RADIX;
0200 }
0201 
0202 //! Returns the size in bits of a double.
0203 [[nodiscard]] constexpr int RealSize()
0204 {
0205   return CHAR_BIT * sizeof(double);
0206 }
0207 
0208 //! Converts a int @p theValue to a double.
0209 [[nodiscard]] constexpr double IntToReal(const int theValue)
0210 {
0211   return theValue;
0212 }
0213 
0214 //! Returns the value of the arc tangent of a double @p theValue.
0215 Standard_DEPRECATED("This function duplicates std::atan and will be removed in future releases. "
0216                     "Use std::atan instead.")
0217 inline double ATan(const double theValue)
0218 {
0219   return std::atan(theValue);
0220 }
0221 
0222 //! Returns the next integer greater than or equal to a double @p theValue.
0223 Standard_DEPRECATED("This function duplicates std::ceil and will be removed in future releases. "
0224                     "Use std::ceil instead.")
0225 inline double Ceiling(const double theValue)
0226 {
0227   return std::ceil(theValue);
0228 }
0229 
0230 //! Returns the cosine of a double @p theValue.
0231 //! Equivalent to std::cos.
0232 Standard_DEPRECATED("This function duplicates std::cos and will be removed in future releases. "
0233                     "Use std::cos instead.")
0234 inline double Cos(const double theValue)
0235 {
0236   return std::cos(theValue);
0237 }
0238 
0239 //! The function returns absolute value of difference between @p theValue and other nearest value of
0240 //! double type. Nearest value is chosen in direction of infinity the same sign as @p theValue.
0241 //! If @p theValue is 0 then returns minimal positive value of double type.
0242 [[nodiscard]] inline double Epsilon(const double theValue)
0243 {
0244   return theValue >= 0.0 ? (std::nextafter(theValue, RealLast()) - theValue)
0245                          : (theValue - std::nextafter(theValue, RealFirst()));
0246 }
0247 
0248 //! Returns the exponential of a double @p theValue.
0249 //! Equivalent to std::exp.
0250 Standard_DEPRECATED("This function duplicates std::exp and will be removed in future releases. "
0251                     "Use std::exp instead.")
0252 inline double Exp(const double theValue)
0253 {
0254   return std::exp(theValue);
0255 }
0256 
0257 //! Returns the nearest integer less than or equal to a double @p theValue.
0258 //! Equivalent to std::floor.
0259 Standard_DEPRECATED("This function duplicates std::floor and will be removed in future releases. "
0260                     "Use std::floor instead.")
0261 inline double Floor(const double theValue)
0262 {
0263   return std::floor(theValue);
0264 }
0265 
0266 //! Returns the integer part of a double @p theValue.
0267 //! Equivalent to std::trunc.
0268 Standard_DEPRECATED("This function duplicates std::trunc and will be removed in future releases. "
0269                     "Use std::trunc instead.")
0270 inline double IntegerPart(const double theValue)
0271 {
0272   return std::trunc(theValue);
0273 }
0274 
0275 //! Returns the logarithm to base 10 of a double @p theValue.
0276 //! Equivalent to std::log10.
0277 Standard_DEPRECATED("This function duplicates std::log10 and will be removed in future releases. "
0278                     "Use std::log10 instead.")
0279 inline double Log10(const double theValue)
0280 {
0281   return std::log10(theValue);
0282 }
0283 
0284 //! Returns the maximum value of two doubles.
0285 //! Equivalent to std::max.
0286 Standard_DEPRECATED("This function duplicates std::max and will be removed in future releases. "
0287                     "Use std::max instead.")
0288 constexpr double Max(const double theValue1, const double theValue2)
0289 {
0290   return (std::max)(theValue1, theValue2);
0291 }
0292 
0293 //! Returns the minimum value of two doubles.
0294 //! Equivalent to std::min.
0295 Standard_DEPRECATED("This function duplicates std::min and will be removed in future releases. "
0296                     "Use std::min instead.")
0297 constexpr double Min(const double theValue1, const double theValue2)
0298 {
0299   return (std::min)(theValue1, theValue2);
0300 }
0301 
0302 //! Returns a double @p theValue raised to the power of @p thePower.
0303 Standard_DEPRECATED("This function duplicates std::pow and will be removed in future releases. "
0304                     "Use std::pow instead.")
0305 inline double Pow(const double theValue, const double thePower)
0306 {
0307   return std::pow(theValue, thePower);
0308 }
0309 
0310 //! Returns the fractional part of a double @p theValue.
0311 //! Always non-negative.
0312 [[nodiscard]] inline double RealPart(const double theValue)
0313 {
0314   return std::abs(std::trunc(theValue) - theValue);
0315 }
0316 
0317 //! Converts a double @p theValue to the nearest valid int.
0318 //! If input value is out of valid range for int, minimal or maximal possible int is returned.
0319 [[nodiscard]] constexpr int RealToInt(const double theValue)
0320 {
0321   // Note that on WNT under MS VC++ 8.0 conversion of double value less
0322   // than INT_MIN or greater than INT_MAX to integer will cause signal
0323   // "Floating point multiple trap" (OCC17861)
0324   return theValue < static_cast<double>(INT_MIN)
0325            ? static_cast<int>(INT_MIN)
0326            : (theValue > static_cast<double>(INT_MAX) ? static_cast<int>(INT_MAX)
0327                                                       : static_cast<int>(theValue));
0328 }
0329 
0330 //! Converts a double @p theValue to the nearest valid float.
0331 //! If input value is out of valid range for float, minimal or maximal
0332 //! possible float is returned.
0333 [[nodiscard]] constexpr float RealToShortReal(const double theValue)
0334 {
0335   return theValue < -FLT_MAX  ? -FLT_MAX
0336          : theValue > FLT_MAX ? FLT_MAX
0337                               : static_cast<float>(theValue);
0338 }
0339 
0340 //! Returns the nearest integer of a double @p theValue.
0341 //! Equivalent to std::round.
0342 Standard_DEPRECATED("This function duplicates std::round and will be removed in future releases. "
0343                     "Use std::round instead.")
0344 inline double Round(const double theValue)
0345 {
0346   return std::round(theValue);
0347 }
0348 
0349 //! Returns the sine of a double @p theValue.
0350 //! Equivalent to std::sin.
0351 Standard_DEPRECATED("This function duplicates std::sin and will be removed in future releases. "
0352                     "Use std::sin instead.")
0353 inline double Sin(const double theValue)
0354 {
0355   return std::sin(theValue);
0356 }
0357 
0358 //! Returns the hyperbolic arc sine of a double @p theValue.
0359 //! Equivalent to std::asinh.
0360 Standard_DEPRECATED("This function duplicates std::asinh and will be removed in future releases. "
0361                     "Use std::asinh instead.")
0362 inline double ASinh(const double theValue)
0363 {
0364   return std::asinh(theValue);
0365 }
0366 
0367 //! Returns the square of a double @p theValue.
0368 [[nodiscard]] constexpr double Square(const double theValue)
0369 {
0370   return theValue * theValue;
0371 }
0372 
0373 //! Returns the tangent of a double @p theValue.
0374 //! Equivalent to std::tan.
0375 Standard_DEPRECATED("This function duplicates std::tan and will be removed in future releases. "
0376                     "Use std::tan instead.")
0377 inline double Tan(const double theValue)
0378 {
0379   return std::tan(theValue);
0380 }
0381 
0382 //! Returns the hyperbolic tangent of a double @p theValue.
0383 //! Equivalent to std::tanh.
0384 Standard_DEPRECATED("This function duplicates std::tanh and will be removed in future releases. "
0385                     "Use std::tanh instead.")
0386 inline double Tanh(const double theValue)
0387 {
0388   return std::tanh(theValue);
0389 }
0390 
0391 #endif // _Standard_Real_HeaderFile