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

Unified Diff: src/js/math.js

Issue 1669773002: [math] Fix Math.hypot to properly call ToNumber on all arguments. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/to_number_order.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/math.js
diff --git a/src/js/math.js b/src/js/math.js
index 8a84fdfd69f7ad32cfeaa0f1fb7a758b567fd09d..a698fd4285cac1adbc1396f84deab9ab6d29e97c 100644
--- a/src/js/math.js
+++ b/src/js/math.js
@@ -164,17 +164,14 @@ function MathHypot(x, y) { // Function length is 2.
// We may want to introduce fast paths for two arguments and when
// normalization to avoid overflow is not necessary. For now, we
// simply assume the general case.
- var length = %_ArgumentsLength();
- var args = new InternalArray(length);
+ var length = arguments.length;
var max = 0;
for (var i = 0; i < length; i++) {
- var n = %_Arguments(i);
- n = TO_NUMBER(n);
- if (n === INFINITY || n === -INFINITY) return INFINITY;
- n = MathAbs(n);
+ var n = MathAbs(arguments[i]);
if (n > max) max = n;
- args[i] = n;
+ arguments[i] = n;
}
+ if (max === INFINITY) return INFINITY;
// Kahan summation to avoid rounding errors.
// Normalize the numbers to the largest one to avoid overflow.
@@ -182,7 +179,7 @@ function MathHypot(x, y) { // Function length is 2.
var sum = 0;
var compensation = 0;
for (var i = 0; i < length; i++) {
- var n = args[i] / max;
+ var n = arguments[i] / max;
var summand = n * n - compensation;
var preliminary = sum + summand;
compensation = (preliminary - sum) - summand;
« no previous file with comments | « no previous file | test/mjsunit/to_number_order.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698