From 0d2597f5a07cf946c921e66121f0b23aa4cc4d14 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Mon, 6 Oct 2008 19:47:06 +0000 Subject: [PATCH] 2008-10-06 Eric Blake * libc/stdlib/ldtoa.c (etoasc): Fix rounding to even when fraction is 0.5 or 0.75. --- newlib/ChangeLog | 5 +++++ newlib/libc/stdlib/ldtoa.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index c7e946f4f..cd001768b 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,8 @@ +2008-10-06 Eric Blake + + * libc/stdlib/ldtoa.c (etoasc): Fix rounding to even when fraction + is 0.5 or 0.75. + 2008-10-06 Craig Howland * libc/time/tzset_r.c (_tzset_r): Change US default start/end dates to diff --git a/newlib/libc/stdlib/ldtoa.c b/newlib/libc/stdlib/ldtoa.c index bb12f0cc7..5c2972593 100644 --- a/newlib/libc/stdlib/ldtoa.c +++ b/newlib/libc/stdlib/ldtoa.c @@ -3153,7 +3153,7 @@ if( digit > 4 ) emovo( y, t, ldp ); if( ecmp(t,ezero) != 0 ) goto roun; /* round to nearest */ - if( (*(s-1) & 1) == 0 ) + if( ndigs < 0 || (*(s-1-(*(s-1)=='.')) & 1) == 0 ) goto doexp; /* round to even */ } /* Round up and propagate carry-outs */