From 7984660b4b8f3dd357b68ebfb57af43f0c7cd0d5 Mon Sep 17 00:00:00 2001 From: Dominik Taborsky Date: Wed, 17 Jun 2015 11:30:14 +0200 Subject: [PATCH 1/2] math: reimplement cosh along its Taylor series. --- src/math/p_cosh.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/math/p_cosh.c b/src/math/p_cosh.c index 02b1421..ea78419 100644 --- a/src/math/p_cosh.c +++ b/src/math/p_cosh.c @@ -18,9 +18,20 @@ #include void p_cosh_f32(const float *a, float *c, int n) { + int i; + for (i = 0; i < n; i++) { + const float *pa = (a+i); + float *pc = (c+i); + float val = 0; + float theta = M_NORMALIZE_RADIANS(*pa); + float theta_sq = theta*theta; - int i; - for (i = 0; i < n; i++) { - *(c + i) = coshf(*(a + i)); - } + val = 1.0f + theta_sq*0.01111111f*val; + val = 1.0f + theta_sq*0.01785714f*val; + val = 1.0f + theta_sq*0.03333333f*val; + val = 1.0f + theta_sq*0.08333333f*val; + val = 1.0f + theta_sq*0.50000000f*val; + + *pc = val; + } } From 76ca98372b8a4335863a48d1c7453a9f29753e59 Mon Sep 17 00:00:00 2001 From: Dominik Taborsky Date: Thu, 25 Jun 2015 11:57:58 +0200 Subject: [PATCH 2/2] math: cosh: do not normalize radians, it's not supposed to be there. --- src/math/p_cosh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/p_cosh.c b/src/math/p_cosh.c index ea78419..61347d0 100644 --- a/src/math/p_cosh.c +++ b/src/math/p_cosh.c @@ -23,7 +23,7 @@ void p_cosh_f32(const float *a, float *c, int n) const float *pa = (a+i); float *pc = (c+i); float val = 0; - float theta = M_NORMALIZE_RADIANS(*pa); + float theta = *pa; float theta_sq = theta*theta; val = 1.0f + theta_sq*0.01111111f*val;