Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix CompareOpFloat NaN handling
partial_cmp returns None for NaN comparisons. is_some_and incorrectly
returned false for all NaN comparisons, but NaN != x should be true
per IEEE 754 semantics.
  • Loading branch information
youknowone committed Mar 4, 2026
commit 5c81306fa4b11ef634ce63d80029a92fcd769b82
10 changes: 6 additions & 4 deletions crates/vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4584,10 +4584,12 @@ impl ExecutingFrame<'_> {
b.downcast_ref_if_exact::<PyFloat>(vm),
) {
let op = self.compare_op_from_arg(arg);
let result = a_f
.to_f64()
.partial_cmp(&b_f.to_f64())
.is_some_and(|ord| op.eval_ord(ord));
let (a, b) = (a_f.to_f64(), b_f.to_f64());
// Use Rust's IEEE 754 float comparison which handles NaN correctly
let result = match a.partial_cmp(&b) {
Some(ord) => op.eval_ord(ord),
None => op == PyComparisonOp::Ne, // NaN != anything is true
};
self.pop_value();
self.pop_value();
self.push_value(vm.ctx.new_bool(result).into());
Expand Down