Browse Source

Fix comparison with infinity (#1001)

Co-authored-by: tofpie <tofpie@users.noreply.github.com>
pull/1002/head
tofpie 4 years ago committed by GitHub
parent
commit
880f6521d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      boa/src/builtins/number/mod.rs
  2. 30
      boa/src/builtins/number/tests.rs

4
boa/src/builtins/number/mod.rs

@ -973,10 +973,10 @@ impl Number {
return AbstractRelation::True;
}
if x.is_infinite() && x.is_sign_negative() {
return AbstractRelation::False;
return AbstractRelation::True;
}
if y.is_infinite() && y.is_sign_negative() {
return AbstractRelation::True;
return AbstractRelation::False;
}
(x < y).into()
}

30
boa/src/builtins/number/tests.rs

@ -1,6 +1,6 @@
#![allow(clippy::float_cmp)]
use crate::{builtins::Number, forward, forward_val, Context};
use crate::{builtins::Number, forward, forward_val, value::AbstractRelation, Context};
#[test]
fn integer_number_primitive_to_number_object() {
@ -444,6 +444,34 @@ fn same_value() {
assert_eq!(Number::equal(1.0, 1.0), true);
}
#[test]
fn less_than() {
assert_eq!(
Number::less_than(f64::NAN, 0.0),
AbstractRelation::Undefined
);
assert_eq!(
Number::less_than(0.0, f64::NAN),
AbstractRelation::Undefined
);
assert_eq!(
Number::less_than(f64::NEG_INFINITY, 0.0),
AbstractRelation::True
);
assert_eq!(
Number::less_than(0.0, f64::NEG_INFINITY),
AbstractRelation::False
);
assert_eq!(
Number::less_than(f64::INFINITY, 0.0),
AbstractRelation::False
);
assert_eq!(
Number::less_than(0.0, f64::INFINITY),
AbstractRelation::True
);
}
#[test]
fn same_value_zero() {
assert_eq!(Number::same_value_zero(0.0, 0.0), true);

Loading…
Cancel
Save