Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Platform independent math library

Is there a publically available library that will produce the exact same results for sin, cos, floor, ceil, exp and log on 32 bit and 64 bit linux, solaris and possibly other platforms?

I am considering the following alternatives:
a) cephes compiled with gcc -mfpmath=sse and the same optimization levels on each platform ... but its not clear that this would work.
b) MPFR but I am worried that this would be too slow.

Regarding precision (edited): For this particular application I don't really need something that produces the value that is numerically closest to the exact value. I just need the answers to be the exact same on all platforms, os and "bitness". That being said the values need to be reasonable (5 digits would probably be enough). I apologize for not having made this clear in my initial question.

I guess MAPM or MPFR with a low enough precision setting might do the trick but I was hoping to find something that did not have the "multiple precision" machinery/flavor to it. In any case, I will try this out.

like image 661
Carlos Avatar asked Aug 30 '25 16:08

Carlos


1 Answers

Would something like: http://lipforge.ens-lyon.fr/www/crlibm/index.html be what you are searching for (this is a library whose aim is to be able to replace the standard math library of C99 -- so keep good enough performance in the normal cases -- while ensuring correctly rounded result according to IEEE 754 rounding modes) ?

like image 111
AProgrammer Avatar answered Sep 02 '25 07:09

AProgrammer