mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 00:17:03 +00:00
writer/hlsl: Special case negative zero
Fixed: tint:960 Change-Id: I060bc6b7a9ad4d21dd5cadb4b68998c7e54ebaed Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57142 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Auto-Submit: Ben Clayton <bclayton@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
ea1a4680d4
commit
26b6edc545
@@ -2475,13 +2475,20 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, ast::Literal* lit) {
|
||||
if (auto* l = lit->As<ast::BoolLiteral>()) {
|
||||
out << (l->IsTrue() ? "true" : "false");
|
||||
} else if (auto* fl = lit->As<ast::FloatLiteral>()) {
|
||||
if (std::isinf(fl->value())) {
|
||||
out << (fl->value() >= 0 ? "asfloat(0x7f800000u)"
|
||||
: "asfloat(0xff800000u)");
|
||||
} else if (std::isnan(fl->value())) {
|
||||
out << "asfloat(0x7fc00000u)";
|
||||
} else {
|
||||
out << FloatToString(fl->value()) << "f";
|
||||
bool positive = std::signbit(fl->value()) == 0;
|
||||
switch (std::fpclassify(fl->value())) {
|
||||
case FP_INFINITE:
|
||||
out << (positive ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)");
|
||||
break;
|
||||
case FP_NAN:
|
||||
out << "asfloat(0x7fc00000u)";
|
||||
break;
|
||||
case FP_ZERO:
|
||||
out << (positive ? "0.0f" : "asfloat(0xff800000u)");
|
||||
break;
|
||||
default:
|
||||
out << FloatToString(fl->value()) << "f";
|
||||
break;
|
||||
}
|
||||
} else if (auto* sl = lit->As<ast::SintLiteral>()) {
|
||||
out << sl->value();
|
||||
|
||||
Reference in New Issue
Block a user