summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-02-28 22:19:37 +0600
committerMike Kaganski <mike.kaganski@collabora.com>2024-02-29 01:39:00 +0100
commite2473fe3a547e5a11d3b91ab8ded833bf5b74356 (patch)
treed076ddfe58e332e91ad7828208b817f4ca8f5ff2 /sal
parent364f0bb1cac0e12f5f926857f61c2f329a353ec7 (diff)
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.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/math.cxx38
1 files changed, 3 insertions, 35 deletions
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)