]> OCCT Git - occt.git/commitdiff
Coding - Reorganize code with constexpr #85 IR-2024-10-04
authordpasukhi <dpasukhi@opencascade.com>
Sat, 28 Sep 2024 21:19:40 +0000 (21:19 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Mon, 30 Sep 2024 17:38:25 +0000 (17:38 +0000)
Continue rework Precision.hxx and Standard type definitions

src/Precision/Precision.hxx
src/Standard/Standard_Character.hxx
src/Standard/Standard_Integer.hxx
src/Standard/Standard_Real.cxx
src/Standard/Standard_Real.hxx
src/Standard/Standard_ShortReal.hxx

index c5d851d64288764c519e8c46986b011996b27caf..66b5340a84bd22fe11f703682956ac490a1abb5c 100644 (file)
@@ -210,7 +210,7 @@ public:
   //! length of the tangent of the curve or the surface.
   //!
   //! Value is P / T
-  static inline Standard_Real Parametric (const Standard_Real P, const Standard_Real T) { return P / T; }
+  static constexpr Standard_Real Parametric (const Standard_Real P, const Standard_Real T) { return P / T; }
 
   //! Returns a precision value in parametric space, which may be used :
   //! -   to test the coincidence of two points in the real space,
@@ -256,7 +256,7 @@ public:
   //! 2.Pi without impacting on the resulting point.
   //! Therefore, take great care when adjusting a parametric
   //! tolerance to your own algorithm.
-  static inline Standard_Real PConfusion (const Standard_Real T) { return Parametric (Confusion(), T); }
+  static constexpr Standard_Real PConfusion (const Standard_Real T) { return Parametric (Confusion(), T); }
 
   //! Returns square of PConfusion.
   //! Created for speed and convenience.
@@ -275,7 +275,7 @@ public:
   //! segment whose length is equal to 100. (default value), or T.
   //! The parametric tolerance of intersection is equal to :
   //! -   Precision::Intersection() / 100., or Precision::Intersection() / T.
-  static inline Standard_Real PIntersection (const Standard_Real T) { return Parametric(Intersection(),T); }
+  static constexpr Standard_Real PIntersection (const Standard_Real T) { return Parametric(Intersection(),T); }
 
   //! Returns a precision value in parametric space, which may
   //! be used by approximation algorithms. The purpose of this
@@ -290,13 +290,13 @@ public:
   //! segment whose length is equal to 100. (default value), or T.
   //! The parametric tolerance of intersection is equal to :
   //! -   Precision::Approximation() / 100., or Precision::Approximation() / T.
-  static inline Standard_Real PApproximation (const Standard_Real T) { return Parametric(Approximation(),T); }
+  static constexpr Standard_Real PApproximation (const Standard_Real T) { return Parametric(Approximation(),T); }
 
   //! Convert a real  space precision  to  a  parametric
   //! space precision on a default curve.
   //!
   //! Value is Parametric(P,1.e+2)
-  static inline Standard_Real Parametric (const Standard_Real P) { return P * 0.01; }
+  static constexpr Standard_Real Parametric (const Standard_Real P) { return P * 0.01; }
 
   //! Used  to test distances  in parametric  space on a
   //! default curve.
@@ -322,11 +322,11 @@ public:
 
   //! Returns True if R may be considered as  a positive
   //! infinite number. Currently R > 1e100
-  static inline Standard_Boolean IsPositiveInfinite (const Standard_Real R) { return R >= (0.5 * Precision::Infinite()); }
+  static constexpr Standard_Boolean IsPositiveInfinite (const Standard_Real R) { return R >= (0.5 * Precision::Infinite()); }
 
   //! Returns True if R may  be considered as a negative
   //! infinite number. Currently R < -1e100
-  static inline Standard_Boolean IsNegativeInfinite (const Standard_Real R) { return R <= -(0.5 * Precision::Infinite()); }
+  static constexpr Standard_Boolean IsNegativeInfinite (const Standard_Real R) { return R <= -(0.5 * Precision::Infinite()); }
 
   //! Returns a  big number that  can  be  considered as
   //! infinite. Use -Infinite() for a negative big number.
index e29f1a4c5563dfb42223d75189fcec9c139f2e26..513f6f407022efbdab79d63803c51922aef9b08e 100644 (file)
@@ -30,8 +30,8 @@
 // ------------------------------------------------------------------
 // IsEqual : Returns Standard_True if two characters have the same value
 // ------------------------------------------------------------------
-inline Standard_Boolean IsEqual(const Standard_Character One,
-                               const Standard_Character Two)
+constexpr Standard_Boolean IsEqual(const Standard_Character One,
+                                   const Standard_Character Two)
 { return One == Two; }
 
 // ===============================================
index d629b87c06e45cc2f7fc2501ec4653ca6442c12e..47a7061f904e95000b710fc91085a73d9d5a0947 100755 (executable)
@@ -27,7 +27,7 @@
 // ------------------------------------------------------------------
 // Abs : Returns the absolute value of an Integer
 // ------------------------------------------------------------------
-inline  Standard_Integer Abs (const Standard_Integer Value)
+constexpr  Standard_Integer Abs (const Standard_Integer Value)
 {
   return Value >= 0 ? Value : -Value;
 }
@@ -35,20 +35,20 @@ inline  Standard_Integer Abs (const Standard_Integer Value)
 // ------------------------------------------------------------------
 // IsEven : Returns Standard_True if an integer is even
 // ------------------------------------------------------------------
-inline Standard_Boolean IsEven (const Standard_Integer Value)
+constexpr Standard_Boolean IsEven (const Standard_Integer Value)
 { return Value % 2 == 0; }
 
 
 // ------------------------------------------------------------------
 // IsOdd : Returns Standard_True if an integer is odd
 // ------------------------------------------------------------------
-inline Standard_Boolean IsOdd (const Standard_Integer Value)
+constexpr Standard_Boolean IsOdd (const Standard_Integer Value)
 { return Value % 2 == 1; }
 
 // ------------------------------------------------------------------
 // Max : Returns the maximum integer between two integers
 // ------------------------------------------------------------------
-inline Standard_Integer  Max (const Standard_Integer Val1,
+constexpr Standard_Integer  Max (const Standard_Integer Val1,
                              const Standard_Integer Val2)
 {
   return Val1 >= Val2 ? Val1 : Val2;
@@ -57,7 +57,7 @@ inline Standard_Integer  Max (const Standard_Integer Val1,
 // ------------------------------------------------------------------
 // Min : Returns the minimum integer between two integers
 // ------------------------------------------------------------------
-inline Standard_Integer  Min (const Standard_Integer Val1,
+constexpr Standard_Integer  Min (const Standard_Integer Val1,
                              const Standard_Integer Val2)
 {
   return Val1 <= Val2 ? Val1 : Val2;
@@ -66,14 +66,14 @@ inline Standard_Integer  Min (const Standard_Integer Val1,
 // ------------------------------------------------------------------
 // Modulus : Returns the remainder of division between two integers
 // ------------------------------------------------------------------
-inline Standard_Integer  Modulus (const Standard_Integer Value,
+constexpr Standard_Integer  Modulus (const Standard_Integer Value,
                                  const Standard_Integer Divisor)
 { return Value % Divisor; }
 
 // ------------------------------------------------------------------
 // Square : Returns the square of an integer
 // ------------------------------------------------------------------
-inline Standard_Integer Square(const Standard_Integer Value)
+constexpr Standard_Integer Square(const Standard_Integer Value)
 { return Value * Value; }
 
 // ------------------------------------------------------------------
index 51721d48d7c7b0637b91a248d4d39bb05b075f9c..7d1749f47b6fdb2a65e59141c1a5ebe0be83bbfd 100644 (file)
@@ -172,8 +172,8 @@ static int HardwareLowBitsOfDouble()
   }
 }
 
-static int HighBitsOfDouble = HardwareHighBitsOfDouble();
-static int LowBitsOfDouble = HardwareLowBitsOfDouble();
+static const int HighBitsOfDouble = HardwareHighBitsOfDouble();
+static const int LowBitsOfDouble = HardwareLowBitsOfDouble();
 
 double NextAfter(const double x, const double y)
 {
index f185568f515fd9a82f1a992cddc900afc128d313..a4a9717ef5691346c6222d8cf8cc433a4680b328 100644 (file)
@@ -182,16 +182,10 @@ inline Standard_Real     Cos (const Standard_Real Value)
 //           If 'Value' is 0 then returns minimal positive value
 //           of Standard_Real type.
 //-------------------------------------------------------------------
-inline Standard_Real     Epsilon (const Standard_Real Value) 
+inline Standard_Real     Epsilon (const Standard_Real Value)
 {
-  Standard_Real aEpsilon;
-
-  if (Value>=0.0){
-    aEpsilon = NextAfter(Value, RealLast()) - Value;
-  } else {
-    aEpsilon = Value - NextAfter(Value, RealFirst());
-  }
-  return aEpsilon;
+  return Value >= 0.0 ? (NextAfter(Value, RealLast()) - Value)
+                      : (Value - NextAfter(Value, RealFirst()));
 }
 
 //-------------------------------------------------------------------
@@ -222,7 +216,7 @@ inline Standard_Real     Log10 (const Standard_Real Value)
 //-------------------------------------------------------------------
 // Max : Returns the maximum value of two reals
 //-------------------------------------------------------------------
-inline Standard_Real     Max (const Standard_Real Val1, 
+constexpr Standard_Real  Max (const Standard_Real Val1, 
                               const Standard_Real Val2) 
 {
   return Val1 >= Val2 ? Val1 : Val2;
@@ -231,7 +225,7 @@ inline Standard_Real     Max (const Standard_Real Val1,
 //-------------------------------------------------------------------
 // Min : Returns the minimum value of two reals
 //-------------------------------------------------------------------
-inline Standard_Real     Min (const Standard_Real Val1, 
+constexpr Standard_Real  Min (const Standard_Real Val1, 
                               const Standard_Real Val2)
 {
   return Val1 <= Val2 ? Val1 : Val2;
@@ -254,7 +248,7 @@ inline  Standard_Real    RealPart (const Standard_Real Value)
 //             If input value is out of valid range for integers,
 //             minimal or maximal possible integer is returned.
 //-------------------------------------------------------------------
-inline Standard_Integer RealToInt (const Standard_Real theValue)
+constexpr Standard_Integer RealToInt (const Standard_Real theValue)
 { 
   // Note that on WNT under MS VC++ 8.0 conversion of double value less 
   // than INT_MIN or greater than INT_MAX to integer will cause signal 
@@ -273,7 +267,7 @@ inline Standard_Integer RealToInt (const Standard_Real theValue)
 //            for Standard_ShortReal, minimal or maximal
 //            Standard_ShortReal is returned.
 // =======================================================================
-inline Standard_ShortReal RealToShortReal (const Standard_Real theVal)
+constexpr Standard_ShortReal RealToShortReal (const Standard_Real theVal)
 {
   return theVal < -FLT_MAX ? -FLT_MAX
     : theVal > FLT_MAX ? FLT_MAX
@@ -306,7 +300,7 @@ inline Standard_Real     ASinh(const Standard_Real Value)
 //-------------------------------------------------------------------
 // Square : Returns a real to the power 2
 //-------------------------------------------------------------------
-inline Standard_Real     Square(const Standard_Real Value) 
+constexpr Standard_Real     Square(const Standard_Real Value) 
 { return Value * Value; }
 
 //-------------------------------------------------------------------
index cf9927248ecdba0e60580f7ab90392055e89b968..9d1da827c1b66bf19a0157f9aa434f85cb4e69e4 100644 (file)
@@ -105,27 +105,19 @@ constexpr Standard_Integer  ShortRealSize()
 //-------------------------------------------------------------------
 // Max : Returns the maximum value of two ShortReals
 //-------------------------------------------------------------------
-inline Standard_ShortReal     Max (const Standard_ShortReal Val1, 
-                                  const Standard_ShortReal Val2) 
+constexpr Standard_ShortReal Max(const Standard_ShortReal Val1,
+                                 const Standard_ShortReal Val2)
 {
-  if (Val1 >= Val2) {
-    return Val1;
-  } else {
-    return Val2;
-  }
+  return Val1 >= Val2 ? Val1 : Val2;
 }
 
 //-------------------------------------------------------------------
 // Min : Returns the minimum value of two ShortReals
 //-------------------------------------------------------------------
-inline Standard_ShortReal     Min (const Standard_ShortReal Val1, 
-                                  const Standard_ShortReal Val2)
+constexpr Standard_ShortReal Min(const Standard_ShortReal Val1,
+                                 const Standard_ShortReal Val2)
 {
-  if (Val1 <= Val2) {
-    return Val1;
-  } else {
-    return Val2;
-  }
+  return Val1 <= Val2 ? Val1 : Val2;
 }
 
 #endif