summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sal/rtl/math.cxx22
1 files changed, 20 insertions, 2 deletions
diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index 698e158df072..7db362f35cfe 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -33,6 +33,8 @@
#include <algorithm>
#include <cassert>
+#include <cfenv>
+#include <cmath>
#include <float.h>
#include <limits>
#include <limits.h>
@@ -1137,8 +1139,24 @@ double SAL_CALL rtl_math_round(double fValue, int nDecPlaces,
if (fValue == 0.0)
return fValue;
- if ( nDecPlaces == 0 && eMode == rtl_math_RoundingMode_Corrected )
- return std::round( fValue );
+ if (nDecPlaces == 0)
+ {
+ switch (eMode)
+ {
+ case rtl_math_RoundingMode_Corrected:
+ return std::round(fValue);
+ 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;