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

Side by Side Diff: src/runtime.cc

Issue 1042006: Revert r4146. Add a special case in Math.round for a SMI result. Also change ... (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 5307 matching lines...) Expand 10 before | Expand all | Expand 10 after
5318 } else { 5318 } else {
5319 return Heap::AllocateHeapNumber(pow(x, y)); 5319 return Heap::AllocateHeapNumber(pow(x, y));
5320 } 5320 }
5321 } 5321 }
5322 5322
5323 5323
5324 static Object* Runtime_Math_round(Arguments args) { 5324 static Object* Runtime_Math_round(Arguments args) {
5325 NoHandleAllocation ha; 5325 NoHandleAllocation ha;
5326 ASSERT(args.length() == 1); 5326 ASSERT(args.length() == 1);
5327 Counters::math_round.Increment(); 5327 Counters::math_round.Increment();
5328
5328 CONVERT_DOUBLE_CHECKED(x, args[0]); 5329 CONVERT_DOUBLE_CHECKED(x, args[0]);
5329
5330 if (x > 0 && x < Smi::kMaxValue) {
5331 return Smi::FromInt(static_cast<int>(x + 0.5));
5332 }
5333
5334 if (signbit(x) && x >= -0.5) return Heap::minus_zero_value(); 5330 if (signbit(x) && x >= -0.5) return Heap::minus_zero_value();
5335 5331 double integer = ceil(x);
5336 // if the magnitude is big enough, there's no place for fraction part. If we 5332 if (integer - x > 0.5) { integer -= 1.0; }
5337 // try to add 0.5 to this number, 1.0 will be added instead. 5333 return Heap::NumberFromDouble(integer);
5338 if (x >= 9007199254740991.0 || x <= -9007199254740991.0) {
5339 return args[0];
5340 }
5341
5342 return Heap::NumberFromDouble(floor(x + 0.5));
5343 } 5334 }
5344 5335
5345 5336
5346 static Object* Runtime_Math_sin(Arguments args) { 5337 static Object* Runtime_Math_sin(Arguments args) {
5347 NoHandleAllocation ha; 5338 NoHandleAllocation ha;
5348 ASSERT(args.length() == 1); 5339 ASSERT(args.length() == 1);
5349 Counters::math_sin.Increment(); 5340 Counters::math_sin.Increment();
5350 5341
5351 CONVERT_DOUBLE_CHECKED(x, args[0]); 5342 CONVERT_DOUBLE_CHECKED(x, args[0]);
5352 return TranscendentalCache::Get(TranscendentalCache::SIN, x); 5343 return TranscendentalCache::Get(TranscendentalCache::SIN, x);
(...skipping 4029 matching lines...) Expand 10 before | Expand all | Expand 10 after
9382 } else { 9373 } else {
9383 // Handle last resort GC and make sure to allow future allocations 9374 // Handle last resort GC and make sure to allow future allocations
9384 // to grow the heap without causing GCs (if possible). 9375 // to grow the heap without causing GCs (if possible).
9385 Counters::gc_last_resort_from_js.Increment(); 9376 Counters::gc_last_resort_from_js.Increment();
9386 Heap::CollectAllGarbage(false); 9377 Heap::CollectAllGarbage(false);
9387 } 9378 }
9388 } 9379 }
9389 9380
9390 9381
9391 } } // namespace v8::internal 9382 } } // 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