weather: use expf if --enable_math is given, otherwise use fast 3rd order approximation
authorCesare Tirabassi <norsetto@ubuntu.com>
Sat, 18 Jul 2009 05:57:04 +0000 (07:57 +0200)
committerCesare Tirabassi <norsetto@ubuntu.com>
Sat, 18 Jul 2009 05:57:04 +0000 (07:57 +0200)
src/weather.c

index a7819b6..361bdfb 100644 (file)
@@ -27,6 +27,9 @@
 #include "temphelper.h"
 #include <time.h>
 #include <ctype.h>
+#ifdef MATH
+#include <math.h>
+#endif /* MATH */
 #include <curl/curl.h>
 #include <curl/types.h>
 #include <curl/easy.h>
@@ -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 */
 }
 
 /*