diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 1cf74807d1..ccce06a89a 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -2183,13 +2183,14 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression* return true; }, [&](const ast::FloatLiteralExpression* l) { - if (std::isinf(l->value)) { + auto f32 = static_cast(l->value); + if (std::isinf(f32)) { out << (l->value >= 0 ? "uintBitsToFloat(0x7f800000u)" : "uintBitsToFloat(0xff800000u)"); } else if (std::isnan(l->value)) { out << "uintBitsToFloat(0x7fc00000u)"; } else { - out << FloatToString(static_cast(l->value)) << "f"; + out << FloatToString(f32) << "f"; } return true; }, diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc index 344d0d87c8..d6a5fa7549 100644 --- a/src/tint/writer/hlsl/generator_impl.cc +++ b/src/tint/writer/hlsl/generator_impl.cc @@ -3139,13 +3139,14 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression* out << (l->value ? "true" : "false"); return true; }, - [&](const ast::FloatLiteralExpression* fl) { - if (std::isinf(fl->value)) { - out << (fl->value >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)"); - } else if (std::isnan(fl->value)) { + [&](const ast::FloatLiteralExpression* l) { + auto f32 = static_cast(l->value); + if (std::isinf(f32)) { + out << (f32 >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)"); + } else if (std::isnan(f32)) { out << "asfloat(0x7fc00000u)"; } else { - out << FloatToString(static_cast(fl->value)) << "f"; + out << FloatToString(f32) << "f"; } return true; }, diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc index be94e2c9fe..54d9164823 100644 --- a/src/tint/writer/msl/generator_impl.cc +++ b/src/tint/writer/msl/generator_impl.cc @@ -1544,12 +1544,13 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression* return true; }, [&](const ast::FloatLiteralExpression* l) { - if (std::isinf(l->value)) { - out << (l->value >= 0 ? "INFINITY" : "-INFINITY"); - } else if (std::isnan(l->value)) { + auto f32 = static_cast(l->value); + if (std::isinf(f32)) { + out << (f32 >= 0 ? "INFINITY" : "-INFINITY"); + } else if (std::isnan(f32)) { out << "NAN"; } else { - out << FloatToString(static_cast(l->value)) << "f"; + out << FloatToString(f32) << "f"; } return true; },