diff options
author | das <das@FreeBSD.org> | 2007-12-03 07:17:33 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2007-12-03 07:17:33 +0000 |
commit | 3f2a2dba4d4736a24fc3d2d5b0fc88cb2366e371 (patch) | |
tree | dfbf857f01092f36ec434909d5660e11c5be0ea8 /lib/libc/gdtoa | |
parent | bfeab92a370c0d11a767a0b417b85c10cde168c2 (diff) | |
download | FreeBSD-src-3f2a2dba4d4736a24fc3d2d5b0fc88cb2366e371.zip FreeBSD-src-3f2a2dba4d4736a24fc3d2d5b0fc88cb2366e371.tar.gz |
In scanf, round according to the current rounding mode.
Diffstat (limited to 'lib/libc/gdtoa')
-rw-r--r-- | lib/libc/gdtoa/_ldtoa.c | 12 | ||||
-rw-r--r-- | lib/libc/gdtoa/machdep_ldisQ.c | 4 | ||||
-rw-r--r-- | lib/libc/gdtoa/machdep_ldisx.c | 4 |
3 files changed, 16 insertions, 4 deletions
diff --git a/lib/libc/gdtoa/_ldtoa.c b/lib/libc/gdtoa/_ldtoa.c index 10731c4..952ca98 100644 --- a/lib/libc/gdtoa/_ldtoa.c +++ b/lib/libc/gdtoa/_ldtoa.c @@ -46,11 +46,11 @@ char * __ldtoa(long double *ld, int mode, int ndigits, int *decpt, int *sign, char **rve) { - static FPI fpi = { + FPI fpi = { LDBL_MANT_DIG, /* nbits */ LDBL_MIN_EXP - LDBL_MANT_DIG, /* emin */ LDBL_MAX_EXP - LDBL_MANT_DIG, /* emax */ - FPI_Round_near, /* rounding */ + FLT_ROUNDS, /* rounding */ #ifdef Sudden_Underflow /* unused, but correct anyway */ 1 #else @@ -64,7 +64,15 @@ __ldtoa(long double *ld, int mode, int ndigits, int *decpt, int *sign, void *vbits = bits; u.e = *ld; + + /* + * gdtoa doesn't know anything about the sign of the number, so + * if the number is negative, we need to swap rounding modes of + * 2 (upwards) and 3 (downwards). + */ *sign = u.bits.sign; + fpi.rounding ^= (fpi.rounding >> 1) & u.bits.sign; + be = u.bits.exp - (LDBL_MAX_EXP - 1) - (LDBL_MANT_DIG - 1); LDBL_TO_ARRAY32(u, bits); diff --git a/lib/libc/gdtoa/machdep_ldisQ.c b/lib/libc/gdtoa/machdep_ldisQ.c index e5cf6e6..ebcb37e 100644 --- a/lib/libc/gdtoa/machdep_ldisQ.c +++ b/lib/libc/gdtoa/machdep_ldisQ.c @@ -33,6 +33,8 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include <float.h> + #include "gdtoaimp.h" long double @@ -40,6 +42,6 @@ strtold(const char * __restrict s, char ** __restrict sp) { long double result; - strtopQ(s, sp, &result); + strtorQ(s, sp, FLT_ROUNDS, &result); return result; } diff --git a/lib/libc/gdtoa/machdep_ldisx.c b/lib/libc/gdtoa/machdep_ldisx.c index 0b61de6..c08c85e 100644 --- a/lib/libc/gdtoa/machdep_ldisx.c +++ b/lib/libc/gdtoa/machdep_ldisx.c @@ -33,6 +33,8 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include <float.h> + #include "gdtoaimp.h" long double @@ -40,6 +42,6 @@ strtold(const char * __restrict s, char ** __restrict sp) { long double result; - strtopx(s, sp, &result); + strtorx(s, sp, FLT_ROUNDS, &result); return result; } |