seclan のほえほえルーム

| |

・プログラミング言語 C の新機能 Part LIV: tgmath.h: 型汎用数学関数 (2000/03/13 [])
 今まで見てきたように、今回の C 言語では complex 型がサポートされ、また数学関係の関数が大量に追加、強化されています。しかし、実際の使用では面倒なことが起こることがあります。例えば、sin 関数を使うことを考えると、float 型の引数に対しては sinf を、double 型の変数に対しては sin を使用する必要があります。しかし後から精度が足りなくなってそれらの型を long double 型に変更した場合には、すべての関数名を sinl に変更しなくてはなりません。これは面倒です。またいちいち実数型、複素数型の関数名を覚えるのは面倒です。sin って書いたら適当に判別してくれたらいいのに! tgmath.h はまさにその機能を提供します。
 tgmath.h を include すると、引数型に応じ自動的に適切な名前に関数名が展開されます。例えば、sin 関数の引数に double 型または int 型を書くと sin 関数に、long double 型を書くと sinl 関数に、float 型を書くと sinf に、float complex 型を書くと csinf に、long double complex 型を書くと csinl にといった具合です。
 実際の展開方法は次のように行います。まず、引数が complex 型である場合、対応する complex.h の中にある複素数関数に展開されます。もし引数に long double 型があるなら math.h の中の対応する実数関数 xxxxl に展開されます。もし引数に double 型または int 型のような整数型があるなら実数関数 xxxx に展開されます。さもなくば、float 型の指定とみなし xxxxf に展開します。また展開の結果対応する関数が存在していないような場合、その動作は未定義となります。
 なお、tgmath.h は自動的に math.h と complex.h を include します。
 最後に、tgmath.h で定義される関数名とその展開後の名前の一覧を示します。

tgmath.h で定義されるマクロとその展開先関数名一覧
tgmath.hmath.hcomplex.h
genericdoublefloatlong doubledouble complexfloat complexlong double complex
sinsinsinfsinlcsincsinfcsinl
coscoscosfcoslccosccosfccosl
tantantanftanlctanctanfctanl
asinasinasinfasinlcasincasinfcasinl
acosacosacosfacoslcacoscacosfcacosl
atanatanatanfatanlcatancatanfcatanl
sinhsinhsinhfsinhlcsinhcsinhfcsinhl
coshcoshcoshfcoshlccoshccoshfccoshl
tanhtanhtanhftanhlctanhctanhfctanhl
asinhasinhasinhfasinhlcasinhcasinhfcasinhl
acoshacoshacoshfacoshlcacoshcacoshfcacoshl
atanhatanhatanhfatanhlcatanhcatanhfcatanhl
expexpexpfexplcexpcexpfcexpl
logloglogfloglclogclogfclogl
powpowpowfpowlcpowcpowfcpowl
sqrtsqrtsqrtfsqrtlcsqrtcsqrtfcsqrtl
fabsfabsfabsffabslcabscabsfcabsl
atan2atan2atan2fatan2lN/A
cbrtcbrtcbrtfcbrtlN/A
ceilceilceilfceillN/A
copysigncopysigncopysignfcopysignlN/A
erferferfferflN/A
erfcerfcerfcferfclN/A
exp2exp2exp2fexp2lN/A
expm1expm1expm1fexpm1lN/A
fdimfdimfdimffdimlN/A
floorfloorfloorffloorlN/A
fmafmafmaffmalN/A
fmaxfmaxfmaxffmaxlN/A
fminfminfminffminlN/A
fmodfmodfmodffmodlN/A
frexpfrexpfrexpffrexplN/A
hypothypothypotfhypotlN/A
ilogbilogbilogbfilogblN/A
ldexpldexpldexpfldexplN/A
lgammalgammalgammaflgammalN/A
llrintllrintllrintfllrintlN/A
llroundllroundllroundfllroundlN/A
log10log10log10flog10lN/A
log1plog1plog1pflog1plN/A
log2log2log2flog2lN/A
logblogblogbflogblN/A
lrintlrintlrintflrintlN/A
lroundlroundlroundflroundlN/A
nearbyintnearbyintnearbyintfnearbyintlN/A
nextafternextafternextafterfnextafterlN/A
nexttowardnexttowardnexttowardfnexttowardlN/A
remainderremainderremainderfremainderlN/A
remquoremquoremquofremquolN/A
rintrintrintfrintlN/A
roundroundroundfroundlN/A
scalbnscalbnscalbnfscalbnlN/A
scalblnscalblnscalblnfscalblnlN/A
tgammatgammatgammaftgammalN/A
trunctrunctruncftrunclN/A
crealN/Acrealcrealfcreall
cimagN/Acimagcimagfcimagl
cargN/Acargcargfcargl
conjN/Aconjconjfconjl
cprojN/Acprojcprojfcprojl
注意:
 N/A には対応する関数が存在しない。指定すると未定義の動作を意味する。
 []色以外のすべての関数は、今回の C の規格で追加された関数。



by seclan


| |

 

配信

29.53 msec