「cpp/numeric/math/remquo」の版間の差分
提供: cppreference.com
(1人の利用者による、間の2版が非表示) | |||
1行: | 1行: | ||
− | {{cpp/title|remquo}} | + | {{cpp/title|remquo}} |
{{cpp/numeric/math/navbar}} | {{cpp/numeric/math/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
{{dcl header | cmath}} | {{dcl header | cmath}} | ||
{{dcl | since=c++11 |num=1| | {{dcl | since=c++11 |num=1| | ||
− | float remquo( float x, float y, int* quo ); | + | float remquo |
+ | ( float x, float y, int* quo ); | ||
}} | }} | ||
{{dcl | since=c++11 |num=2| | {{dcl | since=c++11 |num=2| | ||
− | double remquo( double x, double y, int* quo ); | + | double remquo ( double x, double y, int* quo ); |
}} | }} | ||
{{dcl | since=c++11 |num=3| | {{dcl | since=c++11 |num=3| | ||
− | long double remquo( long double x, long double y, int* quo ); | + | long double remquo |
+ | ( long double x, long double y, int* quo ); | ||
}} | }} | ||
{{dcl | since=c++11 | num=4| | {{dcl | since=c++11 | num=4| | ||
− | + | remquo ( 算術型1 x, 算術型2 y, int* quo ); | |
}} | }} | ||
{{dcl end}} | {{dcl end}} | ||
@1-3@ {{lc|std::remainder()}} 関数が行うように除算 {{c|x/y}} の浮動小数点剰余を計算します。 さらに、周期内の結果の象限を判定するのに十分な、 {{c|x/y}} の少なくとも3個の最後のビットと符号が {{c|quo}} に格納されます。 | @1-3@ {{lc|std::remainder()}} 関数が行うように除算 {{c|x/y}} の浮動小数点剰余を計算します。 さらに、周期内の結果の象限を判定するのに十分な、 {{c|x/y}} の少なくとも3個の最後のビットと符号が {{c|quo}} に格納されます。 | ||
− | @4@ 1-3 でカバーされない[[cpp/types/is_arithmetic|算術型]]の引数のすべての組み合わせに対するオーバーロード集合または関数テンプレート。 いずれかの非ポインタ引数が[[cpp/types/is_integral|整数型]]の場合、それは {{c|double}} にキャストされます。 他のいずれかの非ポインタ引数が {{c|long double}} の場合、戻り値型は {{c|long double}} になり、そうでなければ {{c|double}} になります。 | + | @4@ 1-3でカバーされない[[cpp/types/is_arithmetic|算術型]]の引数のすべての組み合わせに対するオーバーロード集合または関数テンプレート。 いずれかの非ポインタ引数が[[cpp/types/is_integral|整数型]]の場合、それは {{c|double}} にキャストされます。 他のいずれかの非ポインタ引数が {{c|long double}} の場合、戻り値型は {{c|long double}} になり、そうでなければ {{c|double}} になります。 |
===引数=== | ===引数=== | ||
38行: | 40行: | ||
===エラー処理=== | ===エラー処理=== | ||
− | + | |math_errhandlingで規定されている通りにエラーが報告されます。 | |
{{tt|y}} がゼロの場合は、定義域エラーが発生することがあります。 | {{tt|y}} がゼロの場合は、定義域エラーが発生することがあります。 | ||
65行: | 67行: | ||
const double pi = std::acos(-1); | const double pi = std::acos(-1); | ||
double cos_pi_x_naive(double x) { return std::cos(pi * x); } | double cos_pi_x_naive(double x) { return std::cos(pi * x); } | ||
− | // | + | // (0;0.5) (0.5;1.5) (1.5,2) |
double cos_pi_x_smart(double x) | double cos_pi_x_smart(double x) | ||
{ | { | ||
int quadrant; | int quadrant; | ||
double rem = std::remquo(x, 1, &quadrant); | double rem = std::remquo(x, 1, &quadrant); | ||
− | quadrant = (unsigned)quadrant % 2; // | + | quadrant = (unsigned)quadrant % 2; // |
switch(quadrant) { | switch(quadrant) { | ||
case 0: return std::cos(pi * rem); | case 0: return std::cos(pi * rem); | ||
92行: | 94行: | ||
<< "cos(pi * 1000000000001.25) = " | << "cos(pi * 1000000000001.25) = " | ||
<< cos_pi_x_smart(1000000000001.25) << '\n'; | << cos_pi_x_smart(1000000000001.25) << '\n'; | ||
− | // | + | // |
std::feclearexcept(FE_ALL_EXCEPT); | std::feclearexcept(FE_ALL_EXCEPT); | ||
int quo; | int quo; | ||
122行: | 124行: | ||
{{dsc end}} | {{dsc end}} | ||
− | + | deenesfritptruzh | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
2018年12月5日 (水) 14:58時点における最新版
ヘッダ <cmath> で定義
|
||
float remquo ( float x, float y, int* quo ); float remquof( float x, float y, int* quo ); |
(1) | (C++11以上) |
double remquo ( double x, double y, int* quo ); |
(2) | (C++11以上) |
long double remquo ( long double x, long double y, int* quo ); long double remquol( long double x, long double y, int* quo ); |
(3) | (C++11以上) |
昇格後の型 remquo ( 算術型1 x, 算術型2 y, int* quo ); |
(4) | (C++11以上) |
1-3) std::remainder() 関数が行うように除算 x/y の浮動小数点剰余を計算します。 さらに、周期内の結果の象限を判定するのに十分な、 x/y の少なくとも3個の最後のビットと符号が quo に格納されます。
4) (1-3) でカバーされない算術型の引数のすべての組み合わせに対するオーバーロード集合または関数テンプレート。 いずれかの非ポインタ引数が整数型の場合、それは double にキャストされます。 他のいずれかの非ポインタ引数が long double の場合、戻り値型は long double になり、そうでなければ double になります。
目次 |