From 4ce99f0aff34dd3e64561baab7b79127f28a8cd4 Mon Sep 17 00:00:00 2001 From: Jean-Yves Lamoureux Date: Wed, 13 Jul 2005 17:45:47 +0000 Subject: [PATCH] * src/math.c src/bitmap.c src/caca.h Removed powf call, added caca_powf, to remove libm depencies and problems on old compilers/linkers. --- src/bitmap.c | 3 +-- src/caca.h | 1 + src/math.c | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/bitmap.c b/src/bitmap.c index 5e95f1c..3686291 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -45,7 +45,6 @@ typedef unsigned int uint32_t; #include #include #include -#include #include "caca.h" #include "caca_internals.h" @@ -338,7 +337,7 @@ void caca_set_bitmap_gamma(struct caca_bitmap *bitmap, float gammaval) bitmap->gammaval = gammaval; for(i = 0; i < 4096; i++) - bitmap->gammatab[i] = 4096.0 * powf((float)i / 4096.0, 1.0 / gammaval); + bitmap->gammatab[i] = 4096.0 * caca_powf((float)i / 4096.0, 1.0 / gammaval); } /** diff --git a/src/caca.h b/src/caca.h index f98f8da..c3bb4c1 100644 --- a/src/caca.h +++ b/src/caca.h @@ -317,6 +317,7 @@ void caca_fill_triangle(int, int, int, int, int, int, char); * @{ */ int caca_rand(int, int); unsigned int caca_sqrt(unsigned int); +float caca_powf(float x, float y); /* @} */ /** \defgroup sprite Sprite handling diff --git a/src/math.c b/src/math.c index 9d93da7..59a7ce2 100644 --- a/src/math.c +++ b/src/math.c @@ -78,3 +78,26 @@ unsigned int caca_sqrt(unsigned int a) return 2 * caca_sqrt(a / 4); } + +/** + * \brief powf substitute (x^y) + * \param x The value to be raised + * \param y The power to raise x of. + * \return \p x raised to the power of \p y + */ + +float caca_powf(float x, float y) +{ + int i=((int)y); + float r=x; + + if(((int)y)==1 || ((int)x)==1) + return x; + + i--; + while(i--) + { + r*=x; + } + return r; +}