authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-18 17:54:42-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-18 18:05:28-04:00
log558ece8f6f1889bc4773432c16cdf96a54ec1431
tree2db2cbdf0c76cd2a29e1dbb8f2a3efcc2c05d78a
parent33c592e981f93f207651b8353a8cbc3d09440353

slightly nicer floating point printing


1 files changed, 14 insertions(+), 6 deletions(-)

std/fmt/index.zig+14-6
...@@ -243,12 +243,20 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons...@@ -243,12 +243,20 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons
243 return false;243 return false;
244 if (!output(context, "."))244 if (!output(context, "."))
245 return false;245 return false;
246 if (!output(context, float_decimal.digits[1..]))246 if (float_decimal.digits.len > 1) {
247 return false;247 if (!output(context, float_decimal.digits[1 .. math.min(usize(7), float_decimal.digits.len)]))
248 if (!output(context, "e"))248 return false;
249 return false;249 } else {
250 if (!formatInt(float_decimal.exp, 10, false, 0, context, output))250 if (!output(context, "0"))
251 return false;251 return false;
252 }
253
254 if (float_decimal.exp != 1) {
255 if (!output(context, "e"))
256 return false;
257 if (!formatInt(float_decimal.exp, 10, false, 0, context, output))
258 return false;
259 }
252 return true;260 return true;
253}261}
254262