Commit bbc38834 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

Fix DoubleToInteger to never return -0

DoubleToInteger, which corresponds to the ToIntegerOrInfinity AO in
ecma262, never returns -0. Currently there's a bug as std::ceil can
return -0.

Bug: v8:10271
Change-Id: Id5e7d040ef9d186462022dc96052d7920be6ebed
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3869196
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82950}
parent 45c878a6
......@@ -80,12 +80,12 @@ inline float DoubleToFloat32(double x) {
return static_cast<float>(x);
}
// #sec-tointegerorinfinity
inline double DoubleToInteger(double x) {
if (std::isnan(x)) return 0;
if (!std::isfinite(x)) return x;
// ToInteger normalizes -0 to +0.
if (x == 0.0) return 0;
return (x >= 0) ? std::floor(x) : std::ceil(x);
// ToIntegerOrInfinity normalizes -0 to +0, so add 0.0.
return ((x >= 0) ? std::floor(x) : std::ceil(x)) + 0.0;
}
// Implements most of https://tc39.github.io/ecma262/#sec-toint32.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment