summaryrefslogtreecommitdiffstats
path: root/winsup/mingw/mingwex/math/llroundl.c
diff options
context:
space:
mode:
authorDanny Smith <dannysmith@users.sourceforge.net>2004-04-22 04:38:24 +0000
committerDanny Smith <dannysmith@users.sourceforge.net>2004-04-22 04:38:24 +0000
commit1a4b7623f43060162b933ac39a4c841ba0f008d0 (patch)
tree6ad3d8fac2b0b478f8799368728b2ef468a55002 /winsup/mingw/mingwex/math/llroundl.c
parentb7ede86cfec578cd698cfdbb367845f7e8ed7a25 (diff)
downloadcygnal-1a4b7623f43060162b933ac39a4c841ba0f008d0.tar.gz
cygnal-1a4b7623f43060162b933ac39a4c841ba0f008d0.tar.bz2
cygnal-1a4b7623f43060162b933ac39a4c841ba0f008d0.zip
* mingwex/math/lround.c: Rewrite.
* mingwex/math/lroundf.c: Rewrite. * mingwex/math/lroundl.c: Rewrite. * mingwex/math/llround.c: Rewrite. * mingwex/math/llroundf.c: Rewrite. * mingwex/math/llroundl.c: Rewrite.
Diffstat (limited to 'winsup/mingw/mingwex/math/llroundl.c')
-rw-r--r--winsup/mingw/mingwex/math/llroundl.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/winsup/mingw/mingwex/math/llroundl.c b/winsup/mingw/mingwex/math/llroundl.c
index ad334fb2c..9d2217411 100644
--- a/winsup/mingw/mingwex/math/llroundl.c
+++ b/winsup/mingw/mingwex/math/llroundl.c
@@ -1,22 +1,19 @@
-#include <fenv.h>
#include <math.h>
+#include <limits.h>
+#include <errno.h>
long long
-llroundl (long double x) {
- long long retval;
- unsigned short saved_cw, _cw;
- __asm__ (
- "fnstcw %0;" : "=m" (saved_cw)
- ); /* save control word */
- _cw = ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
- | (x > 0.0 ? FE_UPWARD : FE_DOWNWARD); /* round away from zero */
- __asm__ (
- "fldcw %0;" : : "m" (_cw)
- ); /* load the rounding control */
- __asm__ __volatile__ (
- "fistpll %0" : "=m" (retval) : "t" (x) : "st");
- __asm__ (
- "fldcw %0;" : : "m" (saved_cw)
- ); /* restore control word */
- return retval;
+llroundl (long double x)
+{
+ /* Add +/- 0.5, then round towards zero. */
+ long double tmp = truncl (x + (x >= 0.0L ? 0.5L : -0.5L));
+ if (!isfinite (tmp)
+ || tmp > (long double)LONG_LONG_MAX
+ || tmp < (long double)LONG_LONG_MIN)
+ {
+ errno = ERANGE;
+ /* Undefined behaviour, so we could return anything. */
+ /* return tmp > 0.0L ? LONG_LONG_MAX : LONG_LONG_MIN; */
+ }
+ return (long long)tmp;
}