From 03ff4138e38512df0e6d33aae55a7f9cb83e2949 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 26 Dec 2023 00:07:48 +0100 Subject: feat: pass all float tests Signed-off-by: Henry --- crates/types/src/lib.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'crates/types') diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 12cdbfb..ad82bd4 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -104,13 +104,24 @@ impl WasmValue { } } - pub fn eq_bits(&self, other: &Self) -> bool { + pub fn eq_loose(&self, other: &Self) -> bool { match (self, other) { (Self::I32(a), Self::I32(b)) => a == b, (Self::I64(a), Self::I64(b)) => a == b, - (Self::F32(a), Self::F32(b)) => a.to_bits() == b.to_bits(), - (Self::F64(a), Self::F64(b)) => a.to_bits() == b.to_bits(), - // (Self::V128(a), Self::V128(b)) => a == b, + (Self::F32(a), Self::F32(b)) => { + if a.is_nan() && b.is_nan() { + true // Both are NaN, treat them as equal + } else { + a.to_bits() == b.to_bits() + } + } + (Self::F64(a), Self::F64(b)) => { + if a.is_nan() && b.is_nan() { + true // Both are NaN, treat them as equal + } else { + a.to_bits() == b.to_bits() + } + } _ => false, } } -- cgit v1.3.1