mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:57:34 +00:00
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:
parent
9b68f91c0b
commit
7241ff3967
1 changed files with 2 additions and 1 deletions
|
@ -109,7 +109,8 @@ public:
|
||||||
|
|
||||||
explicit Value(double value)
|
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_type = Type::Int32;
|
||||||
m_value.as_i32 = static_cast<i32>(value);
|
m_value.as_i32 = static_cast<i32>(value);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue