Browse Source

Fix `PartialEq` for `JsBigInt` and `f64` (#2461)

This Pull Request changes the following:

- Use the `BigInt::from_f64` function when checking `JsBigInt` and `f64` for eqality.
pull/2464/head
raskad 2 years ago
parent
commit
7971d4c197
  1. 14
      boa_engine/src/bigint.rs

14
boa_engine/src/bigint.rs

@ -453,21 +453,15 @@ impl PartialEq<JsBigInt> for i32 {
impl PartialEq<f64> for JsBigInt { impl PartialEq<f64> for JsBigInt {
#[inline] #[inline]
fn eq(&self, other: &f64) -> bool { fn eq(&self, other: &f64) -> bool {
if other.fract() != 0.0 { other.fract().is_zero()
return false; && RawBigInt::from_f64(*other).map_or(false, |bigint| self.inner.as_ref() == &bigint)
}
self.inner.as_ref() == &RawBigInt::from(*other as i64)
} }
} }
impl PartialEq<JsBigInt> for f64 { impl PartialEq<JsBigInt> for f64 {
#[inline] #[inline]
fn eq(&self, other: &JsBigInt) -> bool { fn eq(&self, other: &JsBigInt) -> bool {
if self.fract() != 0.0 { self.fract().is_zero()
return false; && RawBigInt::from_f64(*self).map_or(false, |bigint| other.inner.as_ref() == &bigint)
}
&RawBigInt::from(*self as i64) == other.inner.as_ref()
} }
} }

Loading…
Cancel
Save