From 0ffb256e72eebe9b830d7c14ab0fc86e49ec4ed6 Mon Sep 17 00:00:00 2001 From: Dominik Date: Tue, 16 Jun 2015 22:31:46 +0200 Subject: [PATCH] math: reimplement pow() as a combination of exp() and ln(). --- src/math/p_pow.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/math/p_pow.c b/src/math/p_pow.c index 8ef58ed..2e46410 100644 --- a/src/math/p_pow.c +++ b/src/math/p_pow.c @@ -15,12 +15,17 @@ * @return None * */ -#include + void p_pow_f32(const float *a, const float *b, float *c, int n) { - - int i; - for (i = 0; i < n; i++) { - *(c + i) = powf(*(a + i), *(b + i)); - } + int i = 0; + float x, *c_ = c; + const float *a_ = a, *b_ = b; + while (i < n) { + /* a^b = e^(b*ln(a)) */ + p_ln_f32(a_++, &x, 1); + x *= *b_++; + p_exp_f32(&x, c_++, 1); + ++i; + } }