mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 10:37:34 +00:00
LibJS: Correctly handle mixing +0 and -0 in Math.{min,max}()
The native C++ < and > operators won't handle this correctly, so the result was different depending on the order of arguments. This is now fixed by explicitly checking for positive and negative zero values. Fixes #6589.
This commit is contained in:
parent
883e8683b2
commit
0053816e9d
3 changed files with 8 additions and 2 deletions
|
@ -157,7 +157,8 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::max)
|
|||
auto cur = vm.argument(i).to_number(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
max = Value(cur.as_double() > max.as_double() ? cur : max);
|
||||
if ((max.is_negative_zero() && cur.is_positive_zero()) || cur.as_double() > max.as_double())
|
||||
max = cur;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
@ -174,7 +175,8 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::min)
|
|||
auto cur = vm.argument(i).to_number(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
min = Value(cur.as_double() < min.as_double() ? cur : min);
|
||||
if ((min.is_positive_zero() && cur.is_negative_zero()) || cur.as_double() < min.as_double())
|
||||
min = cur;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue