---
Updated to check with fegetround to see which rounding mode to use,
fixed the way the mode is checked (by using == instead of &).
---
mingw-w64-crt/math/llrint.c | 11 ++++++++++-
mingw-w64-crt/math/llrintf.c | 11 ++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/mingw-w64-crt/math/llrint.c b/mingw-w64-crt/math/llrint.c
index 1fc11e8..8b138c0 100644
--- a/mingw-w64-crt/math/llrint.c
+++ b/mingw-w64-crt/math/llrint.c
@@ -4,6 +4,7 @@
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <math.h>
+#include <fenv.h>
long long llrint (double x)
{
@@ -11,7 +12,15 @@ long long llrint (double x)
#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) ||
defined(__i386__)
__asm__ __volatile__ ("fistpll %0" : "=m" (retval) : "t" (x) : "st");
#else
- retval = (long long)x;
+ int mode = fegetround();
+ if (mode == FE_DOWNWARD)
+ retval = (long long)floor(x);
+ else if (mode == FE_UPWARD)
+ retval = (long long)ceil(x);
+ else if (mode == FE_TOWARDZERO)
+ retval = x >= 0 ? (long long)floor(x) : (long long)ceil(x);
+ else
+ retval = x >= 0 ? (long long)floor(x + 0.5) : (long long)ceil(x - 0.5);
#endif
return retval;
}
diff --git a/mingw-w64-crt/math/llrintf.c b/mingw-w64-crt/math/llrintf.c
index aabd81f..1b2a422 100644
--- a/mingw-w64-crt/math/llrintf.c
+++ b/mingw-w64-crt/math/llrintf.c
@@ -4,6 +4,7 @@
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <math.h>
+#include <fenv.h>
long long llrintf (float x)
{
@@ -11,7 +12,15 @@ long long llrintf (float x)
#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) ||
defined(__i386__)
__asm__ __volatile__ ("fistpll %0" : "=m" (retval) : "t" (x) : "st");
#else
- retval = (long long)x;
+ int mode = fegetround();
+ if (mode == FE_DOWNWARD)
+ retval = (long long)floorf(x);
+ else if (mode == FE_UPWARD)
+ retval = (long long)ceilf(x);
+ else if (mode == FE_TOWARDZERO)
+ retval = x >= 0 ? (long long)floorf(x) : (long long)ceilf(x);
+ else
+ retval = x >= 0 ? (long long)floorf(x + 0.5) : (long long)ceilf(x - 0.5);
#endif
return retval;
}
--
2.7.4
------------------------------------------------------------------------------
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public