Oracle® Solaris Studio 12.4: 数値計算ガイド

印刷ビューの終了

更新: 2015 年 1 月
 
 

3.3 単精度、倍精度、および拡張/4 倍精度

ほとんどの数値関数は、単精度、倍精度、および拡張 (x86) または 4 倍精度で使用できます。さまざまな関数の異なる精度バージョンを各言語から呼び出した例をTable 3–4 に示します。

表 3-4  単精度、倍精度、および拡張/4 倍精度関数の呼び出し
言語
単精度
倍精度
拡張/4 倍精度
C、C++
#include <math.h> float x,y,z; x = sinf(y); x = fmodf(y,z); #include <sunmath.h> float x; x = max_normalf(); x = r_addran_();
#include <math.h> double x,y,z; x = sin(y); x = fmod(y,z); #include <sunmath.h> double x; x = max_normal(); x = d_addran_();
#include <math.h> long double x,y,z; x = sinl(y); x = fmodl(y,z); #include <sunmath.h> long double x; x = max_normall();
Fortran
REAL x,y,z x = sin(y) x = r_fmod(y,z) x = r_max_normal() x = r_addran()
REAL*8 x,y,z x = sin(y) x = d_fmod(y,z) x = d_max_normal() x = d_addran()
REAL*16 x,y,z x = sin(y) x = q_fmod(y,z) x = q_max_normal()

C では、単精度関数の名前は倍精度関数の名前に f を追加することによって形成され、拡張または 4 倍精度関数の名前は l を追加することによって形成されます。 Fortran の呼び出し規約は異なるため、libsunmath は、単精度、倍精度、および 4 倍精度のために、それぞれ r_…、d_…、および q_…関数を提供します。Fortran の組み込み関数は、3 つのすべての精度の汎用名で呼び出すことができます。

すべての関数に q_… のバージョンがあるわけではありません。libm および libsunmath 関数の名前と定義については、math.h および sunmath.h を参照してください。

Fortran プログラムでは、r_… 関数を real として、d_… 関数を倍精度として、および q_… 関数を REAL*16 として宣言することを忘れないでください。そうしないと、型の不一致が発生することがあります。


注 -  Oracle Solaris Studio Fortran は、拡張倍精度をサポートしていません。