diff options
| author | Henry <mail@henrygressmann.de> | 2023-12-26 00:07:48 +0100 |
|---|---|---|
| committer | Henry <mail@henrygressmann.de> | 2023-12-26 00:07:48 +0100 |
| commit | 03ff4138e38512df0e6d33aae55a7f9cb83e2949 (patch) | |
| tree | dd489bef080847b81223deddb52062029eedc531 /crates/types | |
| parent | 9ea2796e334cfd1343fef76458b2d9de50fb35f1 (diff) | |
feat: pass all float tests
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/types')
| -rw-r--r-- | crates/types/src/lib.rs | 19 |
1 files changed, 15 insertions, 4 deletions
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, } } |
