sal/rtl/math.cxx |   38 +++-----------------------------------
 1 file changed, 3 insertions(+), 35 deletions(-)

New commits:
commit e2473fe3a547e5a11d3b91ab8ded833bf5b74356
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Feb 28 22:19:37 2024 +0600
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Feb 29 01:39:00 2024 +0100

    Drop redundant code: this is handled below
    
    And use standard functions in the rtl_math_RoundingMode_HalfEven
    handler.
    
    Change-Id: If9f29aa63423db9457a02ed003cfc27cf3df5585
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164104
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index 75cada0b7d48..fe45b90a8297 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -459,23 +459,6 @@ double SAL_CALL rtl_math_round(double fValue, int 
nDecPlaces, enum rtl_math_Roun
     if (fValue == 0.0)
         return fValue;
 
-    if (nDecPlaces == 0)
-    {
-        switch (eMode)
-        {
-            case rtl_math_RoundingMode_HalfEven:
-                if (const int oldMode = std::fegetround(); 
std::fesetround(FE_TONEAREST) == 0)
-                {
-                    fValue = std::nearbyint(fValue);
-                    std::fesetround(oldMode);
-                    return fValue;
-                }
-                break;
-            default:
-                break;
-        }
-    }
-
     const double fOrigValue = fValue;
 
     // sign adjustment
@@ -568,27 +551,12 @@ double SAL_CALL rtl_math_round(double fValue, int 
nDecPlaces, enum rtl_math_Roun
             }
             break;
             case rtl_math_RoundingMode_HalfEven:
-#if defined FLT_ROUNDS
-                /*
-                   Use fast version. FLT_ROUNDS may be defined to a function 
by some compilers!
-
-                   DBL_EPSILON is the smallest fractional number which can be 
represented,
-                   its reciprocal is therefore the smallest number that cannot 
have a
-                   fractional part. Once you add this reciprocal to `x', its 
fractional part
-                   is stripped off. Simply subtracting the reciprocal back out 
returns `x'
-                   without its fractional component.
-                   Simple, clever, and elegant - thanks to Ross Cottrell, the 
original author,
-                   who placed it into public domain.
-
-                   volatile: prevent compiler from being too smart
-                */
-                if (FLT_ROUNDS == 1)
+                if (const int oldMode = std::fegetround(); 
std::fesetround(FE_TONEAREST) == 0)
                 {
-                    volatile double x = fValue + 1.0 / DBL_EPSILON;
-                    fValue = x - 1.0 / DBL_EPSILON;
+                    fValue = std::nearbyint(fValue);
+                    std::fesetround(oldMode);
                 }
                 else
-#endif // FLT_ROUNDS
                 {
                     double f = floor(fValue);
                     if ((fValue - f) != 0.5)

Reply via email to