From 880f6521d6c42e25f2232c26a97ebc6756bd46f0 Mon Sep 17 00:00:00 2001 From: tofpie <75836434+tofpie@users.noreply.github.com> Date: Sun, 27 Dec 2020 22:14:51 +0100 Subject: [PATCH] Fix comparison with infinity (#1001) Co-authored-by: tofpie --- boa/src/builtins/number/mod.rs | 4 ++-- boa/src/builtins/number/tests.rs | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/boa/src/builtins/number/mod.rs b/boa/src/builtins/number/mod.rs index 3b7c10e31a..4a8ddd1dcf 100644 --- a/boa/src/builtins/number/mod.rs +++ b/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() } diff --git a/boa/src/builtins/number/tests.rs b/boa/src/builtins/number/tests.rs index 24760223fd..cb407b7f9c 100644 --- a/boa/src/builtins/number/tests.rs +++ b/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);