diff options
author | Kevin B Kenny <kennykb@acm.org> | 2011-01-15 18:10:18 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2011-01-15 18:10:18 (GMT) |
commit | 3aded4ee3f9fa66143b3b8b4be6b021243515cf1 (patch) | |
tree | 51b622116570a04f374cceb905e6453578b77cae /generic/tclStrToD.c | |
parent | 825e2402afb20392182bfdb0cc585bf5f2c5f89d (diff) | |
download | tcl-3aded4ee3f9fa66143b3b8b4be6b021243515cf1.zip tcl-3aded4ee3f9fa66143b3b8b4be6b021243515cf1.tar.gz tcl-3aded4ee3f9fa66143b3b8b4be6b021243515cf1.tar.bz2 |
* doc/tclvars.n:
* generic/tclStrToD.c:
* generic/tclUtil.c (Tcl_PrintDouble):
* tests/util.test (util-16.*): Restored full Tcl 8.4 compatibility
for the formatting of floating point numbers when $::tcl_precision
is not zero. Added compatibility tests to make sure that excess
trailing zeroes are suppressed for all eight major code paths.
[Bug 3157475]
Diffstat (limited to 'generic/tclStrToD.c')
-rwxr-xr-x | generic/tclStrToD.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c index 51a1a58..53ffedd 100755 --- a/generic/tclStrToD.c +++ b/generic/tclStrToD.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclStrToD.c,v 1.52 2010/12/07 16:27:39 dkf Exp $ + * RCS: @(#) $Id: tclStrToD.c,v 1.53 2011/01/15 18:10:19 kennykb Exp $ */ #include "tclInt.h" @@ -3086,6 +3086,11 @@ StrictInt64Conversion( if (i == ilim) { if (2*b > S || (2*b == S && (digit & 1) != 0)) { s = BumpUp(s, retval, &k); + } else { + while (*--s == '0') { + /* do nothing */ + } + ++s; } break; } @@ -3330,6 +3335,11 @@ ShorteningBignumConversionPowD( *s++ = '9'; s = BumpUp(s, retval, &k); break; + } else if (mp_iszero(&b)) { + while (*--s == '0') { + /* do nothing */ + } + ++s; } } @@ -3494,6 +3504,10 @@ StrictBignumConversionPowD( if (ShouldBankerRoundUpPowD(&b, sd, digit&1)) { s = BumpUp(s, retval, &k); } + while (*--s == '0') { + /* do nothing */ + } + ++s; break; } @@ -3766,7 +3780,7 @@ ShorteningBignumConversion( --s5; /* - * TODO: It might possibly be a win to fall back to int64 + * IDEA: It might possibly be a win to fall back to int64 * arithmetic here if S < 2**64/10. But it's a win only for * a fairly narrow range of magnitudes so perhaps not worth * bothering. We already know that we shorten the @@ -3966,6 +3980,10 @@ StrictBignumConversion( } } } + while (*--s == '0') { + /* do nothing */ + } + ++s; /* * Endgame - store the location of the decimal point and the end of the @@ -4023,9 +4041,10 @@ StrictBignumConversion( * choosing the one that is closest to the given number (and * resolving ties with 'round to even'). It is allowed to return * fewer than 'ndigits' if the number converts exactly; if the - * TCL_DD_E_FORMAT|TCL_DD_SHORTEN_FLAG is supplied instead, it is - * also allowed to return fewer digits if the shorter string will - * still reconvert to the given input number. + * TCL_DD_E_FORMAT|TCL_DD_SHORTEN_FLAG is supplied instead, it + * also returns fewer digits if the shorter string will still + * reconvert without loss to the given input number. In any case, + * strings of trailing zeroes are suppressed. * TCL_DD_F_FORMAT - This value is used to prepare numbers for %f format * conversion. It requests that conversion proceed until * 'ndigits' digits after the decimal point have been converted. @@ -4035,7 +4054,8 @@ StrictBignumConversion( * number that converts exactly, and changing the argument to * TCL_DD_F_FORMAT|TCL_DD_SHORTEN_FLAG will allow the routine * also to return fewer digits if the shorter string will still - * reconvert without loss to the given input number. + * reconvert without loss to the given input number. Strings of + * trailing zeroes are suppressed. * * To any of these flags may be OR'ed TCL_DD_NO_QUICK; this flag requires * all calculations to be done in exact arithmetic. Normally, E and F |