From cba36f279b2b584a9f4eec7ca2fe9572670878c4 Mon Sep 17 00:00:00 2001 From: Cesare Tirabassi Date: Sat, 18 Jul 2009 07:57:04 +0200 Subject: [PATCH] weather: use expf if --enable_math is given, otherwise use fast 3rd order approximation --- src/weather.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/weather.c b/src/weather.c index a7819b6b..361bdfb8 100644 --- a/src/weather.c +++ b/src/weather.c @@ -27,6 +27,9 @@ #include "temphelper.h" #include #include +#ifdef MATH +#include +#endif /* MATH */ #include #include #include @@ -109,8 +112,12 @@ int rel_humidity(int dew_point, int air) { const float a = 17.27f; const float b = 237.7f; - float g = a*dew_point/(b+dew_point); - return (int)(100.f*expf(g-a*air/(b+air))); + float diff = a*(dew_point/(b+dew_point)-air/(b+air)); +#ifdef MATH + return (int)(100.f*expf(diff)); +#else + return (int)(16.666667163372f*(6.f+diff*(6.f+diff*(3.f+diff)))); +#endif /* MATH */ } /*