// Round appropriately.
// Negative precision means "only as much as needed to be exact."
+ shortest := false;
if prec < 0 {
+ shortest = true;
RoundShortest(d, mant, exp, flt);
switch fmt {
case 'e':
}
// %e is used if the exponent from the conversion
// is less than -4 or greater than or equal to the precision.
+ // if precision was the shortest possible, use precision 6 for this decision.
+ eprec := prec;
+ if shortest {
+ eprec = 6
+ }
exp := d.dp - 1;
- if exp < -4 || exp >= prec {
+ if exp < -4 || exp >= eprec {
return FmtE(neg, d, prec - 1);
}
return FmtF(neg, d, Max(prec - d.dp, 0));
Test{ 1, 'f', 5, "1.00000" },
Test{ 1, 'g', 5, "1" },
Test{ 1, 'g', -1, "1" },
+ Test{ 20, 'g', -1, "20" },
+ Test{ 200000, 'g', -1, "200000" },
+ Test{ 2000000, 'g', -1, "2e+06" },
Test{ 0, 'e', 5, "0.00000e+00" },
Test{ 0, 'f', 5, "0.00000" },