summaryrefslogtreecommitdiffstats
path: root/lib/libc/gdtoa/_ldtoa.c
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2007-12-03 07:17:33 +0000
committerdas <das@FreeBSD.org>2007-12-03 07:17:33 +0000
commit3f2a2dba4d4736a24fc3d2d5b0fc88cb2366e371 (patch)
treedfbf857f01092f36ec434909d5660e11c5be0ea8 /lib/libc/gdtoa/_ldtoa.c
parentbfeab92a370c0d11a767a0b417b85c10cde168c2 (diff)
downloadFreeBSD-src-3f2a2dba4d4736a24fc3d2d5b0fc88cb2366e371.zip
FreeBSD-src-3f2a2dba4d4736a24fc3d2d5b0fc88cb2366e371.tar.gz
In scanf, round according to the current rounding mode.
Diffstat (limited to 'lib/libc/gdtoa/_ldtoa.c')
-rw-r--r--lib/libc/gdtoa/_ldtoa.c12
1 files changed, 10 insertions, 2 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);
OpenPOWER on IntegriCloud