Compilation and installation
See the INSTALL file in the main directory. This library is
developed using the GNU autotools, and can therefore be compiled on
most Unixlike systems by
./configure; make
The command make check will launch the selftest. For
more advanced testing you will need to have MPFR installed and to pass
the enablempfr flag to configure . For other
flags, see ./configure help .
Using CRlibm functions in your program
Currently CRlibm functions have different names from the
standard math.h functions. For example, for the sine function
(double sin(double) in the standard math.h ), you
have four different functions in crlibm for the four
different rounding modes. These functions are named sin_rn ,
sin_ru , sin_rd and sin_rz for round to the
nearest, round up, round down and round to zero respectively. These
functions are declared in the C header file \textttcrlibm.h.
The CRlibm library relies on doubleprecision IEEE754
compliant floatingpoint operations. For some processors and some
operating systems (most notably IA32 and IA64 processors under
GNU/Linux), the default precision is set to doubleextended. On such
systems you will need to call the crlibm_init() function
before using any CRlibm function to ensure such compliance.
This has the effect of setting the processor flags to IEEE754
doubleprecision with rounding to the nearest mode. This function
returns the previous processor status, so that previous mode can be
restored using the function crlibm_exit() . Note that you
probably only need one call to crlibm_init() at the beginning
of your program, not one call before each call to a mathematical
function.
Here's an example function named compare.c using the cosine
function from CRlibm library.
#include< stdio.h >
#include< math.h >
#include< crlibm.h >
int main(void){
double x, res_libm, res_crlibm;
crlibm_init(); /* no need here to save the old processor state returned by crlibm_init() */
printf("Enter a floating point number: ");
scanf("%lf", &x);
res_libm = cos(x);
res_crlibm = cos_rn(x);
printf("\n x=%.25e \n", x);
printf("\n cos(x) with the system : %.25e \n", res_libm);
printf("\n cos(x) with crlibm : %.25e \n", res_crlibm);
return 0;
}
This example will be compiled with
gcc compare.c lm lcrlibm o compare
