mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 16:10:20 +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
Notes:
sideshowbarker
2024-07-18 21:09:58 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7241ff39672
1 changed files with 2 additions and 1 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue