From c189b1d4797847e2e30b7d3c6082eda80b1a2306 Mon Sep 17 00:00:00 2001 From: David Neto <dneto@google.com> Date: Fri, 21 Aug 2020 21:19:33 +0000 Subject: [PATCH] Re-enable float emission tests Test a value that should stably convert to decimal exponent representation. This might be working around a bug in the MSVC runtime library. Bug: tint:201 Change-Id: I37200cef815cafc35284c8c873dfbb8a5312360e Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27160 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org> --- src/writer/hlsl/generator_impl_constructor_test.cc | 7 ++++--- src/writer/msl/generator_impl_constructor_test.cc | 7 ++++--- src/writer/wgsl/generator_impl_constructor_test.cc | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/writer/hlsl/generator_impl_constructor_test.cc b/src/writer/hlsl/generator_impl_constructor_test.cc index 0fed10ec6b..823fa21835 100644 --- a/src/writer/hlsl/generator_impl_constructor_test.cc +++ b/src/writer/hlsl/generator_impl_constructor_test.cc @@ -69,15 +69,16 @@ TEST_F(HlslGeneratorImplTest, EmitConstructor_UInt) { EXPECT_EQ(g.result(), "56779u"); } -TEST_F(HlslGeneratorImplTest, DISABLED_EmitConstructor_Float) { +TEST_F(HlslGeneratorImplTest, EmitConstructor_Float) { ast::type::F32Type f32; - auto lit = std::make_unique<ast::FloatLiteral>(&f32, 1.5e27); + // Use a number close to 1<<30 but whose decimal representation ends in 0. + auto lit = std::make_unique<ast::FloatLiteral>(&f32, float((1 << 30) - 4)); ast::ScalarConstructorExpression expr(std::move(lit)); ast::Module m; GeneratorImpl g(&m); ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error(); - EXPECT_EQ(g.result(), "1.49999995e+27f"); + EXPECT_EQ(g.result(), "1.07374182e+09f"); } TEST_F(HlslGeneratorImplTest, EmitConstructor_Type_Float) { diff --git a/src/writer/msl/generator_impl_constructor_test.cc b/src/writer/msl/generator_impl_constructor_test.cc index bbcd830cc3..13fc4eb194 100644 --- a/src/writer/msl/generator_impl_constructor_test.cc +++ b/src/writer/msl/generator_impl_constructor_test.cc @@ -69,15 +69,16 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) { EXPECT_EQ(g.result(), "56779u"); } -TEST_F(MslGeneratorImplTest, DISABLED_EmitConstructor_Float) { +TEST_F(MslGeneratorImplTest, EmitConstructor_Float) { ast::type::F32Type f32; - auto lit = std::make_unique<ast::FloatLiteral>(&f32, 1.5e27); + // Use a number close to 1<<30 but whose decimal representation ends in 0. + auto lit = std::make_unique<ast::FloatLiteral>(&f32, float((1 << 30) - 4)); ast::ScalarConstructorExpression expr(std::move(lit)); ast::Module m; GeneratorImpl g(&m); ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error(); - EXPECT_EQ(g.result(), "1.49999995e+27f"); + EXPECT_EQ(g.result(), "1.07374182e+09f"); } TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) { diff --git a/src/writer/wgsl/generator_impl_constructor_test.cc b/src/writer/wgsl/generator_impl_constructor_test.cc index c97546b578..9ce40ecc49 100644 --- a/src/writer/wgsl/generator_impl_constructor_test.cc +++ b/src/writer/wgsl/generator_impl_constructor_test.cc @@ -64,14 +64,15 @@ TEST_F(WgslGeneratorImplTest, EmitConstructor_UInt) { EXPECT_EQ(g.result(), "56779u"); } -TEST_F(WgslGeneratorImplTest, DISABLED_EmitConstructor_Float) { +TEST_F(WgslGeneratorImplTest, EmitConstructor_Float) { ast::type::F32Type f32; - auto lit = std::make_unique<ast::FloatLiteral>(&f32, 1.5e27); + // Use a number close to 1<<30 but whose decimal representation ends in 0. + auto lit = std::make_unique<ast::FloatLiteral>(&f32, float((1 << 30) - 4)); ast::ScalarConstructorExpression expr(std::move(lit)); GeneratorImpl g; ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error(); - EXPECT_EQ(g.result(), "1.49999995e+27"); + EXPECT_EQ(g.result(), "1.07374182e+09"); } TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Float) {