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(&f32, 1.5e27); + // Use a number close to 1<<30 but whose decimal representation ends in 0. + auto lit = std::make_unique(&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(&f32, 1.5e27); + // Use a number close to 1<<30 but whose decimal representation ends in 0. + auto lit = std::make_unique(&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(&f32, 1.5e27); + // Use a number close to 1<<30 but whose decimal representation ends in 0. + auto lit = std::make_unique(&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) {