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

Side by Side Diff: src/runtime.cc

Issue 567011: Fix a bug that Math.round() returns incorrect results for huge integers. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 10 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 | test/mjsunit/math-round.js » ('j') | 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 4644 matching lines...) Expand 10 before | Expand all | Expand 10 after
4655 } 4655 }
4656 } 4656 }
4657 4657
4658 4658
4659 static Object* Runtime_Math_round(Arguments args) { 4659 static Object* Runtime_Math_round(Arguments args) {
4660 NoHandleAllocation ha; 4660 NoHandleAllocation ha;
4661 ASSERT(args.length() == 1); 4661 ASSERT(args.length() == 1);
4662 4662
4663 CONVERT_DOUBLE_CHECKED(x, args[0]); 4663 CONVERT_DOUBLE_CHECKED(x, args[0]);
4664 if (signbit(x) && x >= -0.5) return Heap::minus_zero_value(); 4664 if (signbit(x) && x >= -0.5) return Heap::minus_zero_value();
4665 return Heap::NumberFromDouble(floor(x + 0.5)); 4665 double integer = ceil(x);
4666 return Heap::NumberFromDouble(integer - x > 0.5 ? integer - 1.0 : integer);
4666 } 4667 }
4667 4668
4668 4669
4669 static Object* Runtime_Math_sin(Arguments args) { 4670 static Object* Runtime_Math_sin(Arguments args) {
4670 NoHandleAllocation ha; 4671 NoHandleAllocation ha;
4671 ASSERT(args.length() == 1); 4672 ASSERT(args.length() == 1);
4672 4673
4673 CONVERT_DOUBLE_CHECKED(x, args[0]); 4674 CONVERT_DOUBLE_CHECKED(x, args[0]);
4674 return TranscendentalCache::Get(TranscendentalCache::SIN, x); 4675 return TranscendentalCache::Get(TranscendentalCache::SIN, x);
4675 } 4676 }
(...skipping 3490 matching lines...) Expand 10 before | Expand all | Expand 10 after
8166 } else { 8167 } else {
8167 // Handle last resort GC and make sure to allow future allocations 8168 // Handle last resort GC and make sure to allow future allocations
8168 // to grow the heap without causing GCs (if possible). 8169 // to grow the heap without causing GCs (if possible).
8169 Counters::gc_last_resort_from_js.Increment(); 8170 Counters::gc_last_resort_from_js.Increment();
8170 Heap::CollectAllGarbage(false); 8171 Heap::CollectAllGarbage(false);
8171 } 8172 }
8172 } 8173 }
8173 8174
8174 8175
8175 } } // namespace v8::internal 8176 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/math-round.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698