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

Side by Side Diff: src/runtime.cc

Issue 149247: Fix issue 397 and issue 399. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 5 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
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 4137 matching lines...) Expand 10 before | Expand all | Expand 10 after
4148 CONVERT_DOUBLE_CHECKED(x, args[0]); 4148 CONVERT_DOUBLE_CHECKED(x, args[0]);
4149 4149
4150 // If the second argument is a smi, it is much faster to call the 4150 // If the second argument is a smi, it is much faster to call the
4151 // custom powi() function than the generic pow(). 4151 // custom powi() function than the generic pow().
4152 if (args[1]->IsSmi()) { 4152 if (args[1]->IsSmi()) {
4153 int y = Smi::cast(args[1])->value(); 4153 int y = Smi::cast(args[1])->value();
4154 return Heap::AllocateHeapNumber(powi(x, y)); 4154 return Heap::AllocateHeapNumber(powi(x, y));
4155 } 4155 }
4156 4156
4157 CONVERT_DOUBLE_CHECKED(y, args[1]); 4157 CONVERT_DOUBLE_CHECKED(y, args[1]);
4158 if (y == 0.5) { 4158
4159 // It's not uncommon to use Math.pow(x, 0.5) to compute the square 4159 if (!isinf(x)) {
4160 // root of a number. To speed up such computations, we explictly 4160 if (y == 0.5) {
4161 // check for this case and use the sqrt() function which is faster 4161 // It's not uncommon to use Math.pow(x, 0.5) to compute the
4162 // than pow(). 4162 // square root of a number. To speed up such computations, we
4163 return Heap::AllocateHeapNumber(sqrt(x)); 4163 // explictly check for this case and use the sqrt() function
4164 } else if (y == -0.5) { 4164 // which is faster than pow().
4165 // Optimized using Math.pow(x, -0.5) == 1 / Math.pow(x, 0.5). 4165 return Heap::AllocateHeapNumber(sqrt(x));
4166 return Heap::AllocateHeapNumber(1.0 / sqrt(x)); 4166 } else if (y == -0.5) {
4167 } else if (y == 0) { 4167 // Optimized using Math.pow(x, -0.5) == 1 / Math.pow(x, 0.5).
4168 return Heap::AllocateHeapNumber(1.0 / sqrt(x));
4169 }
4170 }
4171
4172 if (y == 0) {
4168 return Smi::FromInt(1); 4173 return Smi::FromInt(1);
4169 } else if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) { 4174 } else if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) {
4170 return Heap::nan_value(); 4175 return Heap::nan_value();
4171 } else { 4176 } else {
4172 return Heap::AllocateHeapNumber(pow(x, y)); 4177 return Heap::AllocateHeapNumber(pow(x, y));
4173 } 4178 }
4174 } 4179 }
4175 4180
4176 4181
4177 static Object* Runtime_Math_round(Arguments args) { 4182 static Object* Runtime_Math_round(Arguments args) {
(...skipping 3378 matching lines...) Expand 10 before | Expand all | Expand 10 after
7556 } else { 7561 } else {
7557 // Handle last resort GC and make sure to allow future allocations 7562 // Handle last resort GC and make sure to allow future allocations
7558 // to grow the heap without causing GCs (if possible). 7563 // to grow the heap without causing GCs (if possible).
7559 Counters::gc_last_resort_from_js.Increment(); 7564 Counters::gc_last_resort_from_js.Increment();
7560 Heap::CollectAllGarbage(); 7565 Heap::CollectAllGarbage();
7561 } 7566 }
7562 } 7567 }
7563 7568
7564 7569
7565 } } // namespace v8::internal 7570 } } // namespace v8::internal
OLDNEW
« src/date-delay.js ('K') | « src/date-delay.js ('k') | test/mjsunit/regress/regress-397.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698