From 5be195a8b0ea9293815e9681c6190a46f7772bcc Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 3 Sep 2011 22:06:00 +0000 Subject: [PATCH] core: slightly reorganise Taylor series in sin() and cos(). --- src/trig.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/trig.cpp b/src/trig.cpp index 5ef4b76b..a24e8e5a 100644 --- a/src/trig.cpp +++ b/src/trig.cpp @@ -190,9 +190,9 @@ double lol_sin(double x) * interleave the Taylor series operations a lot better. */ double x2 = absx * absx; double x4 = x2 * x2; - double sub1 = SC[3] * x4 + SC[1]; + double sub1 = (SC[3] * x4 + SC[1]) * x4 + ONE; double sub2 = (SC[4] * x4 + SC[2]) * x4 + SC[0]; - double taylor = (sub1 * x2 + sub2) * x2 + ONE; + double taylor = sub2 * x2 + sub1; return x * taylor; } #endif @@ -228,9 +228,9 @@ double lol_sin(double x) double x1 = HALF - lol_fabs(absx); double x2 = x1 * x1; double x4 = x2 * x2; - double sub1 = (CC[5] * x4 + CC[3]) * x4 + CC[1]; + double sub1 = ((CC[5] * x4 + CC[3]) * x4 + CC[1]) * x4 + ONE; double sub2 = (CC[4] * x4 + CC[2]) * x4 + CC[0]; - double taylor = (sub1 * x2 + sub2) * x2 + ONE; + double taylor = sub2 * x2 + sub1; return taylor * sign; } @@ -241,13 +241,13 @@ double lol_sin(double x) double x2 = absx * absx; double x4 = x2 * x2; #if defined LOL_FEATURE_VERY_CHEAP_BRANCHES - double sub1 = SC[3] * x4 + SC[1]; + double sub1 = (SC[3] * x4 + SC[1]) * x4 + ONE; double sub2 = (SC[4] * x4 + SC[2]) * x4 + SC[0]; #else - double sub1 = ((SC[7] * x4 + SC[5]) * x4 + SC[3]) * x4 + SC[1]; + double sub1 = (((SC[7] * x4 + SC[5]) * x4 + SC[3]) * x4 + SC[1]) * x4 + ONE; double sub2 = ((SC[6] * x4 + SC[4]) * x4 + SC[2]) * x4 + SC[0]; #endif - double taylor = (sub1 * x2 + sub2) * x2 + ONE; + double taylor = sub2 * x2 + sub1; return absx * taylor * sign; } @@ -302,13 +302,13 @@ double lol_cos(double x) double x2 = absx * absx; double x4 = x2 * x2; #if defined LOL_FEATURE_VERY_CHEAP_BRANCHES - double sub1 = (CC[5] * x4 + CC[3]) * x4 + CC[1]; + double sub1 = ((CC[5] * x4 + CC[3]) * x4 + CC[1]) * x4 + ONE; double sub2 = (CC[4] * x4 + CC[2]) * x4 + CC[0]; #else - double sub1 = ((CC[7] * x4 + CC[5]) * x4 + CC[3]) * x4 + CC[1]; + double sub1 = (((CC[7] * x4 + CC[5]) * x4 + CC[3]) * x4 + CC[1]) * x4 + ONE; double sub2 = ((CC[6] * x4 + CC[4]) * x4 + CC[2]) * x4 + CC[0]; #endif - double taylor = (sub1 * x2 + sub2) * x2 + ONE; + double taylor = sub2 * x2 + sub1; return taylor * sign; }