diff options
-rw-r--r-- | winsup/mingw/ChangeLog | 6 | ||||
-rw-r--r-- | winsup/mingw/mingwex/math/round.c | 31 | ||||
-rw-r--r-- | winsup/mingw/mingwex/math/roundf.c | 31 | ||||
-rw-r--r-- | winsup/mingw/mingwex/math/roundl.c | 32 |
4 files changed, 21 insertions, 79 deletions
diff --git a/winsup/mingw/ChangeLog b/winsup/mingw/ChangeLog index 65641bbc4..a4412a204 100644 --- a/winsup/mingw/ChangeLog +++ b/winsup/mingw/ChangeLog @@ -1,3 +1,9 @@ +2004-03-29 Danny Smith <dannysmith@users.sourceforge.net> + + * mingwex/math/round.c: Rewrite. + * mingwex/math/roundf.c: Rewrite. + * mingwex/math/roundl.c: Rewrite. + 2004-03-25 Danny Smith <dannysmith@users.sourceforge.net> * include/_mingw.h (__MSVCRT_VERSION__): Define default as 0x0600. diff --git a/winsup/mingw/mingwex/math/round.c b/winsup/mingw/mingwex/math/round.c index 9d8e949e4..d2d4cab5e 100644 --- a/winsup/mingw/mingwex/math/round.c +++ b/winsup/mingw/mingwex/math/round.c @@ -1,29 +1,8 @@ -#include <fenv.h> +#include <math.h> double -round (double x) { - double 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__ ( - "frndint;" - : "=t" (retval) - : "0" (x) - ); /* do the rounding */ - __asm__ ( - "fldcw %0;" - : - : "m" (saved_cw) - ); /* restore control word */ - return retval; +round (double x) +{ + /* Add +/- 0.5 then then round towards zero. */ + return trunc ( x + (x >= 0.0 ? 0.5 : -0.5)); } diff --git a/winsup/mingw/mingwex/math/roundf.c b/winsup/mingw/mingwex/math/roundf.c index 6ae81bdd8..b50d950a7 100644 --- a/winsup/mingw/mingwex/math/roundf.c +++ b/winsup/mingw/mingwex/math/roundf.c @@ -1,29 +1,8 @@ -#include <fenv.h> +#include <math.h> float -roundf (float x) { - double 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__ ( - "frndint;" - : "=t" (retval) - : "0" (x) - ); /* do the rounding */ - __asm__ ( - "fldcw %0;" - : - : "m" (saved_cw) - ); /* restore control word */ - return retval; +roundf (float x) +{ + /* Add +/- 0.5 then then round towards zero. */ + return truncf ( x + (x >= 0.0F ? 0.5F : -0.5F)); } diff --git a/winsup/mingw/mingwex/math/roundl.c b/winsup/mingw/mingwex/math/roundl.c index de3334a62..9c5f0aca1 100644 --- a/winsup/mingw/mingwex/math/roundl.c +++ b/winsup/mingw/mingwex/math/roundl.c @@ -1,30 +1,8 @@ -#include <fenv.h> +#include <math.h> long double -roundl (long double x) { - long double 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__ ( - "frndint;" - : "=t" (retval) - : "0" (x) - ); /* do the rounding */ - __asm__ ( - "fldcw %0;" - : - : "m" (saved_cw) - ); /* restore control word */ - return retval; +roundl (long double x) +{ + /* Add +/- 0.5 then then round towards zero. */ + return truncl ( x + (x >= 0.0L ? 0.5L : -0.5L)); } - |