Reviewers: Jakob,
Description:
Further improve Math.sin/cos.
[email protected]
BUG=
Please review this at https://codereview.chromium.org/71503004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+10, -18 lines):
M src/math.js
Index: src/math.js
diff --git a/src/math.js b/src/math.js
index
529033ebd82ccad43fd949f39cfdfd89d65c519b..1c19421bb1371832e139e2a6d4b9dcfe1d31b972
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.
+ 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;
+ 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;
};
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.