From 3282cf30bb33181b4e9399ad204b73047db3084c Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 4 Oct 2011 13:35:55 +0000 Subject: [PATCH] core: replace the cos(real) implementation with a simple call to sin(pi/2-x). No loss in precision in theory. --- src/real.cpp | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/src/real.cpp b/src/real.cpp index 78ab1b3c..2101053e 100644 --- a/src/real.cpp +++ b/src/real.cpp @@ -738,33 +738,7 @@ real sin(real const &x) real cos(real const &x) { - bool switch_sign = false; - real absx = fmod(fabs(x), real::R_PI << 1); - - if (absx > real::R_PI) - absx = (real::R_PI << 1) - absx; - - if (absx > real::R_PI_2) - { - absx = real::R_PI - absx; - switch_sign = true; - } - - real ret = 0.0, fact = 1.0, xn = 1.0, x2 = absx * absx; - for (int i = 1; ; i += 2) - { - real newret = ret + xn / fact; - if (ret == newret) - break; - ret = newret; - xn *= x2; - fact *= (real)(-i * (i + 1)); - } - - /* Propagate sign */ - if (switch_sign) - ret.m_signexp ^= 0x80000000u; - return ret; + return sin(real::R_PI_2 - x); } static real asinacos(real const &x, bool is_asin, bool is_negative)