fix(tvix/value): fix display representation of floats

Nix displays a maximum of 5 digits for floating points.

Change-Id: Ifa3c0d96fa0b24e3be8f94dfebc99e602a258355
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6133
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-08-10 20:01:23 +03:00 committed by tazjin
parent ad1c11b606
commit 522d93745c

View file

@ -80,11 +80,17 @@ impl Display for Value {
Value::Bool(true) => f.write_str("true"),
Value::Bool(false) => f.write_str("false"),
Value::Integer(num) => f.write_fmt(format_args!("{}", num)),
Value::Float(num) => f.write_fmt(format_args!("{}", num)),
Value::String(s) => s.fmt(f),
Value::Attrs(attrs) => attrs.fmt(f),
Value::List(list) => list.fmt(f),
// Nix prints floats with a maximum precision of 5 digits
// only.
Value::Float(num) => f.write_fmt(format_args!(
"{}",
format!("{:.5}", num).trim_end_matches(['.', '0'])
)),
// internal types
Value::AttrPath(_) | Value::Blackhole => f.write_str("internal"),
}