Developer Guide and Reference

Contents

Using the Intel® Math Library

Many routines in the Intel® Math Library are more optimized for Intel® microprocessors than for non-Intel microprocessors.
The
mathimf.h
header file includes prototypes for Intel® Math Library functions.
To use the Intel® Math Library, include the header file,
mathimf.h
, in your program. If the Intel® C++ Compiler is used for linking, then the Intel® Math Library is used by default.

Example: Using Real Functions

The following examples demonstrate how to use the Intel® Math Library with the Intel® C++ Compiler. After you compile this example and run the program, the program will display the sine value of
x
.
Linux*
and
macOS*
// real_math.c #include <stdio.h> #include <mathimf.h> int main() { float fp32bits; double fp64bits; long double fp80bits; long double pi_by_four = 3.141592653589793238/4.0; // pi/4 radians is about 45 degrees fp32bits = (float) pi_by_four; // float approximation to pi/4 fp64bits = (double) pi_by_four; // double approximation to pi/4 fp80bits = pi_by_four; // long double (extended) approximation to pi/4 // The sin(pi/4) is known to be 1/sqrt(2) or approximately .7071067 printf("When x = %8.8f, sinf(x) = %8.8f \n", fp32bits, sinf(fp32bits)); printf("When x = %16.16f, sin(x) = %16.16f \n", fp64bits, sin(fp64bits)); printf("When x = %20.20Lf, sinl(x) = %20.20Lf \n", fp80bits, sinl(fp80bits)); return 0; }
Use the following command to compile the example code on Linux* platforms:
icc
real_math.c
Windows*
// real_math.c #include <stdio.h> #include <mathimf.h> int main() {   float fp32bits;   double fp64bits; // /Qlong-double compiler option required because, without it, // long double types are mapped to doubles.   long double fp80bits;   long double pi_by_four = 3.141592653589793238/4.0; // pi/4 radians is about 45 degrees   fp32bits = (float) pi_by_four; // float approximation to pi/4   fp64bits = (double) pi_by_four; // double approximation to pi/4   fp80bits = pi_by_four; // long double (extended) approximation to pi/4 // The sin(pi/4) is known to be 1/sqrt(2) or approximately .7071067   printf("When x = %8.8f, sinf(x) = %8.8f \n",   fp32bits, sinf(fp32bits));   printf("When x = %16.16f, sin(x) = %16.16f \n",   fp64bits, sin(fp64bits));   printf("When x = %20.20f, sinl(x) = %20.20f \n",   (double) fp80bits, (double) sinl(fp80bits)); // printf() does not support the printing of long doubles // on Microsoft* Windows*, so fp80bits is cast to double in this example.   return 0; }
Since the
real_math.c
program includes the
long double
data type, use the
/Qlong-double
and
/Qpc80
compiler options in the command line:
icl
/Qlong-double
/Qpc80
real_math.c

Example Using Complex