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

Unified Diff: src/math.js

Issue 71503004: Further improve Math.sin/cos. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/math.js
diff --git a/src/math.js b/src/math.js
index 529033ebd82ccad43fd949f39cfdfd89d65c519b..2097ed429b1edf3e5914635bfb766a3f269566bd 100644
--- a/src/math.js
+++ b/src/math.js
@@ -217,14 +217,8 @@ var InitTrigonometricFunctions;
// Also define the initialization function that populates the lookup table
// and then wires up the function definitions.
function SetupTrigonometricFunctions() {
- var samples = 1800; // Table size.
- var pi = 3.1415926535897932;
- var pi_half = pi / 2;
- var inverse_pi_half = 2 / pi;
- var two_pi = 2 * pi;
- var four_pi = 4 * pi;
- var interval = pi_half / samples;
- var inverse_interval = samples / pi_half;
+ var samples = 1620; // Table size. Do not change arbitrarily.
+ var inverse_pi_half = 0.63661977236758134;
var table_sin;
var table_cos_interval;
@@ -240,7 +234,7 @@ function SetupTrigonometricFunctions() {
// 7) Negate the result if x was in the 3rd or 4th quadrant.
// 8) Get rid of -0 by adding 0.
var Interpolation = function(x) {
- var double_index = x * inverse_interval;
+ var double_index = x * samples;
var index = double_index | 0;
var t1 = double_index - index;
var t2 = 1 - t1;
@@ -253,21 +247,19 @@ function SetupTrigonometricFunctions() {
}
var MathSinInterpolation = function(x) {
- // This is to make Sunspider's result verification happy.
- if (x > four_pi) x -= four_pi;
- var multiple = MathFloor(x * inverse_pi_half);
- if (%_IsMinusZero(multiple)) return multiple;
- x = (multiple & 1) * pi_half +
- (1 - ((multiple & 1) << 1)) * (x - multiple * pi_half);
+ x = x * inverse_pi_half;
+ var multiple = MathFloor(x);
+ if (%_IsMinusZero(multiple)) return -0;
Jakob Kummerow 2013/11/18 13:53:46 Why this change? "return multiple" might be (ever
+ x = (multiple & 1) + (1 - ((multiple & 1) << 1)) * (x - multiple);
return Interpolation(x) * (1 - (multiple & 2)) + 0;
}
// Cosine is sine with a phase offset of pi/2.
var MathCosInterpolation = function(x) {
- var multiple = MathFloor(x * inverse_pi_half);
+ x = x * inverse_pi_half;
+ var multiple = MathFloor(x);
var phase = multiple + 1;
- x = (phase & 1) * pi_half +
- (1 - ((phase & 1) << 1)) * (x - multiple * pi_half);
+ x = (phase & 1) + (1 - ((phase & 1) << 1)) * (x - multiple);
return Interpolation(x) * (1 - (phase & 2)) + 0;
};
« 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