インテル数値演算ライブラリの使用

インテル数値演算ライブラリを使用するには、プログラムに、ヘッダファイルmathimf.hをインクルードしてください。下記に、数値演算ライブラリを使用した2つのプログラム例を示します。

実関数の使用例

// 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.20f \n", fp80bits, sinl(fp80bits));

 

return 0;

}

上記のプログラム例では、long doubleデータ型を含むため、-long_doubleコンパイラ・オプションを必ず含めるようにしてください。

IA-32 システム: icc -long_double real_math.c

Itanium® ベース・システム: ecc -long_double real_math.c

a.out の出力は下記のようになります。

When x = 0.78539816, sinf(x) = 0.70710678

When x = 0.7853981633974483, sin(x) = 0.7071067811865475

When x = 0.78539816339744827900, sinl(x) = 0.70710678118654750275

 

複素数関数の使用例

// complex_math.c

 

#include <stdio.h>

#include <mathimf.h>

 

int main()

{

 

float  _Complex c32in,c32out;

double _Complex c64in,c64out;

double pi_by_four= 3.141592653589793238/4.0;

 

c64in = 1.0 + __I__* pi_by_four;

 

// Create the double precision complex number 1 + pi/4 I

// where __I__ is the imaginary unit.

 

c32in = (float _Complex) c64in;

 

// Create the float complex value from the double complex value.

 

c64out = cexp(c64in);

c32out = cexpf(c32in);

 

// Call the complex exponential,

// cexp(z) = cexp(x+Iy) = e^ (x + i y) = e^x * (cos(y) + i sin(y))

 

printf("When z = %7.7f + %7.7f I, cexpf(z) = %7.7f + %7.7f I \n",crealf(c32in),cimagf(c32in),crealf(c32out),cimagf(c32out));

printf("When z = %12.12f + %12.12f I, cexp(z) = %12.12f + %12.12f I \n",creal(c64in),cimag(c64in),creal(c64out),cimagf(c64out));

 

return 0;

}

IA-32 システム: icc complex_math.c

Itanium ベース・システム: ecc complex_math.c

a.out の出力は下記のようになります。

When z = 1.0000000 + 0.7853982 I, cexpf(z) = 1.9221154 + 1.9221156 I

When z = 1.000000000000 + 0.785398163397 I, cexp(z) = 1.922115514080 + 1.922115514080 I

_Complexデータ型は、Cプログラムではサポートされていますが、C++プログラムにはサポートされていません。

その他の考慮事項

コンパイラによって、自動的にインライン化される数値演算関数もあります。実際にインライン化される関数は、使用するベクトル化またはプロセッサ固有のコンパイラ・オプションに依存し、異なります。詳細は、「関数のインライン展開の条件」を参照してください。

デフォルトの精度制御または丸めモードを変更すると、いくつかの算術関数で返される結果に影響する場合があります。「浮動小数点演算の精度」を参照してください。

使用するデータ型によるいくつかの重要なコンパイラ・オプションは次のとおりです。