mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:07:34 +00:00
LibJS: Improve correctness of rounding and bitwise operations
Patch from Anonymous
This commit is contained in:
parent
6622ad8895
commit
16a0e7a66d
9 changed files with 106 additions and 19 deletions
|
@ -154,7 +154,16 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::round)
|
|||
return {};
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
return Value(::round(number.as_double()));
|
||||
double intpart = 0;
|
||||
double frac = modf(number.as_double(), &intpart);
|
||||
if (intpart >= 0) {
|
||||
if (frac >= 0.5)
|
||||
intpart += 1.0;
|
||||
} else {
|
||||
if (frac < -0.5)
|
||||
intpart -= 1.0;
|
||||
}
|
||||
return Value(intpart);
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::max)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue