c99数学関数マニュアル - 長崎大学1 / 60 c99数学関数マニュアル iso/iec...
TRANSCRIPT
1 / 60
C99数学関数マニュアルC99数学関数マニュアルC99数学関数マニュアルC99数学関数マニュアル
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.3.5 7.3.5 7.3.5 7.3.5 三角関数三角関数三角関数三角関数
7.3.5.1 cacos 関数
【名前】
cacos – 複素数逆余弦関数
【形式】
#include <complex.h> double complex cacos(double complex z); float complex cacosf(float complex z); long double complex cacosl(long double complex z);
【機能説明】
cacos 関数は z の複素数逆余弦を求めます。
【戻り値】
cacos 関数は、複素数の逆余弦を求めます。結果の値は、実軸は[0, π]、虚軸は無限の範囲
にあります。
【詳細】
cacos(conj(z)) = conj(cacos(z)) が成立します。
cacos(±0.0 + i 0.0) の場合、 02
i−πを返却します。
cacos(±0.0 + i NaN) の場合、 iNaN−2π
を返却します。
cacos(x + i ∞) (x は有限値)の場合、 ∞− i2π
を返却します。
cacos(x + i NaN) (x は有限値かつ x≠0.0)の場合、浮動小数点無効演算例外(invalid)を発
生して NaN + i NaN を返却します。
cacos(-∞ + i y) (y > 0.0)の場合、π + i ∞を返却します。
cacos(+∞ + i y) (y > 0.0)の場合、+0.0 – i ∞を返却します。
cacos(-∞ + i ∞) の場合、 ∞− i4
3πを返却します。
cacos(+∞ + i ∞) の場合、 ∞− i4π
を返却します。
cacos(+∞ + i NaN) の場合、NaN ± i ∞ (結果の虚部の符号は定義されない)を返却しま
す。
cacos(+∞ + i y) (y は有限値)の場合、浮動小数点無効演算例外(invalid)を発生して NaN +
i NaN を返却します。
cacos(NaN + i ∞) の場合、NaN – i ∞を返却します。
2 / 60
cacos(NaN + i NaN)の場合、NaN + i NaN を返却します。
【補足】
)1z log(z i cacos(z) 2 −+=
7.3.5.2 casin 関数
【名前】
casin – 複素数逆正弦関数
【形式】
#include <complex.h> double complex casin(double complex z); float complex casinf(float complex z); long double complex casinl(long double complex z);
【機能説明】
casin 関数は z の複素数逆正弦を求めます。
【戻り値】
casin 関数は、複素数の逆正弦を求めます。結果の値は、実軸は ]2
,2
[ ππ +− 、虚軸は無限の
範囲にあります。
【詳細】
casin(z) = -i casinh(i z)が成立します。
【補足】
)z-1 z log(-i i casin(z) 2+=
7.3.5.3 catan 関数
【名前】
catan – 複素数逆正接関数
【形式】
#include <complex.h> double complex catan(double complex z); float complex catanf(float complex z); long double complex catanl(long double complex z);
【機能説明】
catan 関数は z の複素数逆正接を求めます。
【戻り値】
catan 関数は、複素数の逆正接を求めます。結果の値は、実軸は ]2
,2
[ ππ +− 、虚軸は無限の
範囲にあります。
【詳細】
3 / 60
catan(z) = -i catanh(i z)が成立します。
7.3.5.4 ccos 関数
【名前】
ccos – 複素数余弦関数
【形式】
#include <complex.h> double complex ccos(double complex z); float complex ccosf(float complex z); long double complex ccosl(long double complex z);
【機能説明】
ccos 関数は z の複素数余弦を求めます。
【戻り値】
ccos 関数は、複素数の余弦を求めます。
【詳細】
ccos(z) = ccosh(i z)が成立します。
【補足】
)(21 ccos(z) iz izee −+=
7.3.5.5 csin 関数
【名前】
csin – 複素数正弦関数
【形式】
#include <complex.h> double complex csin(double complex z); float complex csinf(float complex z); long double complex csinl(long double complex z);
【機能説明】
csin 関数は z の複素数正弦を求めます。
【戻り値】
csin 関数は、複素数の正弦を求めます。
【詳細】
csin(z) = -i csinh(i z)が成立します。
【補足】
)(2i1 csin(z) iz izee −−=
7.3.5.6 ctan 関数
【名前】
ctan – 複素数正接関数
4 / 60
【形式】
#include <complex.h> double complex ctan(double complex z); float complex ctanf(float complex z); long double complex ctanl(long double complex z);
【機能説明】
ctan 関数は z の複素数正接を求めます。
【戻り値】
ctan 関数は、複素数の正接を求めます。
【詳細】
ctan(z) = -i ctanh(i z)が成立します。
5 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.3.6 7.3.6 7.3.6 7.3.6 双曲線関数双曲線関数双曲線関数双曲線関数
7.3.6.1 cacosh 関数
【名前】
cacosh – 複素数逆双曲線余弦関数
【形式】
#include <complex.h> double complex cacosh(double complex z); float complex cacoshf(float complex z); long double complex cacoshl(long double complex z);
【機能説明】
cacosh 関数は、実軸が 1.0 より小さい z の複素数逆双曲線余弦を求めます。
【戻り値】
cacosh 関数は、複素数の逆双曲線余弦を求めます。結果の値は、虚軸は[-iπ, iπ]、実軸
は非負の範囲にあります。
【詳細】
cacosh(conj(z)) = conj(cacosh(z))が成立します。
cacosh(±0.0 + i 0.0) の場合、2
0 πi++ を返却します。
cacosh(x + i ∞) (x は有限値)の場合、2πi+∞+ を返却します。
cacosh(x + i NaN) (x は有限値)の場合、浮動小数点無効演算例外(invalid)を発生して NaN
+ i NaN を返却します。
cacosh(-∞ + i y) (y > 0.0)の場合、+∞ + i πを返却します。
cacosh(∞ + i y) (y > 0.0)の場合、+∞ + i 0.0 を返却します。
cacosh(-∞ + i ∞) の場合、4
3πi+∞+ を返却します。
cacosh(+∞ + i ∞) の場合、4πi+∞+ を返却します。
cacosh(+∞ + i NaN) の場合、+∞ + i NaN を返却します。
cacosh(+∞ + i y) (y は有限値)の場合、浮動小数点無効演算例外(invalid)を発生して NaN
+ i NaN を返却します。
cacosh(NaN + i ∞) の場合、∞ + i NaN を返却します。
cacosh(NaN + i NaN) の場合、NaN + i NaN を返却します。
7.3.6.2 casinh 関数
【名前】
6 / 60
casinh – 複素数逆双曲線正弦関数
【形式】
#include <complex.h> double complex casinh(double complex z); float complex casinhf(float complex z); long double complex casinhl(long double complex z);
【機能説明】
casinh 関数は、実軸が 1.0 より小さい z の複素数逆双曲線正弦を求めます。
【戻り値】
casinh 関数は、複素数の逆双曲線正弦を求めます。結果の値は、虚軸は ]2
,2
[ ππ ii +− 、実軸
は非負の範囲にあります。
【詳細】
casinh(conj(z)) = conj(casinh(z))が成立します。
casinh(±0.0 + i 0.0) の場合、2πi+∞+ を返却します。
casinh(x + i ∞) (x 正の有限値)の場合、2πi+∞+ を返却します。
casinh(x + i NaN) (x は有限値)の場合、浮動小数点無効演算例外(invalid)を発生して NaN
+ i NaN を返却します。
casinh(+∞ + i y) (y は正の有限値)の場合、+∞ + i 0.0 を返却します。
casinh(+∞ + i ∞) の場合、4πi+∞+ を返却します。
casinh(+∞ + i NaN) の場合、+∞ + i NaN を返却します。
casinh(NaN + i 0.0) の場合、NaN + i 0.0 を返却します。
casinh(NaN + i y) (y はゼロでない有限値) の場合、NaN + i NaN を返却します。浮動小数
点無効演算例外(invalid)を発生するかどうかは任意です。
casinh(NaN + i ∞) の場合、±∞ + i NaN を返却します。実部の符号は不定です。
casinh(NaN + i NaN) の場合、NaN + i NaN を返却します。
7.3.6.3 catanh 関数
【名前】
catanh – 複素数逆双曲線正接関数
【形式】
#include <complex.h> double complex catanh(double complex z); float complex catanhf(float complex z); long double complex catanhl(long double complex z);
【機能説明】
7 / 60
catanh 関数は、実軸が[-1.0, 1.0]の範囲外にある z の複素数逆双曲線正接を求めます。
【戻り値】
catanh 関数は、複素数の逆双曲線正接を求めます。結果の値は、虚軸は ]2
,2
[ ππ ii− の範囲に
あります。
【詳細】
catanh(conj(z)) = conj(catanh(z))が成立します。
catanh(±0.0 + i 0.0) の場合、+0.0 + i 0.0 を返却します。
catanh(+0.0 + i NaN) の場合、+0.0 + i NaN を返却します。
catanh(+1.0 + i 0.0) の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発生して+∞+ i
0.0 を返却します。
catanh(x + i ∞) (x は正の有限値)の場合、2
0.0 πi++ を返却します。
catanh(x + i NaN) (x はゼロでない有限値)の場合、浮動小数点無効演算例外(invalid)を発
生して、NaN + i NaN を返却します。
catanh(+∞ + i y) (y は正の有限値)の場合、2
0.0 πi++ を返却します。
catanh(+∞ + i ∞) の場合、2
0.0 πi++ を返却します。
catanh(+∞ + i NaN) の場合、+0.0 + i NaN を返却します。
catanh(NaN + i y) (y は有限値) の場合、浮動小数点無効演算例外(invalid)を発生して、
NaN + i NaN を返却します。実部の符号は不定です。
catanh(NaN + i ∞) の場合、2
0.0 πi+± を返却します。実部の符号は不定です。
catanh(NaN + i NaN) の場合、NaN + i NaN を返却します。
7.3.6.4 ccosh 関数
【名前】
ccosh – 複素数双曲線余弦関数
【形式】
#include <complex.h> double complex ccosh(double complex z); float complex ccoshf(float complex z); long double complex ccoshl(long double complex z);
【機能説明】
ccosh 関数は、z の双曲線余弦を求めます。
【戻り値】
ccosh 関数は、複素数の双曲線余弦を求めます。
8 / 60
【詳細】
ccosh(conj(z)) = conj(ccosh(z))が成立します。
ccosh(±0.0 + i 0.0) の場合、1.0 + i 0.0 を返却します。
ccosh(+0.0 + i ∞) の場合、浮動小数点無効演算例外(invalid)を発生して、NaN ± i 0.0
を返却します。虚部の符号は不定です。
ccosh(+0.0 + i NaN)の場合、NaN ± i 0.0 を返却します。虚部の符号は不定です。
ccosh(x + i ∞) (x はゼロでない有限値)の場合、浮動小数点無効演算例外(invalid)を発生
して、NaN + i NaN を返却します。
ccosh(x + i NaN) (x はゼロでない有限値)の場合、浮動小数点無効演算例外(invalid)を発
生して、NaN + i NaN を返却します。
ccosh(+∞ + i 0.0) の場合、+∞ + i 0.0 を返却します。
ccosh(+∞ + i y) (y はゼロでない有限値)の場合、+∞ cis(y)を返却します。
ccosh(+∞ + i ∞) (x はゼロでない有限値)の場合、浮動小数点無効演算例外(invalid)を発
生して、±∞ + i NaN を返却します。実部の符号は不定です。
ccosh(+∞ + i NaN) の場合、+∞ + i NaN を返却します。
ccosh(NaN + i 0.0) の場合、NaN ± i 0.0 を返却します。虚部の符号は不定です。
ccosh(NaN + i y) (y はゼロでないすべての値)の場合、NaN + i NaN を返却します。浮動小
数点無効演算例外(invalid)を発生するかどうかは任意です。
ccosh(NaN + i NaN) の場合、NaN + i NaN を返却します。
7.3.6.5 csinh 関数
【名前】
csinh – 複素数双曲線正弦関数
【形式】
#include <complex.h> double complex csinh(double complex z); float complex csinhf(float complex z); long double complex csinhl(long double complex z);
【機能説明】
csinh 関数は、z の双曲線正弦を求めます。
【戻り値】
csinh 関数は、複素数の双曲線正弦を求めます。
【詳細】
csinh(conj(z)) = conj(csinh(z))が成立します。
csinh(±0.0 + i 0.0) の場合、0.0 + i 0.0 を返却します。
csinh(+0.0 + i ∞) の場合、浮動小数点無効演算例外(invalid)を発生して、±0.0 + i NaN
を返却します。実部の符号は不定です。
csinh(+0.0 + i NaN)の場合、±0.0 + i NaN を返却します。実部の符号は不定です。
9 / 60
csinh(x + i ∞) (x は正の有限値)の場合、浮動小数点無効演算例外(invalid)を発生して、
NaN + i NaN を返却します。
csinh(x + i NaN) (x はゼロでない有限値)の場合、浮動小数点無効演算例外(invalid)を発
生して、NaN + i NaN を返却します。
csinh(+∞ + i 0.0) の場合、+∞ + i 0.0 を返却します。
csinh(+∞ + i y) (y は正の有限値)の場合、+∞ cis(y)を返却します。
csinh(+∞ + i ∞) の場合、浮動小数点無効演算例外(invalid)を発生して、±∞ + i NaN
を返却します。実部の符号は不定です。
csinh(+∞ + i NaN) の場合、±∞ + i NaN を返却します。実部の符号は不定です。
csinh(NaN + i 0.0) の場合、NaN + i 0.0 を返却します。
csinh(NaN + i y) (y はゼロでないすべての値)の場合、NaN + i NaN を返却します。浮動小
数点無効演算例外(invalid)を発生するかどうかは任意です。
csinh(NaN + i NaN) の場合、NaN + i NaN を返却します。
7.3.6.6 ctanh 関数
【名前】
ctanh – 複素数双曲線正接関数
【形式】
#include <complex.h> double complex ctanh(double complex z); float complex ctanhf(float complex z); long double complex ctanhl(long double complex z);
【機能説明】
ctanh 関数は、z の双曲線正接を求めます。
【戻り値】
ctanh 関数は、複素数の双曲線正接を求めます。
【詳細】
ctanh(conj(z)) = conj(ctanh(z))が成立します。
ctanh(±0.0 + i 0.0) の場合、0.0 + i 0.0 を返却します。
csinh(x + i ∞) (x は正の有限値)の場合、浮動小数点無効演算例外(invalid)を発生して、
NaN + i NaN を返却します。
ctanh(x + i NaN) (x はゼロでない有限値)の場合、浮動小数点無効演算例外(invalid)を発
生して、NaN + i NaN を返却します。
ctanh(+∞ + i y) (y は正の有限値)の場合、1.0 + i 0 sin(2y)を返却します。
ctanh(+∞ + i ∞) の場合、浮動小数点無効演算例外(invalid)を発生して、1.0 + i 0.0
を返却します。虚部の符号は不定です。
ctanh(+∞ + i NaN) の場合、1.0 ± i 0.0 を返却します。虚部の符号は不定です。
ctanh(NaN + i 0.0) の場合、NaN + i 0.0 を返却します。
10 / 60
ctanh(NaN + i y) (y はゼロでないすべての値)の場合、NaN + i NaN を返却します。浮動小
数点無効演算例外(invalid)を発生するかどうかは任意です。
csinh(NaN + i NaN) の場合、NaN + i NaN を返却します。
11 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.3.7 7.3.7 7.3.7 7.3.7 指数関数及び対数関数指数関数及び対数関数指数関数及び対数関数指数関数及び対数関数
7.3.7.1 cexp 関数
【名前】
cexp – 複素数指数関数
【形式】
#include <complex.h> double complex cexp(double complex z); float complex cexpf(float complex z); long double complex cexpl(long double complex z);
【機能説明】
cexp 関数は、底を e とする z の指数を求めます。
【戻り値】
cexp 関数は、底を e とする指数値を返却します。
【詳細】
cexp(conj(z)) = conj(cexp(z)) が成立します。
cexp(±0.0 + i 0.0) の場合、1.0 + i 0.0 を返却します。
cexp(x + i ∞) の場合、浮動小数点無効演算例外(invalid)を発生して、NaN + i NaN を返
却します。
cexp(x + i NaN)の場合、浮動小数点無効演算例外(invalid)を発生して、NaN + i NaN を返
却します。
cexp(+∞ + i 0.0)の場合、+∞ + i 0.0 を返却します。
cexp(-∞ + i y) (y は有限値)の場合、0 cis(y)を返却します。
cexp(+∞ + i y) (y はゼロでない有限値)の場合、+∞ cis(y)を返却します。
cexp(-∞ + i ∞) の場合、±0.0 ± i 0.0 を返却します。結果の実部および虚部の符号は
不定です。
cexp(+∞ + i ∞) の場合、±∞ + i NaN を返却します。結果の実部の符号は不定です。
cexp(-∞ + i NaN) の場合、±0.0 ± i 0.0 を返却します。結果の実部および虚部の符号は
不定です。
cexp(+∞ + i NaN) の場合、±∞ + i NaN を返却します。結果の実部の符号は不定です。
cexp(NaN + i 0.0) の場合、NaN + i 0.0 を返却します。
cexp(NaN + i y) (y はゼロでなければ何でもよい)の場合、NaN + i NaN を返却します。浮
動小数点無効演算例外(invalid)を発生させるかどうかは任意です。
cexp(NaN + i NaN) の場合、NaN + i NaN を返却します。
7.3.7.2 clog 関数
【名前】
12 / 60
clog – 複素数対数関数
【形式】
#include <complex.h> double complex clog(double complex z); float complex clogf(float complex z); long double complex clogl(long double complex z);
【機能説明】
clog 関数は、底を e とする z の対数を求めます。
【戻り値】
clog 関数は、底を e とする対数を返却します。実軸は無限、虚軸は[-i π, +i π]の範囲に
あります。
【詳細】
clog(conj(z)) = conj(clog(z)) が成立します。
clog(-0.0 + i 0.0)の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発生して、-∞ + i
πを返却します。
clog(+0.0 + i 0.0)の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発生して、-∞ + i
0.0 を返却します。
clog(x + i ∞) (x は有限値)の場合、2πi+∞+ を返却します。
clog(+x + i NaN)の場合、浮動小数点無効演算例外(invalid)を発生して、NaN + i NaN を返
却します。
clog(-∞ + i y) (y > 0.0)の場合、+∞ + i πを返却します。
clog(+∞ + i y) (y > 0.0)の場合、+∞ + i 0.0 を返却します。
clog(-∞ + i ∞)の場合、4
3πi+∞+ を返却します。
clog(+∞ + i ∞)の場合、4πi+∞+ を返却します。
clog(NaN + i y) (y は有限値)の場合、浮動小数点無効演算例外(invalid)を発生して、NaN +
i NaN を返却します。
clog(NaN + i ∞)の場合、+∞ + i NaN を返却します。
clog(NaN + i NaN)の場合、NaN + i NaN を返却します。
13 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.3.8 7.3.8 7.3.8 7.3.8 べき乗関数及び絶対値関数べき乗関数及び絶対値関数べき乗関数及び絶対値関数べき乗関数及び絶対値関数
7.3.8.1 cabs 関数
【名前】
cabs – 複素数指数関数
【形式】
#include <complex.h> double cabs(double complex z); float cabsf(float complex z); long double cabsl(long double complex z);
【機能説明】
cabs 関数は、z の絶対値を求めます。
【戻り値】
cabs 関数は、z の絶対値を返却します。
【追加事項】
22)( yxiyxcabs +=+
7.3.8.2 cpow 関数
【名前】
cpow – 複素数べき乗関数
【形式】
#include <complex.h> double complex cpow(double complex x, double complex y); float complex cpowf(float complex x, float complex y); long double complex cpowl(long double complex x, long double complex y);
【機能説明】
cpow 関数は、べき乗 yx を求めます。
【戻り値】
cpow 関数は、引数のべき乗を返却します。
【詳細】
cpow 関数は、もし結果の一部の演算がそれにあたるならば浮動小数点例外を発生する。偽の
例外を発生させるかもしれない。
cpow(z, c)は、cexp(c, clog(z))に置き換えてもかまわない。
7.3.8.3 csqrt 関数
【名前】
csqrt – 複素数平方根関数
【形式】
#include <complex.h>
14 / 60
double complex csqrt(double complex z); float complex csqrtf(float complex z); long double complex csqrtl(long double complex z);
【機能説明】
csqrt 関数は、z の平方根を求めます。
【戻り値】
csqrt 関数は、平方根を返却します。
【詳細】
csqrt(conj(z)) = conj(csqrt(z)) が成立します。
csqrt(0.0 + i 0.0)の場合、-0.0 + i 0.0 を返却します。
csqrt(x + i ∞) (x は NaN を含むすべて)の場合、-∞ + i ∞を返却します。
csqrt(x + i NaN)(x は NaN を含むすべて)の場合、NaN + i NaN を返却します。浮動小数点
無効演算例外(invalid)を発生させるかどうかは任意です。
csqrt(-∞ + i y) (y > 0.0)の場合、+0.0 + i ∞を返却します。
csqrt(+∞ + i y) (y > 0.0)の場合、+∞ + i 0.0 を返却します。
csqrt(-∞ + i NaN)の場合、NaN ± i ∞を返却します。結果の虚部の符号は不定です。
csqrt(+∞ + i NaN)の場合、+∞ + i NaN を返却します。
csqrt(NaN + i y)(y は有限値)の場合、NaN + i NaN を返却します。浮動小数点無効演算例
外(invalid)を発生させるかどうかは任意です。
csqrt(NaN + i NaN)の場合、NaN + i NaN を返却します。
15 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.3.9 7.3.9 7.3.9 7.3.9 操作関数操作関数操作関数操作関数
7.3.9.1 carg 関数
【名前】
carg – 位相角関数
【形式】
#include <complex.h> double carg(double complex z); float cargf(float complex z); long double cargl(long double complex z);
【機能説明】
carg 関数は、z の角度(位相角)を求めます。
【戻り値】
carg 関数は、[-π, π]の範囲にある引数の値を返却します。
【詳細】
carg(x + i y) = atan2(y, x) が成立します。
7.3.9.2 cimag 関数
【名前】
cimag – 虚部の取得
【形式】
#include <complex.h> double cimag(double complex z); float cimagf(float complex z); long double cimagl(long double complex z);
【機能説明】
cimag 関数は、z の虚部を求めます。
【戻り値】
cimag 関数は、z の虚部を返却します。
7.3.9.3 conj 関数
【名前】
conj – 共益複素数関数
【形式】
#include <complex.h> double complex conj(double complex z); float complex conjf(float complex z); long double complex conjl(long double complex z);
【機能説明】
conj 関数は、z の虚部の符号を反転させた共益複素数を求めます。
【戻り値】
16 / 60
conj 関数は、z の共益複素数を返却します。
7.3.9.4 cproj 関数
【名前】
cproj – リ-マン面への投射関数
【形式】
#include <complex.h> double complex cproj(double complex z); float complex cprojf(float complex z); long double complex cprojl(long double complex z);
【機能説明】
cproj 関数は、リ-マン面への z の投射を求めます。
z の実部または虚部が Inf の場合、以下の計算式によって求められます。
INFINITY+I*copysign(0.0,cimag(z))
【戻り値】
cproj 関数は、リ-マン面への投射を返却します。
7.3.9.5 creal 関数
【名前】
creal – 実部の取得
【形式】
#include <complex.h> double creal(double complex z); float crealf(float complex z); long double creall(long double complex z);
【機能説明】
creal 関数は、z の実部を求めます。
【戻り値】
creal 関数は、z の実部を返却します。
17 / 60
ISO/IEC 9899:1999 ISO/IEC 9899:1999 ISO/IEC 9899:1999 ISO/IEC 9899:1999
7.6 7.6 7.6 7.6 浮浮浮浮動小数点環境動小数点環境動小数点環境動小数点環境 <fenv.h> <fenv.h> <fenv.h> <fenv.h>
7.6.0 7.6.0 7.6.0 7.6.0 マクロ及び型定義マクロ及び型定義マクロ及び型定義マクロ及び型定義
7.6.0.1 マクロ
・浮動小数点例外状態マクロ群。aexc ビットに対応させる。
マクロ名 説明 値(1) 値(2)
FE_INVALID 無効演算 1 << 9 0x00000200
FE_OVERFLOW オ-バフロ- 1 << 8 0x00000100
FE_UNDERFLOW アンダフロ-
1 << 7 0x00000080
FE_DIVBYZERO ゼロ除算 1 << 6 0x00000040
FE_INEXACT 結果不正確 1 << 5 0x00000020
FE_ALL_EXCEPT 全ての例外5 つ のマ ク ロの or
丸め方向マクロ群。いずれか一つのみ指定可能。RD ビットに対応させる。
マクロ名 説明 値(1) 値(2)
FE_TONEAREST 最近似 0 << 30 0x00000000
FE_TOWARDZERO ゼロ方向 1 << 30 0x40000000
FE_UPWARD +∞方向 2 << 30 0x80000000
FE_DOWNWARD -∞方向 3 << 30 0xc0000000
・fenv_t デフォルト値
※ (fenv_t *) 0 に設定する。(処理系依存)
マクロ名 説明 値
FE_DFL_ENV デフォルト値
(fenv_t *)0
7.6.0.2 型定義
・fenv_t を unsigned long int で宣言。
・fexcept_t を unsigned long int で宣言。
7.6.1 FENV_ACCESS pragma7.6.1 FENV_ACCESS pragma7.6.1 FENV_ACCESS pragma7.6.1 FENV_ACCESS pragma
18 / 60
7.6.2 7.6.2 7.6.2 7.6.2 浮動小数点例外浮動小数点例外浮動小数点例外浮動小数点例外
浮動小数点例外の状態フラグにアクセスするための関数を提供します。
7.6.2.1 feclearexcept 関数
【名前】
feclearexcept – 浮動小数点例外状態フラグのクリア
【形式】
#include <fenv.h> void feclearexcept(int excepts);
【機能説明】
feclearexcept 関数は、excepts に指定した浮動小数点例外状態フラグをクリアします。
excepts に指定した浮動小数点例外はそのまま保存します。excepts には 0 または以下のマ
クロまたはいずれかまたは複数のマクロのビットごとの論理和を指定することができます。
FE_INVALID 無効演算
FE_OVERFLOW オ-バフロ-
FE_UNDERFLOW アンダフロ-
FE_DIVBYZERO ゼロ除算
FE_INEXACT 結果不正確
FE_ALL_EXCEPT
【戻り値】
なし
7.6.2.2 fegetexceptflag 関数
【名前】
fegetexceptflag – 現在の浮動小数点例外状態フラグ
【形式】
#include <fenv.h> void fegetexceptflag(fexcept_t *flagp, int excepts);
【機能説明】
fegetexceptflag 関数は、*flag に現在の浮動小数点例外状態フラグを保存します。*flagp
には現在の浮動小数点例外状態フラグにexceptsに指定した浮動小数点例外を加えたものが
設定されます。excepts には 0 または以下のマクロまたはいずれかまたは複数のマクロのビ
ットごとの論理和を指定することができます。
FE_INVALID 無効演算
FE_OVERFLOW オ-バフロ-
FE_UNDERFLOW アンダフロ-
FE_DIVBYZERO ゼロ除算
FE_INEXACT 結果不正確
FE_ALL_EXCEPT
【戻り値】
なし
19 / 60
7.6.2.3 feraiseexcept 関数
【名前】
feraiseexcept – 浮動小数点例外の送信
【形式】
#include <fenv.h> void feraiseexcept(int excepts);
【機能説明】
feraiseexcept 関数は、excepts に指定した浮動小数点例外をプログラムに送信します。
excepts には 0 または以下のマクロまたはいずれか複数のマクロのビットごとの論理和を指
定することができます。
FE_INVALID 無効演算
FE_OVERFLOW オ-バフロ-
FE_UNDERFLOW アンダフロ-
FE_DIVBYZERO ゼロ除算
FE_INEXACT 結果不正確
FE_ALL_EXCEPT
【戻り値】
なし
7.6.2.4 fesetexceptflag 関数
【名前】
fesetexceptflag – 浮動小数点例外状態フラグの変更
【形式】
#include <fenv.h> void fesetexceptflag(const fexcept_t *flagp, int excepts);
【機能説明】
fesetexceptflag 関数は flagp のポインタ先の状態に excepts によって指定された浮動小数
点状態フラグを設定する。*flagp は少なくとも excepts に指定されている浮動小数点例外を
持つ第 2 引数を指定した fegetexceptflag を先に呼び出して設定しておいた方が良い。
fesetexceptflag 関数は、浮動小数点例外状態フラグを変更します。*flagp に excepts の浮
動小数点例外状態フラグを加えたものをシステムに設定します。excepts には、0 または以
下のマクロまたはいずれか複数のマクロのビットごとの論理和を指定することができます。
FE_INVALID 無効演算
FE_OVERFLOW オ-バフロ-
FE_UNDERFLOW アンダフロ-
FE_DIVBYZERO ゼロ除算
FE_INEXACT 結果不正確
FE_ALL_EXCEPT
【戻り値】
なし
20 / 60
7.6.2.5 fetestexcept 関数
【名前】
fetestexcept – 浮動小数点例外状態の調査
【形式】
#include <fenv.h> void fetestexcept (int excepts);
【機能説明】
fetestexcept 関数は、excepts に指定した浮動小数点例外について浮動小数点例外状態の調
査を行います。excepts に指定した浮動小数点例外の状態フラグがオンの場合、その例外マ
クロを返却します。適合するものが複数あった場合、結果は論理和で返却されます。excepts
には0または以下のマクロまたはいずれか複数のマクロのビットごとの論理和を指定するこ
とができます。
FE_INVALID 無効演算
FE_OVERFLOW オ-バフロ-
FE_UNDERFLOW アンダフロ-
FE_DIVBYZERO ゼロ除算
FE_INEXACT 結果不正確
FE_ALL_EXCEPT
【戻り値】
浮動小数点例外マクロです。複数の結果を持つ場合、そのマクロのビットごとの論理和です。
【例】
#include <stdio.h> #include <fenv.h> int main() { int f;
feclearexcept(FE_OVERFLOW | FE_UNDERFLOW); ... process ... ... may be raised overflow or underflow ... f = fetestexcept(FE_OVERFLOW | FE_UNDERFLOW); /* FE_OVERFLOW をチェック */ if(f & FE_OVERFLOW) printf(“OVERFLOW occurred. \n”); /* FE_UNDERFLOW をチェック */
if(f & FE_UNDERFLOW) printf(“UNDERFLOW occurred. \n”); }
21 / 60
ISO/IECISO/IECISO/IECISO/IEC 9899:1999 9899:1999 9899:1999 9899:1999
7.6.3 7.6.3 7.6.3 7.6.3 丸め丸め丸め丸め
丸め方向を制御するための関数を提供します。
7.6.3.1 fegetround 関数
【名前】
fegetround – 丸め方向の取得
【形式】
#include <fenv.h> int fegetround(void);
【機能説明】
fegetround 関数は、現在の丸め方向を取得します。
【戻り値】
以下のマクロのいずれかが返却されます。
FE_TONEAREST 最近似
FE_TOWARDZERO ゼロ方向
FE_UPWARD +∞方向
FE_DOWNWARD -∞方向
7.6.3.2 fesetround 関数
【名前】
fesetround – 丸め方向の設定
【形式】
#include <fenv.h> int fesetround(int round);
【機能説明】
fesetround 関数は、round に指定された現在の丸め方向を設定します。round は以下のマク
ロのいずれか一つを指定します。
FE_TONEAREST 最近似
FE_TOWARDZERO ゼロ方向
FE_UPWARD +∞方向
FE_DOWNWARD -∞方向
【戻り値】
引数がマクロのいずれかでもなかった場合 1 を返却します。
それ以外の場合は 0 を返却します。
22 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.6.4 7.6.4 7.6.4 7.6.4 環境環境環境環境
浮動小数点の演算環境を操作する関数を提供します。
7.6.4.1 fegetenv 関数
【名前】
fegetenv – 浮動小数点状態レジスタの取得
【形式】
#include <fenv.h> void fegetenv(fenv_t *envp);
【機能説明】
fegetenv 関数は、現在の浮動小数点状態レジスタ(%fsr)を*envp に保存します。
【戻り値】
なし。
7.6.4.2 feholdexcept 関数
【名前】
feholdexcept – 例外捕捉を除外した浮動小数点状態レジスタの取得
【形式】
#include <fenv.h> int feholdexcept(fenv_t *envp);
【機能説明】
feholdexcept 関数は、浮動小数点状態レジスタ(%fsr)を *envp に保存します。fegetenv(3C)
との違いは、浮動小数点の例外検出フラグ(TEM ビット:23-27 ビット)をクリアしたビット列
が保存されることです。
【戻り値】
常に、0 を返却します。
7.6.4.3 fesetenv 関数
【名前】
fesetenv – 浮動小数点状態レジスタの設定
【形式】
#include <fenv.h> void fesetenv(const fenv_t *envp);
【機能説明】
fesetenv 関数は、*envp の内容を浮動小数点状態レジスタ(%fsr)に設定します。
envp がマクロ FE_DFL_ENV だった場合、初期状態に戻します。
【戻り値】
なし。
23 / 60
【例】
一時的に浮動小数点例外から逃れる方法。 #include <fenv.h> int main() { int f; fenv_t fenv_save, fenv_hold;
if(!feholdenv(&fenv_save)) return -1; ... process ... ... May be occurred floating point exceptions, ... ... but the system doesn’t catch any floating point traps ... fesetenv(FE_DFL_DEFAULT); }
7.6.4.4 feupdateenv 関数
【名前】
feupdateenv – 浮動小数点状態レジスタの更新
【形式】
#include <fenv.h> void feupdateenv(const fenv_t *envp);
【機能説明】
feupdateenv 関数は、*envp の内容を浮動小数点状態レジスタ(%fsr)に設定します。
fesetenv(3C)との違いは、保存されている浮動小数点例外を発生させることです。
【戻り値】
なし。
24 / 60
ISO/IEC ISO/IEC ISO/IEC ISO/IEC 9899:19999899:19999899:19999899:1999
7.12.4 7.12.4 7.12.4 7.12.4 三角関数三角関数三角関数三角関数
7.12.4.1 acos 関数
【名前】
acos – 逆余弦関数
【形式】
#include <math.h> double acos(double x); float acosf(float x); long double acosl(long double x);
【機能説明】
acos 関数は、x の逆余弦を求めます。引数が[-1.0, 1.0]の範囲にない場合、エラ-が発生し
ます。
【戻り値】
acos 関数の結果は、[0, π]の範囲にある x の逆余弦です。
【詳細】
acos(1.0) の場合、+0.0 を返却します。
acos(x) (|x| > 1.0)の場合、浮動小数点無効演算例外(invalid)を発生して NaN を返却しま
す。
7.12.4.2 asin 関数
【名前】
asin – 逆正弦関数
【形式】
#include <math.h> double asin(double x); float asinf(float x); long double asinl(long double x);
【機能説明】
asin 関数は、x の逆正弦を求めます。引数が[-1.0, 1.0]の範囲にない場合、エラ-が発生し
ます。
【戻り値】
asin 関数の結果は、 ]2
,2
[ ππ +− の範囲にある x の逆正弦です。
【詳細】
asin(±0.0) の場合、±0.0 を返却します。
asin(x) (|x| > 1.0)の場合、浮動小数点無効演算例外(invalid)を発生して NaN を返却しま
す。
25 / 60
7.12.4.3 atan 関数
【名前】
atan – 逆正接関数
【形式】
#include <math.h> double atan(double x); float atanf(float x); long double atanl(long double x);
【機能説明】
atan 関数は、x の逆正接を求めます。
【戻り値】
atan 関数の結果は、 ]2
,2
[ ππ +− の範囲にある x の逆正接です。
【詳細】
atan(±0.0) の場合、±0.0 を返却します。
atan(±∞)の場合、2π± を返却します。
7.12.4.4 atan2 関数
【名前】
atan2 – 2 引数の逆正接関数
【形式】
#include <math.h> double atan2(double y, double x); float atan2f(float y, float x); long double atan2l(long double y, long double x);
【機能説明】
atan2 関数は、xy
の逆正接を求めます。引数の両方とも 0.0 の場合、エラ-となります。
【戻り値】
atan2 関数の結果は、[-π, +π]の範囲にあるxy
の逆正接です。
【詳細】
atan2(±0.0, -0.0) の場合、±πを返却します。
atan2(±0.0, +0.0)の場合、±0.0 を返却します。
atan2(±0.0, x) (x < 0.0)の場合、±πを返却します。
atan2(±0.0, x) (x > 0.0)の場合、±0.0 を返却します。
atan2(y, ±0.0) (y < 0.0)の場合、2π− を返却します。
26 / 60
atan2(y, ±0.0) (y > 0.0)の場合、2π
を返却します。
atan2(±y, -∞) (y > 0.0 の有限値)の場合、±πを返却します。
atan2(±y, +∞) (y > 0.0 の有限値)の場合、±0.0 を返却します。
atan2(±∞, x) (x は有限値)の場合、2π± を返却します。
atan2(±∞, -∞) の場合、4
3π± を返却します。
atan2(±∞, +∞) の場合、4π± を返却します。
7.12.4.5 cos 関数
【名前】
cos – 余弦関数
【形式】
#include <math.h> double cos(double x); float cosf(float x); long double cosl(long double x);
【機能説明】
cos 関数は、x の余弦を求めます。
【戻り値】
cos 関数の結果は、x の余弦です。
【詳細】
cos(±0.0) の場合、1.0 を返却します。
cos(±∞) の場合、浮動小数点無効演算例外(invalid)を発生して NaN を返却します。
7.12.4.6 sin 関数
【名前】
sin – 正弦関数
【形式】
#include <math.h> double sin(double x); float sinf(float x); long double sinl(long double x);
【機能説明】
sin 関数は、x の正弦を求めます。
【戻り値】
sin 関数の結果は、x の正弦です。
【詳細】
27 / 60
sin(±0.0) の場合、±0.0 を返却します。
sin(±∞) の場合、浮動小数点無効演算例外(invalid)を発生して NaN を返却します。
7.12.4.7 tan 関数
【名前】
tan – 正接関数
【形式】
#include <math.h> double tan(double x); float tanf(float x); long double tanl(long double x);
【機能説明】
tan 関数は、x の正接を求めます。
【戻り値】
tan 関数の結果は、x の正接です。
【詳細】
tan(±0.0) の場合、±0.0 を返却します。
tan(±∞) の場合、浮動小数点無効演算例外(invalid)を発生して NaN を返却します。
28 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.12.5 7.12.5 7.12.5 7.12.5 双曲線関数双曲線関数双曲線関数双曲線関数
7.12.5.1 acosh 関数
【名前】
acosh – 逆双曲線余弦関数
【形式】
#include <math.h> double acosh(double x); float acoshf(float x); long double acoshl(long double x);
【機能説明】
acosh 関数は、(非負の)x の逆双曲線余弦を求めます。引数が 1.0 より小さい場合エラ-が発
生します。
【戻り値】
acosh 関数の結果は、[0, +∞]の範囲にある x の逆双曲線余弦です。
【詳細】
acosh(1.0) の場合、+0.0 を返却します。
acosh(x) (x < 1.0) の場合、浮動小数点無効演算例外(invalid)を発生して NaN を返却しま
す。
acosh(+∞) の場合、+∞を返却します。
【補足】
)1x log(x acosh(x) 2 −+=
7.12.5.2 asinh 関数
【名前】
asinh – 逆双曲線正弦関数
【形式】
#include <math.h> double asinh(double x); float asinhf(float x); long double asinhl(long double x);
【機能説明】
asinh 関数は、x の逆双曲線正弦を求めます。
【戻り値】
asinh 関数の結果は、x の逆双曲線正弦です。
【詳細】
asinh(±0.0) の場合、±0.0 を返却します。
asinh(±∞) の場合、±∞を返却します。
29 / 60
【補足】
)1x |xlog(|*sign(x) asinh(x) 2 ++=
7.12.5.3 atanh 関数
【名前】
atanh – 逆双曲線正接関数
【形式】
#include <math.h> double atanh(double x); float atanhf(float x); long double atanhl(long double x);
【機能説明】
atanh 関数は、x の逆双曲線正接を求めます。引数 x が[-1, +1]の範囲にない場合、エラ-と
なります。引数が-1 および 1 のときもエラ-となります。
【戻り値】
atanh 関数の結果は、x の逆双曲線正接です。
【詳細】
atanh(±0.0)の場合、±0.0 を返却します。
atanh(±1.0)の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発生させた上で、±∞を
返却します。
atanh(x)で |x| > 1.0 のとき、浮動小数点無効演算例外(invalid)を発生させた上で、NaN
を返却します。
7.12.5.4 cosh 関数
【名前】
cosh – 双曲線余弦関数
【形式】
#include <math.h> double cosh(double x); float coshf(float x); long double coshl(long double x);
【機能説明】
cosh 関数は、双曲線余弦を求めます。x が大きいとき、エラ-が発生します。
【戻り値】
cosh 関数の結果は、x の双曲線余弦です。
【詳細】
cosh(±0.0) の場合、1.0 を返却します。
cosh(±∞) の場合、+∞を返却します。
30 / 60
7.12.5.5 sinh 関数
【名前】
sinh – 双曲線正弦関数
【形式】
#include <math.h> double sinh(double x); float sinhf(float x); long double sinhl(long double x);
【機能説明】
sinh 関数は、双曲線正弦を求めます。x が大きいとき、エラ-が発生します。
【戻り値】
sinh 関数の結果は、x の双曲線正弦です。
【詳細】
sinh(±0.0) の場合、±0.0 を返却します。
sinh(±∞) の場合、±∞を返却します。
7.12.5.6 tanh 関数
【名前】
tanh – 双曲線正接関数
【形式】
#include <math.h> double tanh(double x); float tanhf(float x); long double tanhl(long double x);
【機能説明】
tanh 関数は、双曲線正接を求めます。
【戻り値】
tanh 関数の結果は、x の双曲線正接です。
【詳細】
tanh(±0.0) の場合、±0.0 を返却します。
tanh(±∞) の場合、±1.0 を返却します。
31 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.12.6 7.12.6 7.12.6 7.12.6 指数関数指数関数指数関数指数関数
7.12.6.1 exp 関数
【名前】
exp – 指数関数
【形式】
#include <math.h> double exp(double x); float expf(float x); long double expl(long double x);
【機能説明】
exp 関数は、e を底とする指数関数の値を求めます。x の値が大きい場合、エラ-が発生しま
す。
【戻り値】
exp 関数の結果は、 xe です。
【詳細】
exp(±0.0)の場合、1.0 を返却します。
exp(-∞)の場合、+0.0 を返却します。
exp(+∞)の場合、+∞を返却します。
7.12.6.2 exp2 関数
【名前】
exp2 – 2 のべき乗関数
【形式】
#include <math.h> double exp2(double x); float exp2f(float x); long double exp2l(long double x);
【機能説明】
exp2 関数は、2 を底とするべき乗の値を求めます。x の値が大きい場合、エラ-が発生します。
【戻り値】
exp2 関数の結果は、 x2 です。
【詳細】
exp2(±0.0)の場合、1.0 を返却します。
exp2(-∞)の場合、+0.0 を返却します。
exp2(+∞)の場合、+∞を返却します。
7.12.6.3 expm1 関数
【名前】
32 / 60
expm1 – 1−xe
【形式】
#include <math.h> double expm1(double x); float expm1f(float x); long double expm1l(long double x);
【機能説明】
expm1 関数は、 xe から 1.0 を引いた値を求めます。x の値が大きい場合、エラ-が発生しま
す。
【戻り値】
expm1 関数の結果は、 1−xe です。
【詳細】
expm1(±0.0)の場合、±0.0 を返却します。
expm1(-∞)の場合、-1.0 を返却します。
expm1(+∞)の場合、+∞を返却します。
7.12.6.4 frexp 関数
【名前】
frexp – 指数部と小数部の分割
【形式】
#include <math.h> double frexp(double value, int *exp); float frexpf(float value, int *exp); long double frexpl(long double value, int *exp);
【機能説明】
frexp 関数は、引数の浮動小数点数を正規化数の小数部と 2 のべき部分に分割します。exp
によって示されたポインタの実体には、2 の整数べきが設定されます。
【戻り値】
value が浮動小数点の値でない場合、結果は不定となります。それ以外の場合、frexp 関数
は、絶対値が[1/2, 1.0]の範囲または 0.0 の値 x を返却します。ここで value は exp2*x で
表せるものとします。value がゼロの場合は結果の値もゼロとなります。
【詳細】
frexp(±0.0, exp)の場合、±0.0 を返却し、exp に指定されたポインタには 0 が設定される。
frexp(±∞, exp)の場合、±∞を返却し、exp に指定されたポインタには不定な値が設定さ
れる。
frexp(NaN, exp)の場合、NaN を返却し、exp に指定されたポインタには不定な値が設定され
る。
7.12.6.5 ilogb 関数
【名前】
33 / 60
ilogb – 指数部の取得
【形式】
#include <math.h> int ilogb(double x); int ilogbf(float x); int ilogbl(long double x);
【機能説明】
ilogb 関数は、符号付き整数の指数部分を求めます。x がゼロの場合、FP_ILOGB0 となります。
x が Inf のとき、INT_MAX となります。x が NAN のとき、FP_ILOGBNAN となります。それ以外
の場合は、logb 関数の結果を int 型でキャストした値となります。x が 0.0 のとき、エラ-
が発生します。
【戻り値】
ilogb 関数は、x の指数を符号付き int として返却します。
7.12.6.6 ldexp 関数
【名前】
ldexp – exp2*x
【形式】
#include <math.h> double ldexp(double x, int exp); float ldexpf(float x, int exp); long double ldexpl(long double x, int exp);
【機能説明】
ldexp 関数は、2 の exp 乗した値に x をかけた値を求めます。range error が発生する可能性
があります。
【戻り値】
ldexp 関数は、 exp2*x を返却します。
【詳細】
2 進を採用しているシステムでは、ldexp(x, exp)と scalbn(x, exp)は同じ値になります。
7.12.6.7 log 関数
【名前】
log – 自然対数関数
【形式】
#include <math.h> double log(double x); float logf(float x); long double logl(long double x);
【機能説明】
log 関数は、e を底とするすなわち自然対数の値を求めます。引数が負の場合、引数エラ-が
発生します。引数が 0.0 の場合、結果エラ-が発生します。
34 / 60
【戻り値】
log 関数の結果は、 )(log xe です。
【詳細】
log(±0.0)の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発生し、-∞を返却します。
log(1.0)の場合、+0.0 を返却します。
log(x) (x < 0) の場合、浮動小数点無効演算例外(invalid)を発生し、NaN を返却します。
log(+∞)の場合、+∞を返却します。
7.12.6.8 log10 関数
【名前】
log10 – 10 を底とする対数関数
【形式】
#include <math.h> double log10(double x); float log10f(float x); long double log10l(long double x);
【機能説明】
log10 関数は、10 を底とする対数の値を求めます。引数が負の場合、引数エラ-が発生しま
す。引数が 0.0 の場合、結果エラ-が発生します。
【戻り値】
log10 関数の結果は、 )(log10 x です。
【詳細】
log10(±0.0)の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発生し、-∞を返却しま
す。
log10(1.0)の場合、+0.0 を返却します。
log10(x) (x < 0) の場合、浮動小数点無効演算例外(invalid)を発生し、NaN を返却します。
log10(+∞)の場合、+∞を返却します。
7.12.6.9 log1p 関数
【名前】
log1p – )0.1(log xe +
【形式】
#include <math.h> double log1p(double x); float log1pf(float x); long double log1pl(long double x);
【機能説明】
log1p 関数は、引数に 1.0 を加えた値の底を e とした自然対数を求めます。引数が-1.0 より
小さい場合、domain error が発生します。引数が-1.0 の場合、range error が発生します。
【戻り値】
35 / 60
ldexp 関数は、 )0.1(log xe + を返却します。
【詳細】
log1p(±0.0)の場合、±0.0 を返却します。
log1p(-1.0)の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発生した上で、-∞を返却
します。
log1p(x)で x < -1.0 の場合、浮動小数点無効演算例外(invalid)を発生した上で、NaN を返
却します。
7.12.6.10 log2 関数
【名前】
log2 – 2 を底とする対数関数
【形式】
#include <math.h> double log2(double x); float log2f(float x); long double log2l(long double x);
【機能説明】
log2 関数は、2 を底とする対数の値を求めます。引数が負の場合、引数エラ-が発生します。
引数が 0.0 の場合、結果エラ-が発生します。
【戻り値】
log2 関数の結果は、 )(log2 x です。
【詳細】
log2(±0.0)の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発生し、-∞を返却します。
log2(1.0)の場合、+0.0 を返却します。
log2(x) (x < 0) の場合、浮動小数点無効演算例外(invalid)を発生し、NaN を返却します。
log2(+∞)の場合、+∞を返却します。
7.12.6.11 logb 関数
【名前】
logb – 指数部の取得
【形式】
#include <math.h> double logb(double x); float logbf(float x); long double logbl(long double x);
【機能説明】
logb 関数は、浮動小数点型の符号付き整数です x の指数部を求めます。x が非正規化数の場
合、x が正規化数のように扱います。正の有限数 x は、
RADIXFLTRADIXFLTx xb __*1 )(log <≤ −
を満たします。
36 / 60
引数が 0.0 の場合、domain error が発生します。
【戻り値】
logb 関数は、x の符号付き指数を返却します。
【詳細】
logb(±0.0)の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発生した上で、±∞を返
却します。
logb(±∞)の場合、+∞を返却します。
7.12.6.12 modf 関数
【名前】
modf – 浮動小数点値の分割
【形式】
#include <math.h> double modf(double value, double *iptr); float modff(float value, float *iptr); long double modfl(long double value, long double *iptr);
【機能説明】
modf 関数は、引数 value と同じ型および同じ符号を持つ整数部と小数部に分割します。整数
部は、iptr のポインタに示されたアドレスに設定されます。
【戻り値】
modf 関数の結果は、value の符号付きの小数部です。
【詳細】
modf(±x, iptr) の場合、x と同じ符号を返却します。
modf(±∞, iptr) の場合、±0.0 を返却し、iptr には±∞が設定される。
modf(NaN, iptr) の場合、NaN を返却し、iptr には NaN 設定される。
7.12.6.13 scalbn and scalbln 関数
【名前】
scalbn, scalbln – 基数べき乗関数
【形式】
#include <math.h> double scalbn(double x, int n); float scalbnf(float x, int n); long double scalbnl(long double x, int n); double scalbln(double x, long int n); float scalblnf(float x, long int n); long double scalblnl(long double x, long int n);
【機能説明】
scalbn 関数および scalbln 関数は、 nRADIXFLTx _* を求めます。
【戻り値】
scalbn 関数および scalbln 関数は、 nRADIXFLTx _* を返却します。
37 / 60
【詳細】
scalbn(±0.0, n)の場合、±0.0 を返却します。
scalbn(x, 0)の場合、x を返却します。
scalbn(±∞, n)の場合、±∞を返却します。
scalbln(±0.0, n)の場合、±0.0 を返却します。
scalbln(x, 0)の場合、x を返却します。
scalbln(±∞, n)の場合、±∞を返却します。
38 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.12.7 7.12.7 7.12.7 7.12.7 べき乗関数及び絶対値関数べき乗関数及び絶対値関数べき乗関数及び絶対値関数べき乗関数及び絶対値関数
7.12.7.1 cbrt 関数
【名前】
cbrt – 立方根関数
【形式】
#include <math.h> double cbrt(double x); float cbrtf(float x); long double cbrtl(long double x);
【機能説明】
cbrt 関数は、x の立方根を求めます。
【戻り値】
cbrt 関数の結果は、 31
x です。
【詳細】
cbrt(±0.0)の場合、±0.0 を返却します。
cbrt(±∞)の場合、±∞を返却します。
7.12.7.2 fabs 関数
【名前】
fabs – 絶対値関数
【形式】
#include <math.h> double fabs(double x); float fabsf(float x); long double fabsl(long double x);
【機能説明】
fabs 関数は、x の絶対値を求めます。
【戻り値】
fabs 関数の結果は、|x|です。
【詳細】
fabs(±0.0)の場合、+0.0 を返却します。
fabs(±∞)の場合、+∞を返却します。
7.12.7.3 hypot 関数
【名前】
hypot – ユークリッド距離関数
【形式】
39 / 60
#include <math.h> double hypot(double x, double y); float hypotf(float x, float y); long double hypotl(long double x, long double y);
【機能説明】
hypot 関数は、オ-バフロ-やアンダフロ-を発生させずに、x と y の平方したものの和の平方
根を求めます。range error が発生する可能性があります。
【戻り値】
hypot 関数は、 22 yx + を返却します。
【詳細】
hypot(x, y) = hypot(y, x) = hypot(x, -y)は成立します。
hypot(x, ±0.0)は、fabs(x)と同じです。
hypot(±∞, y)の場合、y が NaN であっても+∞を返却します。
7.12.7.4 pow 関数
【名前】
pow – べき乗関数
【形式】
#include <math.h> double pow(double x, double y); float powf(float x, float y); long double powl(long double x, long double y);
【機能説明】
pow関数は、xのyのべき乗を求めます。xがInfかつxが負かつyが非整数の場合domain error
が発生します。x がゼロおよび y がゼロまたはゼロより小さい場合、range error が発生し
ます。
【戻り値】
pow 関数は、 yx を返却します。
【詳細】
pow(±0.0, y) (y<0 で奇数の場合)の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発
生して、±∞を返却します。
pow(±0.0, y) (y<0 で奇数でない場合)の場合、浮動小数点ゼロ除算例外(divide-by-zero)
を発生して、+∞を返却します。
pow(±0.0, y) (y が正の奇数)の場合、±0.0 を返却します。
pow(±0.0, y) (y が正で奇数でない場合)の場合、+0.0 を返却します。
pow(-1.0, ±∞)の場合、1.0 を返却します。
pow(+1.0, x) (x は NaN であってもよい)の場合、1.0 を返却します。
pow(x, ±0.0) (x は NaN であってもよい)の場合、1.0 を返却します。
40 / 60
pow(x, y) (x が負で y が非整数)の場合、浮動小数点無効演算例外(invalid)を発生して、NaN
を返却します。
pow(x, -∞) (|x| < 1.0)の場合、+∞を返却します。
pow(x, -∞) (|x| > 1.0)の場合、+0.0 を返却します。
pow(x, +∞) (|x| < 1.0)の場合、+0.0 を返却します。
pow(x, +∞) (|x| > 1.0)の場合、+∞を返却します。
pow(-∞, y) (y が負の奇数)の場合、-0.0 を返却します。
pow(-∞, y) (y が負で奇数でない)の場合、+0.0 を返却します。
pow(-∞, y) (y が正の奇数)の場合、-∞を返却します。
pow(-∞, y) (y が正で奇数でない)の場合、+∞を返却します。
pow(+∞, y) (y < 0.0))の場合、+0.0 を返却します。
pow(+∞, y) (y> 0.0)の場合、+∞を返却します。
7.12.7.5 sqrt 関数
【名前】
sqrt – 平方根関数
【形式】
#include <math.h> double sqrt(double x); float sqrtf(float x); long double sqrtl(long double x);
【機能説明】
sqrt 関数は、非負の数値の x の平方根を求めます。引数がゼロよりも小さい場合、domain
error が発生します。
【戻り値】
sqrt 関数は、 x を返却します。
【詳細】
sqrt 関数は、IEC60559 において基本的な数値演算として定義されています。
41 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.12.8 7.12.8 7.12.8 7.12.8 エラー関数及びガンマ関数エラー関数及びガンマ関数エラー関数及びガンマ関数エラー関数及びガンマ関数
7.12.8.1 erf 関数
【名前】
erf - 誤差関数
【形式】
#include <math.h> double erf(double x); float erff(float x); long double erfl(long double x);
【機能説明】
erf 関数は x の誤差関数の値を求めます。
【戻り値】
erf 関数は、 � −x
0π
2 e t 2
dt を返却します。
【詳細】
erf(±0.0) の場合、±0.0 を返却します。
erf(±Inf) の場合、±1.0 を返却します。
7.12.8.2 erfc 関数
【名前】
erfc - 余誤差関数
【形式】
#include <math.h> double erfc(double x); float erfcf(float x); long double erfcl(long double x);
【機能説明】
erfc 関数は x の余誤差関数 1 - erf(x) の値を求めます。引数が大きすぎる場合、range error
が発生します。
【戻り値】
erfc 関数は、1 - erf(x) = �∞ −x e t 2
π
2 dt を返却します。
【詳細】
erfc(+Inf) の場合、+0.0 を返却します。
erfc(-Inf) の場合、+2.0 を返却します。
7.12.8.3 lgamma 関数
【名前】
42 / 60
lgamma - Γ関数の対数関数
【形式】
#include <math.h> double lgamma(double x); float lgammaf(float x); long double lgammal(long double x);
【機能説明】
lgamma 関数は、x のΓ関数の絶対値の自然対数を求めます。引数が大きすぎる場合、range
error が発生します。また、引数がゼロ以下の場合、range error を発生する可能性があり
ます。
【戻り値】
lgamma 関数は、 )(log xe
Γ を返却します。
【詳細】
lgamma(+1.0) の場合、+0.0 を返却します。
lgamma(+2.0) の場合、+0.0 を返却します。
lgamma(+x) (x が 0,0 または負の整数)の場合、浮動小数点ゼロ除算例外(divide-by-zero)
を発生し
て+Inf を返却します。
lgamma(-Inf) の場合、+Inf を返却します。
lgamma(+Inf) の場合、+Inf を返却します。
7.12.8.4 tgamma 関数
tgamma - Γ関数
【形式】
#include <math.h> double tgamma(double x); float tgammaf(float x); long double tgammal(long double x);
【機能説明】
tgamma 関数は、x のΓ関数を求めます。引数がゼロより小さい場合または引数がゼロで答え
を示すことができなかった場合、domain error を発生します。また、引数の絶対値が大きす
ぎたり小さすぎた場合、range error を発生する可能性があります。
【戻り値】
tgamma 関数は、Γ(x) を返却します。
【詳細】
tgamma(±0.0) の場合、浮動小数点ゼロ除算例外(divide-by-zero)を発生して±Inf
を返却します。
tgamma(x) (x が負の整数)の場合、浮動小数点無効演算例外(invalid)を発
43 / 60
生して NaN を返却します。
tgamma(-Inf) の場合、浮動小数点無効演算例外(invalid)を発生して NaN
を返却します。
tgamma(+Inf) の場合、+Inf を返却します。
44 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.12.9 7.12.9 7.12.9 7.12.9 近似整数関数近似整数関数近似整数関数近似整数関数
7.12.9.1 ceil 関数
【名前】
ceil - 引数以上で最小の整数
【形式】
#include <math.h> double ceil(double x); float ceilf(float x); long double ceill(long double x);
【機能説明】
ceil 関数は、x 以上で最小の整数値を求めます。
【戻り値】
ceil 関数は、浮動小数点数である � �x を返却します。
【詳細】
ceil(±0.0) の場合、±0.0 を返却します。
ceil(±Inf) の場合、±Inf を返却します。
7.12.9.2 floor 関数
【名前】
floor - 引数を超えない最大の整数
【形式】
#include <math.h> double floor(double x); float floorf(float x); long double floorl(long double x);
【機能説明】
floor 関数は、x を超えない最大の整数値を求めます。
【戻り値】
floor 関数は、浮動小数点数である � �x を返却します。
【詳細】
floor(±0.0) の場合、±0.0 を返却します。
floor(±Inf) の場合、±Inf を返却します。
7.12.9.3 nearbyint 関数
【名前】
nearbyint - 丸め方向を利用した整数化
【形式】
#include <math.h> double nearbyint(double x);
45 / 60
float nearbyintf(float x); long double nearbyintl(long double x);
【機能説明】
nearbyint 関数は、浮動小数点不正確例外(inexact)を発生させずに現在の丸め方向を使って、
浮動小数点数を整数にした値を求めます。
【戻り値】
nearbyint 関数は、整数値に丸めた値を返却します。
【詳細】
nearbyint 関数は、現在の丸め方向に従って IEC60559 rounding を利用する。結果が引数と
違っていても、浮動小数点不正確例外(inexact)は発生しない。
nearbyint(±0.0)の場合、すべての丸め方向で±0.0 を返却します。
nearbyint(±∞)の場合、すべての丸め方向で±∞を返却します。
7.12.9.4 rint 関数
【名前】
rint - 丸め方向を利用した整数化
【形式】
#include <math.h> double rint(double x); float rintf(float x); long double rintl(long double x);
【機能説明】
rint 関数が、nearbyint 関数(7.12.9.3)と異なる点は、結果が引数と値が異なる場合、浮動
小数点不正確例外(inexact)が発生することで、それ以外はすべて nearbyint 関数と同じで
す。
【戻り値】
rint 関数は、整数値に丸めた値を返却します。
【詳細】
rint 関数が、nearbyint 関数と異なる点は、結果が引数との間で値が異なる場合、浮動小数
点不正確例外(inexact)が発生することです。
7.12.9.5 lrint and llrint 関数
【名前】
lrint, llrint - 丸め方向を利用した整数化
【形式】
#include <math.h> long int lrint(double x); long int lrintf(float x); long int lrintl(long double x); long long int llrint(double x); long long int llrintf(float x); long long int llrintl(long double x);
46 / 60
【機能説明】
lrint 関数および llrint 関数は、現在の丸め方向に従ってもっとも近い整数値を求めます。
結果の値が、関数結果の型の範囲を超えていた場合、不定となります。x の絶対値が非常に
大きい場合、range error が発生する可能性があります。
【戻り値】
lrint 関数および llrint 関数は、整数値に丸めた値を返却します。
【詳細】
lrint 関数および llrint 関数は、IEC60779 によって規定されている浮動小数と整数変換を
提供する。これらは現在の丸め方向によって丸められる。結果の値が結果の型の範囲を超え
ていた場合、結果の値は不定で浮動小数点無効演算例外(invalid)を発生する。ほかの浮動
小数点例外が発生しないまたは結果が引数と異なる場合、浮動小数点不正確例外(inexact)
が発生する。
7.12.9.6 round 関数
【名前】
round - 整数化
【形式】
#include <math.h> double round(double x); float roundf(float x); long double roundl(long double x);
【機能説明】
round 関数は、引数を最近似へ整数化します。引数が halfway にいる場合、ゼロから離れた
方向へ丸めます。
【戻り値】
round 関数は、整数値に丸めた値を返却します。
【詳細】
round(±0.0)の場合、±0.0 を返却します。
round(±∞)の場合、±∞を返却します。
7.12.9.7 lround and llround 関数
【名前】
lround, lround - 丸め関数
【形式】
#include <math.h> long int lround(double x); long int lroundf(float x); long int lroundl(long double x); long long int llround(double x); long long int llroundf(float x); long long int llroundl(long double x);
47 / 60
【機能説明】
lround 関数および llround 関数は、引数を現在の丸め方向とは関係なく最近似へ整数化しま
す。真中(halfway cases = .5)の場合は、ゼロから遠い方へ丸めます。もし結果が関数結果
の型の範囲を超えていた場合、結果の値は不定となります。x の絶対値が非常に大きい場合
range error が発生する可能性があります。
【戻り値】
lround 関数および llround 関数は、整数値に丸めた値を返却します。
7.12.9.8 trunc 関数
【名前】
trunc - 切り捨て関数
【形式】
#include <math.h> double trunc(double x); float truncf(float x); long double truncl(long double x);
【機能説明】
trunc 関数は、引数の絶対値を越えない最近似の整数を求めます。
【戻り値】
trunc 関数は、整数値に切り捨てた値を返却します。
【詳細】
trunc 関数は、現在の丸め方向に関係なくゼロ方向に IEC60559 rounding を行う。
trunc(±0.0)の場合、±0.0 を返却します。
trunc (±∞)の場合、±∞を返却します。
48 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.12.10 7.12.10 7.12.10 7.12.10 剰余関数剰余関数剰余関数剰余関数
7.12.10.1 fmod 関数
【名前】
fmod – 剰余関数
【形式】
#include <math.h> double fmod(double x, double y); float fmodf(float x, float y); long double fmodl(long double x, long double y);
【機能説明】
fmod 関数は、xy
の余りを求めます。
【戻り値】
fmod 関数の結果は、x – n y を返却します。ここで n の値は、y がゼロでない場合、結果は
y の絶対値よりも小さく、x と同じ符号を持ちます。y がゼロの場合、引数エラ-または結果
ゼロと定義します。
【詳細】
fmod(±0.0, y) (y != 0.0)の場合、±0.0 を返却します。
fmod(x, y)で、x が Inf または y が 0.0 の場合、浮動小数点無効演算例外(invalid)を発生し
て、NaN を返却します。
fmod(x, ±∞) (x が Inf でない)の場合、x を返却します。
7.12.10.2 remainder 関数
【名前】
remainder - 丸め方向を利用した整数化
【形式】
#include <math.h> double remainder(double x, double y); float remainderf(float x, float y); long double remainderl(long double x, long double y);
【機能説明】
remainder 関数は、IEC60559 に定義される x REM y を計算します。
【戻り値】
remainder 関数は、x REM y を返却します。
【追加事項】
y≠0.0 のとき、余り r = x REM y は丸め方向に関係なく || nyxr −= で定義される。ここで
n は x / y の最近似の整数とする。しかし、21|| =−
yxn のとき、n は偶数とする。このよう
49 / 60
に余りはすべて正確とする。もし r=0.0 ですならば、x の符号と同じものでなければならな
い。
【詳細】
remainder 関数は、IEC60559 において基本的な数値演算として定義されています。
7.12.10.3 remquo 関数
【名前】
remquo – 剰余関数
【形式】
#include <math.h> double remquo(double x, double y, int *quo); float remquof(float x, float y, int *quo); long double remquol(long double x, long double y, int *quo);
【機能説明】
remquo 関数は、remainder 関数と同じように余りを求めます。
【戻り値】
remquo 関数は、x REM y を返却します。
【詳細】
remquo 関数は、remainder 関数の仕様を満たしています。
50 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.12.11 7.12.11 7.12.11 7.12.11 操作関数操作関数操作関数操作関数
7.12.11.1 copysign 関数
【名前】
copysign – 符号の設定
【形式】
#include <math.h> double copysign(double x, double y); float copysignf(float x, float y); long double copysignl(long double x, long double y);
【機能説明】
copysign 関数は、x の絶対値に y の符号を設定した値を求めます。
x が NaN の場合は、y の符号を持つ NaN を返却します。
【戻り値】
x の絶対値に y の符号を設定した値を返却します。
【実行論理】
x の符号ビットをマスク後に、y の符号とビットごとの論理和を取る。
7.12.11.2 nan 関数
【名前】
nan – 非数関数
【形式】
#include <math.h> double nan(const char *tagp); float nanf(const char *tagp); long double nanl(const char *tagp);
【機能説明】
nan 関数は、以下の条件で式を適用した値を返却します。
n-char-sequence 結果
文字列がある場合 strtod(“NAN(n-char-sequence)”, (char **)NULL)
“” strtod(“NAN()”, (char **)NULL) NULL strtod(“NAN”, (char **)NULL) nanf, nanl の場合は、それぞれ strtof, strtold を利用します。
【戻り値】
tagp に与えられた内容に応じて、tagp に与えられた内容を伴った qNaN を返却します。
処理系が qNaN をサポ-トしていない場合、0.0 を返却します。
【実行論理】
tagp != NULL の場合、strtod(“NAN(n-char-sequence), (char **)NULL); の復帰値を返却し
ます。
51 / 60
それ以外の場合は、strtod(“NAN”, (char **)NULL); の復帰値を返却します。
float, long double の場合は、それぞれ strtof, strtold を利用する。
7.12.11.3 nextafter 関数
【名前】
nextafter – y方向で次の値
【形式】
#include <math.h> double nextafter(double x, double y); float nextafterf(float x, float y); long double nextafterl(long double x, long double y);
【機能説明】
nextafter 関数は、y の方向で x の次の値を求めます。x が y 等しいとき、y を返却します。
x の絶対値が最大値で結果の値が Inf またはその型で表現できない場合、range error が発
生します。
【戻り値】
y 方向で x の次に出現する値を返却します。
【追加事項】
結果が Inf のとき、overflow と浮動小数点不正確例外(inexact)を発生させる。
結果が非正規化数(subnormal)のとき、underflow と浮動小数点不正確例外(inexact)を発生
させる。
【実行論理】
x または y が NaN のとき : x + y を返却します。
(a) x > y のとき、x を整数化したものをデクリメントする。
(b) x < y のとき、x を整数化したものをインクリメントする。
(a) および(b)の結果(r)のチェック
結果が Inf のとき : overflow と浮動小数点不正確例外(inexact)を発生させる : r + r を
返却します
結果が非正規化数(subnormal)のとき : underflow と浮動小数点不正確例外(inexact)を発
生させる : r * r を返却します
7.12.11.4 nexttoward 関数
【名前】
nexttoward – y方向で次の値
【形式】
#include <math.h> double nexttoward(double x, long double y); float nexttowardf(float x, long double y); long double nexttowardl(long double x, long double y);
【機能説明】
52 / 60
nexttoward 関数は、第二引数が long double 型であることを除けば nextafter と同等の機能
を提供します。x が y 等しければ、関数の型に変換した y を返却します。
【追加事項】
なし。
53 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.12.12 7.12.12 7.12.12 7.12.12 最大最大最大最大, , , , 最小及び正差関数最小及び正差関数最小及び正差関数最小及び正差関数
7.12.12.1 fdim 関数
【名前】
fdim – 超過分
【形式】
#include <math.h> double fdim(double x, double y); float fdimf(float x, float y); long double fdiml(long double x, long double y);
【機能説明】
fdim 関数は超過分を計算します。
x > y のときは x – y、それ以外のときは 0.0 を返却します。
【戻り値】
正の超過分です。
【実行論理】
isnan(x) が真
isnan(y) が真
isinf(x) && (y < 0 && isinf(y)) が真
x > y
上記条件のいずれかを満たした場合、x – y を返却します。
それ以外の場合は、0.0 を返却します。
7.12.12.2 fmax 関数
【名前】
fmax – 最大値関数
【形式】
#include <math.h> double fmax(double x, double y); float fmaxf(float x, float y); long double fmaxl(long double x, long double y);
【機能説明】
fmax 関数は x と y で大きい値を求めます。
x > y のときは x 、それ以外のときは y を返却します。
【戻り値】
x と y で大きい値を返却します。
一方が NaN、一方が数値であった場合は数値を返却します。両方が NaN
であった場合は、NaN を返却します。一方が+0.0、 一方が-0.0 であった場合、どちらであ
るかは不定です。
54 / 60
7.12.12.3 fmin 関数
【名前】
fmin – 最小値関数
【形式】
#include <math.h> double fmin (double x, double y); float fminf(float x, float y); long double fminl(long double x, long double y);
【機能説明】
fmin 関数は x と y で小さい値を求めます。
x < y のときは x 、それ以外のときは y を返却します。
【戻り値】
x と y で大きい値を返却します。
一方が NaN、一方が数値であった場合は数値を返却します。両方が NaN であった場合は NaN
を返却します。一方が+0.0、 一方が-0.0 であった場合、どちらであるかは不定です。
55 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.12.13 7.12.13 7.12.13 7.12.13 浮動小数点積和関数浮動小数点積和関数浮動小数点積和関数浮動小数点積和関数
7.12.13.1 fma 関数
【名前】
fma – 積和
【形式】
#include <math.h> double fma(double x, double y, double z); float fmaf(float x, float y, float z); long double fmal(long double x, long double y, long double z);
【機能説明】
fma 関数は、(x * y) + z を計算して返却します。結果の値は、Inf か FLT_ROUNDS の値に示
されている丸めモ-ドに従って一度だけ丸められた値になります。
【戻り値】
fma 関数は、(x * y) + z を一つの演算として丸められた値を返却します。
【追加事項】
fma(x, y, z)は、一度だけ丸めた x * y + z を返却します。
fma(x, y, z)は以下の場合、NaN を返却します。
- x または y のいずれかが Inf でもう一方がゼロかつ z が NaN のとき、浮動小数点無効演
算例外(invalid)を発生するかどうかは任意です。
- x または y のいずれかが Inf でもう一方がゼロかつ z が NaN でないとき、浮動小数点無
効演算例外(invalid)が発生します。
- x * y が Inf かつ z が Inf で両者の符号が互いに違うとき、浮動小数点無効演算例外
(invalid)が発生します。
56 / 60
ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999ISO/IEC 9899:1999
7.12.14 7.12.14 7.12.14 7.12.14 比較マクロ比較マクロ比較マクロ比較マクロ
7.12.14.1 isgreater マクロ
【名前】
isgreater – 比較(>)
【形式】
#include <math.h> int isgreater(real-floating x, real-floating y);
【機能説明】
isgreater マクロは、第一引数が第二引数より大きいかどうか調べるマクロです。一般的に、
(x) > (y)と同等の値になります。しかし、(x) > (y)と違うところは、x と y が比較不能
(unordered)のときに浮動小数点無効演算例外(invalid)を発生しないことです。
【戻り値】
(x) > (y) を返却します。
7.12.14.2 isgreaterequal マクロ
【名前】
isgreaterequal – 比較(>=)
【形式】
#include <math.h> int isgreaterequal(real-floating x, real-floating y);
【機能説明】
isgreaterequal マクロは、第一引数が第二引数以上かどうか調べるマクロです。一般的に、
(x) >= (y)と同等の値になります。しかし、(x) >= (y)と違うところは、x と y が比較不能
(unordered)のときに浮動少数点無効演算例外(invalid)を発生しないことです。
【戻り値】
(x) >= (y) を返却します。
7.12.14.3 isless マクロ
【名前】
isless – 比較(<)
【形式】
#include <math.h> int isless(real-floating x, real-floating y);
【機能説明】
isless マクロは、第一引数が第二引数より小さいかどうか調べるマクロです。一般的に、(x)
< (y)と同等の値になります。しかし、(x) < (y)と違うところは、xと yが比較不能(unordered)
のときに浮動小数点無効演算例外(invalid)を発生しないことです。
【戻り値】
57 / 60
(x) < (y) を返却します。
7.12.14.4 islessequal マクロ
【名前】
islessequal – 比較(<=)
【形式】
#include <math.h> int islessequal(real-floating x, real-floating y);
【機能説明】
islessequal マクロは、第一引数が第二引数以下かどうか調べるマクロです。一般的に、(x)
<= (y)と同等の値になります。しかし、(x) <= (y)と違うところは、x と y が比較不能
(unordered)のときに浮動小数点無効演算例外(invalid)を発生しないことです。
【戻り値】
(x) <= (y) を返却します。
7.12.14.5 islessgreater マクロ
【名前】
islessgreater – 比較(<=)
【形式】
#include <math.h> int islessgreater(real-floating x, real-floating y);
【機能説明】
islessgreater マクロは、第一引数が第二引数より大きいまたはより小さいかどうか調べる
マクロです。一般的に、(x) < (y) || (x) > (y) と同等の値になります。しかし、x と y
が比較不能(unordered)のときに浮動少数点無効演算例外(invalid)を発生しないことです。
x または y が二度評価されることもありません。
【戻り値】
(x) < (y) || (x) > (y) を返却します。
7.12.14.6 isunordered マクロ
【名前】
isunordered – 比較(<=)
【形式】
#include <math.h> int isunordered(real-floating x, real-floating y);
【機能説明】
isunordered マクロは、第一引数が第二引数が比較不能(unordered)かどうかを調べます。
【戻り値】
比較不能の場合 1、可能な場合は 0 を返却します。
58 / 60
付録付録付録付録 AAAA 浮動小数点のビットモデル浮動小数点のビットモデル浮動小数点のビットモデル浮動小数点のビットモデル
A.1 float(32bits)
s exponent(8) fraction(23)
31 30 23 22 0
#define FLT_RADIX 2 #define FLT_MANT_DIG 24 #define FLT_EPSILON 1.192092896E-07F #define FLT_DIG 6 #define FLT_MIN_EXP (-125) #define FLT_MIN 1.175494351E-38F #define FLT_MIN_10_EXP (-37) #define FLT_MAX_EXP (+128) #define FLT_MAX 3.402823466E+38F #define FLT_MAX_10_EXP (+38)
A.2 double(64bits)
s exponent(11) fraction(52)
63 62 52 51 32
fraction
31 0
#define DBL_MANT_DIG 53 #define DBL_EPSILON 2.2204460492503131E-16 #define DBL_DIG 15 #define DBL_MIN_EXP (-1021) #define DBL_MIN 2.2250738585072014E-308 #define DBL_MIN_10_EXP (-307) #define DBL_MAX_EXP (+1024) #define DBL_MAX 1.7976931348623157E+308 #define DBL_MAX_10_EXP (+308)
A.3 long double(128bits)
s exponent(15) fraction(112)
127 126 112 111 96
fraction
95 64
59 / 60
fraction
63 32
fraction
31 0
#define LDBL_MANT_DIG 113 #define LDBL_EPSILON 1.925929944387235853055977942584927319E-34L #define LDBL_DIG 33 #define LDBL_MIN_EXP (-16381) #define LDBL_MIN 3.362103143112093506262677817321752603E-4932L #define LDBL_MIN_10_EXP (-4931) #define LDBL_MAX_EXP (+16384) #define LDBL_MAX 1.189731495357231765085759326628007016E+4932L #define LDBL_MAX_10_EXP (+4932)
A.4 各型の特殊な値
名称 float double long double
+0 00000000 00000000 00000000 00000000 00000000 00000000 00000000
-0 80000000 80000000 00000000 80000000 00000000 00000000 00000000
+正規化された最大値 7f7fffff 7fefffff ffffffff 7ffeffff ffffffff ffffffff ffffffff
-正規化された最大値 ff7fffff ffefffff ffffffff fffeffff ffffffff ffffffff ffffffff
+正規化された最小値 00800000 00100000 00000000 00010000 00000000 00000000 00000000
-正規化された最小値 80800000 80100000 00000000 80010000 00000000 00000000 00000000
+正規化されていない最大値
007fffff 000fffff ffffffff 0000ffff ffffffff ffffffff ffffffff
-正規化されていない最大値
807fffff 800fffff ffffffff 8000ffff ffffffff ffffffff ffffffff
+正規化されていない最小値
00000001 00000000 00000001 00000000 00000000 00000000 00000001
-正規化されていない最小値
80000001 80000000 00000001 80000000 00000000 00000000 00000001
+Inf 7f800000 7ff00000 00000000 7fff0000 00000000 00000000 00000000
-Inf ff800000 fff00000 00000000 ffff0000 00000000 00000000 00000000
+qNaN 7fc00000 ~ 7fffffff
7ff80000 00000000 ~ 7fffffff ffffffff
7fff8000 00000000 00000000 00000000~ 7fffffff ffffffff ffffffff ffffffff
-qNaN ffc00000 ~ ffffffff
ff800000 00000000 ~ ffffffff ffffffff
ffff8000 00000000 00000000 00000000~ ffffffff ffffffff ffffffff ffffffff
+sNaN 7f800001 ~ 7fbfffff
7ff00000 00000001 ~ 7ff7ffff ffffffff
7fff0000 00000000 00000000 00000001 ~ 7ff7ffff ffffffff ffffffff ffffffff
-sNaN ff800001 ~ ffbfffff
fff00000 00000001 ~ fff7ffff ffffffff
ffff0000 00000000 00000000 00000001 ~ fff7ffff ffffffff ffffffff ffffffff
60 / 60
付録付録付録付録 BBBB 注意注意注意注意
B.1 cis
cis(y) = cos(y) + i sin(y) と定義されます。