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/msl/generator_impl_import_test.cc b/src/writer/msl/generator_impl_import_test.cc
index 9d3b71a..ef5428d 100644
--- a/src/writer/msl/generator_impl_import_test.cc
+++ b/src/writer/msl/generator_impl_import_test.cc
@@ -126,8 +126,8 @@
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
- EXPECT_EQ(gen.result(), std::string("metal::") + param.msl_name +
- "(1.00000000f, 2.00000000f)");
+ EXPECT_EQ(gen.result(),
+ std::string("metal::") + param.msl_name + "(1.0f, 2.0f)");
}
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
MslImportData_DualParamTest,
@@ -175,8 +175,8 @@
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
EXPECT_EQ(gen.result(), std::string("metal::") + param.msl_name +
- "(float3(1.00000000f, 2.00000000f, 3.00000000f), "
- "float3(4.00000000f, 5.00000000f, 6.00000000f))");
+ "(float3(1.0f, 2.0f, 3.0f), "
+ "float3(4.0f, 5.0f, 6.0f))");
}
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
MslImportData_DualParam_VectorTest,
@@ -225,8 +225,8 @@
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
- EXPECT_EQ(gen.result(), std::string("metal::") + param.msl_name +
- "(1.00000000f, 2.00000000f, 3.00000000f)");
+ EXPECT_EQ(gen.result(),
+ std::string("metal::") + param.msl_name + "(1.0f, 2.0f, 3.0f)");
}
INSTANTIATE_TEST_SUITE_P(
MslGeneratorImplTest,