mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:47:34 +00:00
LibJS: Add js_negative_infinity()
Value(-js_infinity().as_double()) is kind of awkward.
This commit is contained in:
parent
f226746394
commit
97de93eed1
4 changed files with 17 additions and 12 deletions
|
@ -114,18 +114,18 @@ Value MathObject::round(Interpreter& interpreter)
|
||||||
|
|
||||||
Value MathObject::max(Interpreter& interpreter)
|
Value MathObject::max(Interpreter& interpreter)
|
||||||
{
|
{
|
||||||
if (!interpreter.argument_count()) {
|
if (!interpreter.argument_count())
|
||||||
return Value(-js_infinity().as_double());
|
return js_negative_infinity();
|
||||||
} else if (interpreter.argument_count() == 1) {
|
|
||||||
|
if (interpreter.argument_count() == 1)
|
||||||
return interpreter.argument(0).to_number();
|
return interpreter.argument(0).to_number();
|
||||||
} else {
|
|
||||||
Value max = interpreter.argument(0).to_number();
|
Value max = interpreter.argument(0).to_number();
|
||||||
for (size_t i = 1; i < interpreter.argument_count(); ++i) {
|
for (size_t i = 1; i < interpreter.argument_count(); ++i) {
|
||||||
Value cur = interpreter.argument(i).to_number();
|
Value cur = interpreter.argument(i).to_number();
|
||||||
max = Value(cur.as_double() > max.as_double() ? cur : max);
|
max = Value(cur.as_double() > max.as_double() ? cur : max);
|
||||||
}
|
|
||||||
return max;
|
|
||||||
}
|
}
|
||||||
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value MathObject::min(Interpreter& interpreter)
|
Value MathObject::min(Interpreter& interpreter)
|
||||||
|
|
|
@ -45,7 +45,7 @@ NumberConstructor::NumberConstructor()
|
||||||
put("EPSILON", Value(EPSILON));
|
put("EPSILON", Value(EPSILON));
|
||||||
put("MAX_SAFE_INTEGER", Value(MAX_SAFE_INTEGER));
|
put("MAX_SAFE_INTEGER", Value(MAX_SAFE_INTEGER));
|
||||||
put("MIN_SAFE_INTEGER", Value(MIN_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("POSITIVE_INFINITY", js_infinity());
|
||||||
put("NaN", js_nan());
|
put("NaN", js_nan());
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ Value Value::to_number() const
|
||||||
if (string == "Infinity" || string == "+Infinity")
|
if (string == "Infinity" || string == "+Infinity")
|
||||||
return js_infinity();
|
return js_infinity();
|
||||||
if (string == "-Infinity")
|
if (string == "-Infinity")
|
||||||
return Value(-js_infinity().as_double());
|
return js_negative_infinity();
|
||||||
bool ok;
|
bool ok;
|
||||||
//FIXME: Parse in a better way
|
//FIXME: Parse in a better way
|
||||||
auto parsed_int = string.to_int(ok);
|
auto parsed_int = string.to_int(ok);
|
||||||
|
|
|
@ -182,6 +182,11 @@ inline Value js_infinity()
|
||||||
return Value(__builtin_huge_val());
|
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(Value lhs, Value rhs);
|
||||||
Value greater_than_equals(Value lhs, Value rhs);
|
Value greater_than_equals(Value lhs, Value rhs);
|
||||||
Value less_than(Value lhs, Value rhs);
|
Value less_than(Value lhs, Value rhs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue