mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +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
Notes:
sideshowbarker
2024-07-19 07:41:07 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/97de93eed14 Pull-request: https://github.com/SerenityOS/serenity/pull/1757
4 changed files with 17 additions and 12 deletions
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue