diff --git a/Libraries/LibJS/Runtime/MathObject.cpp b/Libraries/LibJS/Runtime/MathObject.cpp index aa49dc5ab0..d26f3b9a22 100644 --- a/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Libraries/LibJS/Runtime/MathObject.cpp @@ -114,18 +114,18 @@ Value MathObject::round(Interpreter& interpreter) Value MathObject::max(Interpreter& interpreter) { - if (!interpreter.argument_count()) { - return Value(-js_infinity().as_double()); - } else if (interpreter.argument_count() == 1) { + if (!interpreter.argument_count()) + return js_negative_infinity(); + + if (interpreter.argument_count() == 1) return interpreter.argument(0).to_number(); - } else { - Value max = interpreter.argument(0).to_number(); - for (size_t i = 1; i < interpreter.argument_count(); ++i) { - Value cur = interpreter.argument(i).to_number(); - max = Value(cur.as_double() > max.as_double() ? cur : max); - } - return max; + + Value max = interpreter.argument(0).to_number(); + for (size_t i = 1; i < interpreter.argument_count(); ++i) { + Value cur = interpreter.argument(i).to_number(); + max = Value(cur.as_double() > max.as_double() ? cur : max); } + return max; } Value MathObject::min(Interpreter& interpreter) diff --git a/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Libraries/LibJS/Runtime/NumberConstructor.cpp index aeb0282514..817a4858b0 100644 --- a/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -45,7 +45,7 @@ NumberConstructor::NumberConstructor() put("EPSILON", Value(EPSILON)); put("MAX_SAFE_INTEGER", Value(MAX_SAFE_INTEGER)); put("MIN_SAFE_INTEGER", Value(MIN_SAFE_INTEGER)); - put("NEGATIVE_INFINITY", Value(-js_infinity().as_double())); + put("NEGATIVE_INFINITY", js_negative_infinity()); put("POSITIVE_INFINITY", js_infinity()); put("NaN", js_nan()); } diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index fbfd214852..1bf14b245b 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -143,7 +143,7 @@ Value Value::to_number() const if (string == "Infinity" || string == "+Infinity") return js_infinity(); if (string == "-Infinity") - return Value(-js_infinity().as_double()); + return js_negative_infinity(); bool ok; //FIXME: Parse in a better way auto parsed_int = string.to_int(ok); diff --git a/Libraries/LibJS/Runtime/Value.h b/Libraries/LibJS/Runtime/Value.h index 7a5820e6b0..79ce3bbfc8 100644 --- a/Libraries/LibJS/Runtime/Value.h +++ b/Libraries/LibJS/Runtime/Value.h @@ -182,6 +182,11 @@ inline Value js_infinity() return Value(__builtin_huge_val()); } +inline Value js_negative_infinity() +{ + return Value(-__builtin_huge_val()); +} + Value greater_than(Value lhs, Value rhs); Value greater_than_equals(Value lhs, Value rhs); Value less_than(Value lhs, Value rhs);