@@ -177,22 +177,16 @@ Result<Literal> Literal::CastTo(const std::shared_ptr<PrimitiveType>& target_typ
177177template <std::floating_point T>
178178std::strong_ordering CompareFloat (T lhs, T rhs) {
179179 // If both are NaN, check their signs
180- bool lhs_is_nan = std::isnan (lhs);
181- bool rhs_is_nan = std::isnan (rhs);
182- if (lhs_is_nan && rhs_is_nan) {
183- bool lhs_is_negative = std::signbit (lhs);
184- bool rhs_is_negative = std::signbit (rhs);
185-
186- if (lhs_is_negative == rhs_is_negative) {
187- // Same sign NaN values are equivalent (no qNaN vs sNaN distinction)
188- return std::strong_ordering::equivalent;
189- }
190- // -NaN < NaN
191- return lhs_is_negative ? std::strong_ordering::less : std::strong_ordering::greater;
180+ bool all_nan = std::isnan (lhs) && std::isnan (rhs);
181+ if (!all_nan) {
182+ // If not both NaN, use strong ordering
183+ return std::strong_order (lhs, rhs);
192184 }
193-
194- // For non-NaN values, use standard strong ordering
195- return std::strong_order (lhs, rhs);
185+ // Same sign NaN values are equivalent (no qNaN vs sNaN distinction),
186+ // and -NAN < NAN.
187+ bool lhs_is_negative = std::signbit (lhs);
188+ bool rhs_is_negative = std::signbit (rhs);
189+ return lhs_is_negative <=> rhs_is_negative;
196190}
197191
198192// Three-way comparison operator
0 commit comments