Revert r4146. Add a special case in Math.round for a SMI result. Also change the imp...
TBR=ager@chromium.org, Review URL: http://codereview.chromium.org/1042006 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4156 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
3ca9367341
commit
38d6470fca
@ -5325,21 +5325,12 @@ static Object* Runtime_Math_round(Arguments args) {
|
|||||||
NoHandleAllocation ha;
|
NoHandleAllocation ha;
|
||||||
ASSERT(args.length() == 1);
|
ASSERT(args.length() == 1);
|
||||||
Counters::math_round.Increment();
|
Counters::math_round.Increment();
|
||||||
|
|
||||||
CONVERT_DOUBLE_CHECKED(x, args[0]);
|
CONVERT_DOUBLE_CHECKED(x, args[0]);
|
||||||
|
|
||||||
if (x > 0 && x < Smi::kMaxValue) {
|
|
||||||
return Smi::FromInt(static_cast<int>(x + 0.5));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signbit(x) && x >= -0.5) return Heap::minus_zero_value();
|
if (signbit(x) && x >= -0.5) return Heap::minus_zero_value();
|
||||||
|
double integer = ceil(x);
|
||||||
// if the magnitude is big enough, there's no place for fraction part. If we
|
if (integer - x > 0.5) { integer -= 1.0; }
|
||||||
// try to add 0.5 to this number, 1.0 will be added instead.
|
return Heap::NumberFromDouble(integer);
|
||||||
if (x >= 9007199254740991.0 || x <= -9007199254740991.0) {
|
|
||||||
return args[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return Heap::NumberFromDouble(floor(x + 0.5));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user