diff options
author | kennykb <kennykb@noemail.net> | 2011-01-15 18:10:17 (GMT) |
---|---|---|
committer | kennykb <kennykb@noemail.net> | 2011-01-15 18:10:17 (GMT) |
commit | 73660cee196e056b9333df8e53148c994b177119 (patch) | |
tree | 51b622116570a04f374cceb905e6453578b77cae /generic/tclStrToD.c | |
parent | 004ac6c705c82fe82cbd3a85bed65921fc30fb6a (diff) | |
download | tcl-73660cee196e056b9333df8e53148c994b177119.zip tcl-73660cee196e056b9333df8e53148c994b177119.tar.gz tcl-73660cee196e056b9333df8e53148c994b177119.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]
FossilOrigin-Name: 32e80e56c745fe97b07be37f3622dca2d5480ac6
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 |