Commit df8b359f authored by danno@chromium.org's avatar danno@chromium.org

Fix handling of -0.0 in IsInt32/IsUInt32

R=ager@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/9169009

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10361 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 842d8b91
// Copyright 2011 the V8 project authors. All rights reserved.
// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
......@@ -2165,6 +2165,11 @@ bool Value::IsInt32() const {
if (obj->IsSmi()) return true;
if (obj->IsNumber()) {
double value = obj->Number();
static const i::DoubleRepresentation minus_zero(-0.0);
i::DoubleRepresentation rep(value);
if (rep.bits == minus_zero.bits) {
return false;
}
return i::FastI2D(i::FastD2I(value)) == value;
}
return false;
......@@ -2177,6 +2182,11 @@ bool Value::IsUint32() const {
if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0;
if (obj->IsNumber()) {
double value = obj->Number();
static const i::DoubleRepresentation minus_zero(-0.0);
i::DoubleRepresentation rep(value);
if (rep.bits == minus_zero.bits) {
return false;
}
return i::FastUI2D(i::FastD2UI(value)) == value;
}
return false;
......
// Copyright 2011 the V8 project authors. All rights reserved.
// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
......@@ -2867,6 +2867,16 @@ THREADED_TEST(isNumberType) {
obj = env->Global()->Get(v8_str("obj"));
CHECK(!obj->IsInt32());
CHECK(!obj->IsUint32());
// Positive zero
CompileRun("var obj = 0.0;");
obj = env->Global()->Get(v8_str("obj"));
CHECK(obj->IsInt32());
CHECK(obj->IsUint32());
// Positive zero
CompileRun("var obj = -0.0;");
obj = env->Global()->Get(v8_str("obj"));
CHECK(!obj->IsInt32());
CHECK(!obj->IsUint32());
}
......
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