Search code examples
ioscswiftllvm-clangmath.h

Integrate FDLIBM library to iOS


I am trying to integrate FDLIBM library (http://www.netlib.org/fdlibm/) into my Swift based (with some objc and c code too) iOS app. However, some of functions there are conflicting with math.h which is automatically included in iOS, i.e. sin, cos,acos, asin, pow, etc. So the project does not compile. I do need to use these functions in the FDLIBM.

These are some of the functions defined in fdlibm.h (http://www.netlib.org/fdlibm/fdlibm.h) which are duplicate to math.h

/*
 * ANSI/POSIX
 */
extern double acos __P((double));
extern double asin __P((double));
extern double atan __P((double));
extern double atan2 __P((double, double));
extern double cos __P((double));
extern double sin __P((double));
extern double tan __P((double));

extern double cosh __P((double));
extern double sinh __P((double));
extern double tanh __P((double));

extern double exp __P((double));
extern double frexp __P((double, int *));
extern double ldexp __P((double, int));
extern double log __P((double));
extern double log10 __P((double));
extern double modf __P((double, double *));

extern double pow __P((double, double));
extern double sqrt __P((double));

Does anyone have a solution for this? Any advice and tips will be appreciated. Thanks.

Update: To give more background about what I am doing, we are building a cross platform app (Android and iOS for now) using the same backend service. There are critical float point calculations we need to make sure the results are the same for both side. Based on our testing, the results of sin(), cos() and some other functions in fdlimb on Android is different from the results of using same functions in math.h in iOS. So I am trying to integrate fdlibm into iOS to see if we can get the same results.

So if there is a way to solve the root problem, which makes the floating point calculation exactly the same for iOS and Android for these functions pow(), sin(), cos(), asin(), acos(), atan2(), I don't have to integrate fdlibm.h


Solution

  • From the comments this looks to much work, consider a work around, e.g on server side round all floating points such that the last digit would be removed.
    Sun (Java) once detected a difference in the last digit between two plattforms and decided to calculate all Math in Software. They called that StrictMath.