Skip to content

Commit

Permalink
Fix PartialEq for JsBigInt and f64 (#2461)
Browse files Browse the repository at this point in the history
This Pull Request changes the following:

- Use the `BigInt::from_f64` function when checking `JsBigInt` and `f64` for eqality.
  • Loading branch information
raskad committed Nov 25, 2022
1 parent 8c88281 commit 7971d4c
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions boa_engine/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,21 +453,15 @@ impl PartialEq<JsBigInt> for i32 {
impl PartialEq<f64> for JsBigInt {
#[inline]
fn eq(&self, other: &f64) -> bool {
if other.fract() != 0.0 {
return false;
}

self.inner.as_ref() == &RawBigInt::from(*other as i64)
other.fract().is_zero()
&& RawBigInt::from_f64(*other).map_or(false, |bigint| self.inner.as_ref() == &bigint)
}
}

impl PartialEq<JsBigInt> for f64 {
#[inline]
fn eq(&self, other: &JsBigInt) -> bool {
if self.fract() != 0.0 {
return false;
}

&RawBigInt::from(*self as i64) == other.inner.as_ref()
self.fract().is_zero()
&& RawBigInt::from_f64(*self).map_or(false, |bigint| other.inner.as_ref() == &bigint)
}
}

0 comments on commit 7971d4c

Please sign in to comment.