LibJS: *Actually* check for negative zero in JS::Value(double)

As @nico pointed out, 0.0 == -0.0 in C++, even though they are not
bitwise identical. Use the same trick as Value::is_negative_zero() to
really check for it.

This allows JS::Value(0.0) to correctly become an Int32-backed 0 value.
This commit is contained in:
Andreas Kling 2021-03-22 07:49:08 +01:00
parent 9b68f91c0b
commit 7241ff3967
Notes: sideshowbarker 2024-07-18 21:09:58 +09:00

View file

@ -109,7 +109,8 @@ public:
explicit Value(double value)
{
if (value >= NumericLimits<i32>::min() && value <= NumericLimits<i32>::max() && trunc(value) == value && value != -0.0) {
bool is_negative_zero = value == 0.0 && (1.0 / value == -INFINITY);
if (value >= NumericLimits<i32>::min() && value <= NumericLimits<i32>::max() && trunc(value) == value && !is_negative_zero) {
m_type = Type::Int32;
m_value.as_i32 = static_cast<i32>(value);
} else {