Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: src/runtime.cc

Issue 981002: Add a special case in Math.round for a SMI result. Also change the implementa... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 5305 matching lines...) Expand 10 before | Expand all | Expand 10 after
5316 } else { 5316 } else {
5317 return Heap::AllocateHeapNumber(pow(x, y)); 5317 return Heap::AllocateHeapNumber(pow(x, y));
5318 } 5318 }
5319 } 5319 }
5320 5320
5321 5321
5322 static Object* Runtime_Math_round(Arguments args) { 5322 static Object* Runtime_Math_round(Arguments args) {
5323 NoHandleAllocation ha; 5323 NoHandleAllocation ha;
5324 ASSERT(args.length() == 1); 5324 ASSERT(args.length() == 1);
5325 Counters::math_round.Increment(); 5325 Counters::math_round.Increment();
5326 CONVERT_DOUBLE_CHECKED(x, args[0]);
5326 5327
5327 CONVERT_DOUBLE_CHECKED(x, args[0]); 5328 if (x > 0 && x < Smi::kMaxValue) {
5329 return Smi::FromInt(static_cast<int>(x + 0.5));
5330 }
5331
5328 if (signbit(x) && x >= -0.5) return Heap::minus_zero_value(); 5332 if (signbit(x) && x >= -0.5) return Heap::minus_zero_value();
5329 double integer = ceil(x); 5333
5330 if (integer - x > 0.5) { integer -= 1.0; } 5334 // if the magnitude is big enough, there's no place for fraction part. If we
5331 return Heap::NumberFromDouble(integer); 5335 // try to add 0.5 to this number, 1.0 will be added instead.
5336 if (x >= 9007199254740991.0 || x <= -9007199254740991.0) {
5337 return Heap::NumberFromDouble(x);
Erik Corry 2010/03/15 20:11:34 Seems like we could just return args[0] here and a
5338 }
5339
5340 return Heap::NumberFromDouble(floor(x + 0.5));
5332 } 5341 }
5333 5342
5334 5343
5335 static Object* Runtime_Math_sin(Arguments args) { 5344 static Object* Runtime_Math_sin(Arguments args) {
5336 NoHandleAllocation ha; 5345 NoHandleAllocation ha;
5337 ASSERT(args.length() == 1); 5346 ASSERT(args.length() == 1);
5338 Counters::math_sin.Increment(); 5347 Counters::math_sin.Increment();
5339 5348
5340 CONVERT_DOUBLE_CHECKED(x, args[0]); 5349 CONVERT_DOUBLE_CHECKED(x, args[0]);
5341 return TranscendentalCache::Get(TranscendentalCache::SIN, x); 5350 return TranscendentalCache::Get(TranscendentalCache::SIN, x);
(...skipping 3999 matching lines...) Expand 10 before | Expand all | Expand 10 after
9341 } else { 9350 } else {
9342 // Handle last resort GC and make sure to allow future allocations 9351 // Handle last resort GC and make sure to allow future allocations
9343 // to grow the heap without causing GCs (if possible). 9352 // to grow the heap without causing GCs (if possible).
9344 Counters::gc_last_resort_from_js.Increment(); 9353 Counters::gc_last_resort_from_js.Increment();
9345 Heap::CollectAllGarbage(false); 9354 Heap::CollectAllGarbage(false);
9346 } 9355 }
9347 } 9356 }
9348 9357
9349 9358
9350 } } // namespace v8::internal 9359 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698