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

Side by Side Diff: src/math.js

Issue 61753011: Slight change to Math.sin approximation. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 var InitTrigonometricFunctions; 213 var InitTrigonometricFunctions;
214 214
215 215
216 // Define constants and interpolation functions. 216 // Define constants and interpolation functions.
217 // Also define the initialization function that populates the lookup table 217 // Also define the initialization function that populates the lookup table
218 // and then wires up the function definitions. 218 // and then wires up the function definitions.
219 function SetupTrigonometricFunctions() { 219 function SetupTrigonometricFunctions() {
220 var samples = 1800; // Table size. 220 var samples = 1800; // Table size.
221 var pi = 3.1415926535897932; 221 var pi = 3.1415926535897932;
222 var pi_half = pi / 2; 222 var pi_half = pi / 2;
223 var inverse_pi_half = 1 / pi_half; 223 var inverse_pi_half = 2 / pi;
224 var two_pi = pi * 2; 224 var two_pi = 2 * pi;
225 var four_pi = 4 * pi;
225 var interval = pi_half / samples; 226 var interval = pi_half / samples;
226 var inverse_interval = samples / pi_half; 227 var inverse_interval = samples / pi_half;
227 var table_sin; 228 var table_sin;
228 var table_cos_interval; 229 var table_cos_interval;
229 230
230 // This implements sine using the following algorithm. 231 // This implements sine using the following algorithm.
231 // 1) Multiplication takes care of to-number conversion. 232 // 1) Multiplication takes care of to-number conversion.
232 // 2) Reduce x to the first quadrant [0, pi/2]. 233 // 2) Reduce x to the first quadrant [0, pi/2].
233 // Conveniently enough, in case of +/-Infinity, we get NaN. 234 // Conveniently enough, in case of +/-Infinity, we get NaN.
234 // 3) Replace x by (pi/2-x) if x was in the 2nd or 4th quadrant. 235 // 3) Replace x by (pi/2-x) if x was in the 2nd or 4th quadrant.
(...skipping 10 matching lines...) Expand all
245 var t2 = 1 - t1; 246 var t2 = 1 - t1;
246 var y1 = table_sin[index]; 247 var y1 = table_sin[index];
247 var y2 = table_sin[index + 1]; 248 var y2 = table_sin[index + 1];
248 var dy = y2 - y1; 249 var dy = y2 - y1;
249 return (t2 * y1 + t1 * y2 + 250 return (t2 * y1 + t1 * y2 +
250 t1 * t2 * ((table_cos_interval[index] - dy) * t2 + 251 t1 * t2 * ((table_cos_interval[index] - dy) * t2 +
251 (dy - table_cos_interval[index + 1]) * t1)); 252 (dy - table_cos_interval[index + 1]) * t1));
252 } 253 }
253 254
254 var MathSinInterpolation = function(x) { 255 var MathSinInterpolation = function(x) {
256 if (x > four_pi) x -= four_pi;
Jakob Kummerow 2013/11/13 16:09:28 I think this needs a comment. Roughly: // Sunspid
255 var multiple = MathFloor(x * inverse_pi_half); 257 var multiple = MathFloor(x * inverse_pi_half);
256 if (%_IsMinusZero(multiple)) return multiple; 258 if (%_IsMinusZero(multiple)) return multiple;
257 x = (multiple & 1) * pi_half + 259 x = (multiple & 1) * pi_half +
258 (1 - ((multiple & 1) << 1)) * (x - multiple * pi_half); 260 (1 - ((multiple & 1) << 1)) * (x - multiple * pi_half);
259 return Interpolation(x) * (1 - (multiple & 2)) + 0; 261 return Interpolation(x) * (1 - (multiple & 2)) + 0;
260 } 262 }
261 263
262 // Cosine is sine with a phase offset of pi/2. 264 // Cosine is sine with a phase offset of pi/2.
263 var MathCosInterpolation = function(x) { 265 var MathCosInterpolation = function(x) {
264 var multiple = MathFloor(x * inverse_pi_half); 266 var multiple = MathFloor(x * inverse_pi_half);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 "min", MathMin, 358 "min", MathMin,
357 "imul", MathImul 359 "imul", MathImul
358 )); 360 ));
359 361
360 %SetInlineBuiltinFlag(MathSin); 362 %SetInlineBuiltinFlag(MathSin);
361 %SetInlineBuiltinFlag(MathCos); 363 %SetInlineBuiltinFlag(MathCos);
362 %SetInlineBuiltinFlag(MathTan); 364 %SetInlineBuiltinFlag(MathTan);
363 } 365 }
364 366
365 SetUpMath(); 367 SetUpMath();
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