Adding_Math_Functions_To_uClibc_mathlib


Adding_Math_Functions_To_uClibc_mathlib

 

Kamikaze's mathlib is missing many C99 math functions. See http://forum.openwrt.org/viewtopic.php?id=4166 for more information. The developers say it is to reduce the math lib's storage footprint. This is a valid point for most embedded systems and most OpenWrt packages don't require these functions. Having said that, if you find the list of included math functions too restrictive, you can add back in those math functions included in the uCLib's math library source but not compiled for OpenWrt. In my experience, adding functions like ceilf or floorf add about 500 bytes each to the resulting math library.

 

To add back some of the C99 math functions that are present in uClibc's libm but are absent in OpenWrt, do the following:

 

 

svn co -r 3535 https://svn.openwrt.org/openwrt/trunk/

cd trunk/openwrt

 

+CSRC+= fpmacros.c nan.c s_rint.c e_hypot.c w_hypot.c

+CSRC+= fpmacros.c nan.c s_rint.c e_hypot.c w_hypot.c s_floorf.c s_ceilf.c

 

 

cd trunk/openwrt/toolchain_build_mipsel/uClibc-0.9.28/libm

grep floorf *.c

 

 

--- uClibc-0.9.28.orig/libm/float_wrappers.c    2005-08-17 15:49:41.000000000 -0700
+++ uClibc-0.9.28/libm/float_wrappers.c 2006-04-01 21:27:12.000000000 -0800
@@ -24,6 +24,8 @@

 #include "math.h"

+#define L_powf
+
 /* For the time being, do _NOT_ implement these functions
  * that are defined by SuSv3 */
 #if 0

 

--- uClibc-0.9.28.orig/libm/float_wrappers.c    2005-08-17 15:49:41.000000000 -0700
+++ uClibc-0.9.28/libm/float_wrappers.c 2006-04-01 22:41:51.000000000 -0800
@@ -24,6 +24,13 @@

 #include "math.h"

+#define L_powf
+float       powf(float, float);
+#define L_cosf
+float       cosf(float);
+#define L_sinf
+float       sinf(float);
+
 /* For the time being, do _NOT_ implement these functions
  * that are defined by SuSv3 */
 #if 0