diff --git a/reference/cmath/abs.md b/reference/cmath/abs.md index 4f35a45bf..1505b65f0 100644 --- a/reference/cmath/abs.md +++ b/reference/cmath/abs.md @@ -6,15 +6,25 @@ ```cpp namespace std { - float abs(float x); // (1) - double abs(double x); // (2) - long double abs(long double x); // (3) + float abs(float x); // (1) C++03からC++20まで - double abs(Integral x); // (4) C++11 から C++14 まで + double abs(double x); // (2) C++03からC++20まで - int abs(int x); // (5) C++17 から - long abs(long int x); // (6) C++17 から - long long abs(long long x); // (7) C++17 から + long double abs(long double x); // (3) C++03からC++20まで + + constexpr floating-point-type + abs(floating-point-type x); // (4) C++23 + + double abs(Integral x); // (5) C++11 から C++14 まで + + int abs(int x); // (6) C++17 + constexpr int abs(int x); // (6) C++23 + + long abs(long int x); // (7) C++17 + constexpr long abs(long int x); // (7) C++23 + + long long abs(long long x); // (8) C++17 + constexpr long long abs(long long x); // (8) C++23 } ``` * Integral[italic] @@ -22,6 +32,15 @@ namespace std { ## 概要 浮動小数点数型の絶対値を求める。abs は absolute value(絶対値)の略。 +- (1) : `float`に対するオーバーロード +- (2) : `double`に対するオーバーロード +- (3) : `long double`に対するオーバーロード +- (4) : 浮動小数点数型に対するオーバーロード +- (5) : 整数型に対するオーバーロード (`double`にキャストして計算される) +- (6) : `int`に対するオーバーロード +- (7) : `long int`に対するオーバーロード +- (8) : `long long`に対するオーバーロード + ## 戻り値 引数 `x` の絶対値を返す。 @@ -31,7 +50,8 @@ namespace std { ## 備考 - $$ f(x) = | x | $$ -- 任意の整数型に対するオーバーロード(4)は C++11 で追加されたが、[一部の符号なし整数型に対して問題を引き起こす](http://wg21.cmeerw.net/lwg/issue2192)ことから C++17 で削除され、符号付き整数型に対するオーバーロード(5),(6),(7)が追加された。 +- 任意の整数型に対するオーバーロード(5)は C++11 で追加されたが、[一部の符号なし整数型に対して問題を引き起こす](http://wg21.cmeerw.net/lwg/issue2192)ことから C++17 で削除され、符号付き整数型に対するオーバーロード(6),(7),(8)が追加された +- C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された ## 例 @@ -76,3 +96,10 @@ namespace std { } } ``` + + +## 参照 +- [P0533R9 constexpr for `` and ``](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0533r9.pdf) + - C++23での、一部関数の`constexpr`対応 +- [P1467R9 Extended floating-point types and standard names](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html) + - C++23で導入された拡張浮動小数点数型への対応として、`float`、`double`、`long double`のオーバーロードを`floating-point-type`のオーバーロードに統合し、拡張浮動小数点数型も扱えるようにした diff --git a/reference/cmath/frexp.md b/reference/cmath/frexp.md index edef8a649..27e351ad4 100644 --- a/reference/cmath/frexp.md +++ b/reference/cmath/frexp.md @@ -5,25 +5,46 @@ ```cpp namespace std { - float frexp(float value, int* exp); - double frexp(double value, int* exp); - long double frexp(long double value, int* exp); - - double frexp(Integral value, int* exp); // C++11 から - - float frexpf(float value, int* exp); // C++17 から - long double frexpl(long double value, int* exp); // C++17 から + float frexp(float value, int* exp); // (1) C++03からC++20まで + double frexp(double value, int* exp); // (2) C++03からC++20まで + long double frexp(long double value, int* exp); // (3) C++03からC++20まで + + constexpr floating-point-type + frexp(floating-point-type value, int* exp); // (4) C++23 + + double + frexp(Integral value, int* exp); // (5) C++11 + constexpr double + frexp(Integral value, int* exp); // (5) C++23 + + float + frexpf(float value, int* exp); // (6) C++17 + constexpr float + frexpf(float value, int* exp); // (6) C++23 + + long double + frexpl(long double value, int* exp); // (7) C++17 + constexpr long double + frexpl(long double value, int* exp); // (7) C++23 } ``` * Integral[italic] ## 概要 -`frexp`関数 (fraction and exponent)は、浮動小数点数`value`を、正規化された仮数部と 2 の累乗へ分解する。 +`frexp`関数 (fraction and exponent) は、浮動小数点数`value`を、正規化された仮数部と 2 の累乗へ分解する。 この関数は、与えられた浮動小数点数`value`を仮数部と指数部に分解し、仮数部を戻り値で返し、指数を`*exp`に書き込んで返す。 この関数と反対に、[`std::ldexp()`](ldexp.md)関数を使用することで、仮数部と指数部の値から浮動小数点数を作り出せる。 +- (1) : `float`に対するオーバーロード +- (2) : `double`に対するオーバーロード +- (3) : `long double`に対するオーバーロード +- (4) : 浮動小数点数型に対するオーバーロード +- (5) : 整数型に対するオーバーロード (`double`にキャストして計算される) +- (6) : `float`型規定 +- (7) : `long double`型規定 + ## 戻り値 引数 `value` が浮動小数点数ではない、もしくは2の乗数が `int` の範囲外である場合、戻り値は未規定。 @@ -39,7 +60,8 @@ C++11 以降では、処理系が IEC 60559 に準拠している場合([`std: - `value = ±0` の場合、戻り値は `±0` となり、`*exp` にはゼロが設定される。 - `value = ±∞` の場合、戻り値は `±∞` となり、`*exp` には未規定の値が設定される。 - `value` が NaN の場合、戻り値は NaN となり、`*exp` には未規定の値が設定される。 -- `frexp` は浮動小数点例外を全く発生させない。 +- この関数は浮動小数点例外を発生させない。 +- C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された ## 例 @@ -68,4 +90,7 @@ int main() ## 参照 - [Why does `frexp()` not yield scientific notation?](http://stackoverflow.com/questions/24928833/why-does-frexp-not-yield-scientific-notation) - `frexp()`が戻り値を`[1, 2)`の範囲ではなく、`[0.5, 1)`の範囲に収めるようにしている理由は、IEEE 754およびISO/IEC 60559が策定される前に作られた関数であることが理由と考えられる - +- [P0533R9 constexpr for `` and ``](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0533r9.pdf) + - C++23での、一部関数の`constexpr`対応 +- [P1467R9 Extended floating-point types and standard names](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html) + - C++23で導入された拡張浮動小数点数型への対応として、`float`、`double`、`long double`のオーバーロードを`floating-point-type`のオーバーロードに統合し、拡張浮動小数点数型も扱えるようにした diff --git a/reference/cmath/ilogb.md b/reference/cmath/ilogb.md index 7822ca28d..7c1faa8e7 100644 --- a/reference/cmath/ilogb.md +++ b/reference/cmath/ilogb.md @@ -6,14 +6,27 @@ ```cpp namespace std { - int ilogb(float); - int ilogb(double); - int ilogb(long double); + int ilogb(float x); // (1) C++11からC++20まで + int ilogb(double x); // (2) C++11からC++20まで + int ilogb(long double x); // (3) C++11からC++20まで - int ilogb(Integral); + constexpr int + ilogb(floating-point-type x); // (3) C++23 - int ilogbf(float x); // C++17 から - int ilogbl(long double x); // C++17 から + int + ilogb(Integral); // (4) C++11 + constexpr int + ilogb(Integral); // (4) C++23 + + int + ilogbf(float x); // (5) C++17 + constexpr int + ilogbf(float x); // (5) C++23 + + int + ilogbl(long double x); // (6) C++17 + constexpr int + ilogbl(long double x); // (6) C++23 } ``` * Integral[italic] @@ -21,6 +34,14 @@ namespace std { ## 概要 `ilogb`関数(integer log binary)は、浮動小数点数 `x` の指数部を `int` として返す。 +- (1) : `float`に対するオーバーロード +- (2) : `double`に対するオーバーロード +- (3) : `long double`に対するオーバーロード +- (4) : 浮動小数点数型に対するオーバーロード +- (5) : 整数型に対するオーバーロード (`double`にキャストして計算される) +- (6) : `float`型規定 +- (7) : `long double`型規定 + ## 戻り値 `x` がゼロの場合は [`FP_ILOGB0`](fp_ilogb0.md) を、無限大の場合は [`INT_MAX`](/reference/climits/int_max.md) を、`NaN` の場合は [`FP_ILOGBNAN`](fp_ilogbnan.md) を返す。 @@ -34,6 +55,7 @@ namespace std { - 正しい結果が戻り値の型(`int`)の範囲で表現可能な場合は、戻り値は正確で、現在の丸め方式に依存しない。 - 正しい結果が戻り値の型(`int`)の範囲外の場合は、戻り値は未規定で、[`FE_INVALID`](../cfenv/fe_invalid.md)(無効演算浮動小数点例外)が発生する。 - `x` がゼロ、無限大、あるいは NaN の場合には、[`FE_INVALID`](../cfenv/fe_invalid.md)(無効演算浮動小数点例外)が発生する。 +- C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された ## 例 @@ -74,3 +96,10 @@ ilogb(1e-309) = -1027 - [GCC](/implementation.md#gcc): 4.3.6 - [ICC](/implementation.md#icc): ?? - [Visual C++](/implementation.md#visual_cpp): ?? + + +## 参照 +- [P0533R9 constexpr for `` and ``](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0533r9.pdf) + - C++23での、一部関数の`constexpr`対応 +- [P1467R9 Extended floating-point types and standard names](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html) + - C++23で導入された拡張浮動小数点数型への対応として、`float`、`double`、`long double`のオーバーロードを`floating-point-type`のオーバーロードに統合し、拡張浮動小数点数型も扱えるようにした diff --git a/reference/cmath/ldexp.md b/reference/cmath/ldexp.md index 188760182..c8e973c15 100644 --- a/reference/cmath/ldexp.md +++ b/reference/cmath/ldexp.md @@ -5,14 +5,27 @@ ```cpp namespace std { - float ldexp(float x, int exp); - double ldexp(double x, int exp); - long double ldexp(long double x, int exp); - - double ldexp(Integral x, int exp); // C++11 から - - float ldexpf(float x, int exp); // C++17 から - long double ldexpl(long double x, int exp); // C++17 から + float ldexp(float x, int exp); // (1) C++03からC++20まで + double ldexp(double x, int exp); // (2) C++03からC++20まで + long double ldexp(long double x, int exp); // (3) C++03からC++20まで + + constexpr floating-point-type + ldexp(floating-point-type x, int exp); // (4) C++23 + + double + ldexp(Integral x, int exp); // (5) C++11 + constexpr double + ldexp(Integral x, int exp); // (5) C++23 + + float + ldexpf(float x, int exp); // (6) C++17 + constexpr float + ldexpf(float x, int exp); // (6) C++23 + + long double + ldexpl(long double x, int exp); // (7) C++17 + constexpr long double + ldexpl(long double x, int exp); // (7) C++23 } ``` * Integral[italic] @@ -24,6 +37,14 @@ namespace std { この関数と反対に、[`std::frexp()`](frexp.md)関数を使用することで、浮動小数点数を仮数部と指数部に分解できる。 +- (1) : `float`に対するオーバーロード +- (2) : `double`に対するオーバーロード +- (3) : `long double`に対するオーバーロード +- (4) : 浮動小数点数型に対するオーバーロード +- (5) : 整数型に対するオーバーロード (`double`にキャストして計算される) +- (6) : `float`型規定 +- (7) : `long double`型規定 + ## 戻り値 x * 2exp @@ -34,6 +55,7 @@ namespace std { ## 備考 - オーバーフローエラー、アンダーフローエラーが発生した場合の挙動については、[``](../cmath.md) を参照。 - C++11 以降では、処理系が IEC 60559 に準拠している場合([`std::numeric_limits`](../limits/numeric_limits.md)`::`[`is_iec559`](../limits/numeric_limits/is_iec559.md)`() != false`)、かつ、基数が 2 の場合([`std::numeric_limits`](../limits/numeric_limits.md)`::`[`radix`](../limits/numeric_limits/radix.md)`() == 2`)、[`scalbn`](scalbn.md)`(x, exp)` と等価である。 +- C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された ## 例 @@ -89,3 +111,9 @@ namespace std { } ``` * std::pow[link pow.md] + +## 参照 +- [P0533R9 constexpr for `` and ``](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0533r9.pdf) + - C++23での、一部関数の`constexpr`対応 +- [P1467R9 Extended floating-point types and standard names](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html) + - C++23で導入された拡張浮動小数点数型への対応として、`float`、`double`、`long double`のオーバーロードを`floating-point-type`のオーバーロードに統合し、拡張浮動小数点数型も扱えるようにした