writer: Simplify floats when printed
Add `tint::writer::FloatToString()`:
Converts the float `f` to a string using fixed-point notation (not scientific).
The float will be printed with the full precision required to describe the float.
All trailing `0`s will be omitted after the last non-zero fractional number,
unless the fractional is zero, in which case the number will end with `.0`.
Use this for the wgsl, msl and hlsl backends.
Change-Id: If5701136579e4398c31c673942f30e8877e9f813
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33421
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/writer/hlsl/generator_impl_member_accessor_test.cc b/src/writer/hlsl/generator_impl_member_accessor_test.cc
index e7e1330..5c15ab6 100644
--- a/src/writer/hlsl/generator_impl_member_accessor_test.cc
+++ b/src/writer/hlsl/generator_impl_member_accessor_test.cc
@@ -619,7 +619,7 @@
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
- EXPECT_EQ(result(), R"(data.Store(4, asuint(2.00000000f));
+ EXPECT_EQ(result(), R"(data.Store(4, asuint(2.0f));
)");
}
@@ -826,9 +826,8 @@
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
- EXPECT_EQ(
- result(),
- R"(data.Store3(16, asuint(float3(1.00000000f, 2.00000000f, 3.00000000f)));
+ EXPECT_EQ(result(),
+ R"(data.Store3(16, asuint(float3(1.0f, 2.0f, 3.0f)));
)");
}
@@ -1194,9 +1193,8 @@
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
- EXPECT_EQ(
- result(),
- R"(data.Store3(16 + (32 * 2) + 0, asuint(float3(1.00000000f, 2.00000000f, 3.00000000f)));
+ EXPECT_EQ(result(),
+ R"(data.Store3(16 + (32 * 2) + 0, asuint(float3(1.0f, 2.0f, 3.0f)));
)");
}
@@ -1273,7 +1271,7 @@
ASSERT_TRUE(td.DetermineResultType(&assign));
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
EXPECT_EQ(result(),
- R"(data.Store((4 * 1) + 16 + (32 * 2) + 0, asuint(1.00000000f));
+ R"(data.Store((4 * 1) + 16 + (32 * 2) + 0, asuint(1.0f));
)");
}