Skip to content

Commit

Permalink
<cmath> : 残りのconstexpr対応 #1067
Browse files Browse the repository at this point in the history
  • Loading branch information
faithandbrave committed Feb 16, 2023
1 parent 019f15e commit be98598
Show file tree
Hide file tree
Showing 36 changed files with 1,307 additions and 271 deletions.
14 changes: 7 additions & 7 deletions reference/cmath.md
Expand Up @@ -255,13 +255,13 @@ C++03 までの場合、[`errno`](cerrno/errno.md) でしか通知されない

| 名前 | 説明 | 対応バージョン |
|-----------|----------------------------------|-------|
| [`ldexp`](cmath/ldexp.md) | 2 の累乗との乗算 | |
| [`frexp`](cmath/frexp.md) | 仮数部と 2 の累乗への分解 | |
| [`ilogb`](cmath/ilogb.md) | 指数部を符号付き整数値として抽出 | C++11 |
| [`logb`](cmath/logb.md) | 指数部を浮動小数点数値として抽出 | C++11 |
| [`modf`](cmath/modf.md) | 整数部と小数部への分解 | |
| [`scalbn`](cmath/scalbn.md) | 内部表現の基数 (`FLT_RADIX`) の累乗との乗算 | C++11 |
| [`scalbln`](cmath/scalbn.md) | 内部表現の基数 (`FLT_RADIX`) の累乗との乗算 | C++11 |
| [`ldexp`](cmath/ldexp.md) | 2 の累乗との乗算 | |
| [`frexp`](cmath/frexp.md) | 仮数部と 2 の累乗への分解 | |
| [`ilogb`](cmath/ilogb.md) | 指数部を符号付き整数値として抽出 | C++11 |
| [`logb`](cmath/logb.md) | 指数部を浮動小数点数値として抽出 | C++11 |
| [`modf`](cmath/modf.md) | 整数部と小数部への分解 | |
| [`scalbn`](cmath/scalbn.md) | 内部表現の基数 (`FLT_RADIX`) の累乗との乗算 | C++11 |
| [`scalbln`](cmath/scalbln.md) | 内部表現の基数 (`FLT_RADIX`) の累乗との乗算。乗数として`long`をとる | C++11 |


## <a id="power-and-absolute-value-functions" href="#power-and-absolute-value-functions">累乗・冪根と絶対値</a>
Expand Down
2 changes: 1 addition & 1 deletion reference/cmath/abs.md
Expand Up @@ -75,7 +75,7 @@ abs(-1.5) = 1.500000
```

### 備考
特定の環境で `constexpr` 指定されている場合がある。(独自拡張)
特定の環境では、早期に `constexpr` 対応されている場合がある:

- GCC 4.6.1 以上

Expand Down
45 changes: 37 additions & 8 deletions reference/cmath/ceil.md
Expand Up @@ -5,21 +5,42 @@

```cpp
namespace std {
float ceil(float x);
double ceil(double x);
long double ceil(long double x);

double ceil(Integral x); // C++11 から

float ceilf(float x); // C++17 から
long double ceill(long double x); // C++17 から
float ceil(float x); // (1) C++03からC++20まで
double ceil(double x); // (2) C++03からC++20まで
long double ceil(long double x); // (3) C++03からC++20まで

constexpr floating-point-type
ceil(floating-point-type x); // (4) C++23

double
ceil(Integral x); // (5) C++11
constexpr double
ceil(Integral x); // (5) C++23

float
ceilf(float x); // (6) C++17
constexpr float
ceilf(float x); // (6) C++17

long double
ceill(long double x); // (7) C++17
constexpr long double
ceill(long double x); // (7) C++17
}
```
* Integral[italic]
## 概要
引数 `x` 以上で最小の整数値を得る。(天井関数)
- (1) : `float`に対するオーバーロード
- (2) : `double`に対するオーバーロード
- (3) : `long double`に対するオーバーロード
- (4) : 浮動小数点数型に対するオーバーロード
- (5) : 整数型に対するオーバーロード (`double`にキャストして計算される)
- (6) : `float`型規定
- (7) : `long double`型規定
## 戻り値
引数 `x` 以上で最小の整数値
Expand All @@ -35,6 +56,7 @@ namespace std {
また、本関数の挙動は、丸めモードが [`FE_UPWARD`](/reference/cfenv/fe_upward.md) に設定されている時の [`rint`](rint.md)、あるいは [`nearbyint`](nearbyint.md) のいずれかと等価である。
したがって、本関数において戻り値が引数 `x` と異なる場合に例外 [`FE_INEXACT`](/reference/cfenv/fe_inexact.md) が発生するか否かは実装依存である。
なお、本関数の挙動は、現在の丸めモードには依存しない。
- C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された
## 例
Expand Down Expand Up @@ -97,3 +119,10 @@ FE_INEXACT = true
```

引数と結果が異なる場合に例外 `FE_INEXACT` が発生するか否かは実装によって異なる。


## 参照
- [P0533R9 constexpr for `<cmath>` and `<cstdlib>`](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`のオーバーロードに統合し、拡張浮動小数点数型も扱えるようにした
62 changes: 52 additions & 10 deletions reference/cmath/copysign.md
Expand Up @@ -6,21 +6,55 @@

```cpp
namespace std {
double copysign(double x, double y);
float copysign(float x, float y);
long double copysign(long double x, long double y);

Integral copysign(Integral x, Integral y);

float copysignf(float x, float y); // C++17 から
long double copysignl(long double x, long double y); // C++17 から
float
copysign(float x,
float y); // (1) C++11からC++20まで
double
copysign(double x,
double y); // (2) C++11からC++20まで
long double
copysign(long double x,
long double y); // (3) C++11からC++20まで

constexpr floating-point-type
copysign(floating-point-type x,
floating-point-type y); // (4) C++23

Integral
copysign(Integral x
Integral y); // (5) C++11
constexpr Integral
copysign(Integral x
Integral y); // (5) C++23

float
copysignf(float x,
float y); // (6) C++17
constexpr float
copysignf(float x,
float y); // (6) C++23

long double
copysignl(long double x,
long double y); // (7) C++17
constexpr long double
copysignl(long double x,
long double y); // (7) C++23
}
```
* Integral[italic]
## 概要
`x`の絶対値に`y`の符号が付いた値を生成する。
- (1) : `float`に対するオーバーロード
- (2) : `double`に対するオーバーロード
- (3) : `long double`に対するオーバーロード
- (4) : 浮動小数点数型に対するオーバーロード
- (5) : 整数型に対するオーバーロード (`double`にキャストして計算される)
- (6) : `float`型規定
- (7) : `long double`型規定
## 戻り値
`x`の絶対値に`y`の符号が付いた値を返す。
Expand All @@ -29,7 +63,8 @@ namespace std {
## 備考
符号付きゼロを表現するが負のゼロを取り扱わない実装では、この関数はゼロを正と見なす。
- 符号付きゼロを表現するが負のゼロを取り扱わない実装では、この関数はゼロを正と見なす。
- C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された
## 例
Expand All @@ -55,7 +90,7 @@ int main()
```

### 備考
特定の環境で `constexpr` 指定されている場合がある。(独自拡張)
特定の環境では、早期に `constexpr` 対応されている場合がある:

- GCC 4.6.1 以上

Expand Down Expand Up @@ -102,3 +137,10 @@ namespace std {
- [GCC](/implementation.md#gcc): 4.3
- [ICC](/implementation.md#icc): ??
- [Visual C++](/implementation.md#visual_cpp): ??
## 参照
- [P0533R9 constexpr for `<cmath>` and `<cstdlib>`](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`のオーバーロードに統合し、拡張浮動小数点数型も扱えるようにした
46 changes: 37 additions & 9 deletions reference/cmath/fabs.md
Expand Up @@ -6,21 +6,42 @@

```cpp
namespace std {
float fabs(float x);
double fabs(double x);
long double fabs(long double x);

double fabs(Integral x); // C++11 から

float fabsf(float x); // C++17 から
long double fabsl(long double x); // C++17 から
float fabs(float x); // (1) C++03からC++20まで
double fabs(double x); // (2) C++03からC++20まで
long double fabs(long double x); // (3) C++03からC++20まで

constexpr floating-point-type
fabs(floating-point-type x); // (4) C++23

double
fabs(Integral x); // (5) C++11
constexpr double
fabs(Integral x); // (5) C++23

float
fabsf(float x); // (6) C++17
constexpr float
fabsf(float x); // (6) C++23

long double
fabsl(long double x); // (7) C++17
constexpr long double
fabsl(long double x); // (7) C++17
}
```
* Integral[italic]
## 概要
算術型の絶対値を求める。
- (1) : `float`に対するオーバーロード
- (2) : `double`に対するオーバーロード
- (3) : `long double`に対するオーバーロード
- (4) : 浮動小数点数型に対するオーバーロード
- (5) : 整数型に対するオーバーロード (`double`にキャストして計算される)
- (6) : `float`型規定
- (7) : `long double`型規定
## 戻り値
引数 `x` の絶対値を返す。
Expand All @@ -34,6 +55,7 @@ namespace std {
- `value = ±0` の場合、戻り値は `+0` となる。
- `value = ±∞` の場合、戻り値は `+∞` となる。
- 戻り値は正確で、現在の丸め方式には依存しない。
- C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された
## 例
Expand Down Expand Up @@ -77,7 +99,7 @@ fabs(-∞) = inf
- [Visual C++](/implementation.md#visual_cpp): 2003, 2005, 2008, 2010

#### 備考
特定の環境で `constexpr` 指定されている場合がある。(独自拡張)
特定の環境では、早期に `constexpr` 対応されている場合がある:

- GCC 4.6.1 以上

Expand Down Expand Up @@ -108,3 +130,9 @@ namespace std {
* signbit[link signbit.md]
* is_integral[link ../type_traits/is_integral.md]
* enable_if[link ../type_traits/enable_if.md]
## 参照
- [P0533R9 constexpr for `<cmath>` and `<cstdlib>`](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`のオーバーロードに統合し、拡張浮動小数点数型も扱えるようにした
51 changes: 44 additions & 7 deletions reference/cmath/fdim.md
Expand Up @@ -6,14 +6,30 @@

```cpp
namespace std {
float fdim(float x, float y);
double fdim(double x, double y);
long double fdim(long double x, long double y);
float fdim(float x, float y); // (1) C++11からC++20まで
double fdim(double x, double y); // (2) C++11からC++20まで
long double fdim(long double x, long double y); // (3) C++11からC++20まで

Promoted fdim(Arithmetic1 x, Arithmetic2 y);
constexpr floating-point-type
fdim(floating-point-type x,
floating-point-type y); // (4) C++23

float fdimf(float x, float y); // C++17 から
long double fdiml(long double x, long double y); // C++17 から
Promoted
fdim(Arithmetic1 x,
Arithmetic2 y); // (5) C++11
constexpr Promoted
fdim(Arithmetic1 x,
Arithmetic2 y); // (5) C++23

float
fdimf(float x, float y); // (6) C++17
constexpr float
fdimf(float x, float y); // (6) C++23

long double
fdiml(long double x, long double y); // (7) C++17
constexpr long double
fdiml(long double x, long double y); // (7) C++23
}
```
* Promoted[italic]
Expand All @@ -23,11 +39,25 @@ namespace std {
## 概要
算術型の正の差を求める。
- (1) : `float`に対するオーバーロード
- (2) : `double`に対するオーバーロード
- (3) : `long double`に対するオーバーロード
- (4) : 浮動小数点数型に対するオーバーロード
- (5) : 算術型に対するオーバーロード (大きい精度にキャストして計算される。整数は`double`で計算される)
- (6) : `float`型規定
- (7) : `long double`型規定
## 戻り値
引数の正の差を返す。
`x - y > 0` の場合は `x - y` を、それ以外の場合は `+0` を返す。
## 備考
- C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された
## 例
```cpp example
#include <cmath>
Expand Down Expand Up @@ -61,6 +91,13 @@ fdim(+1.0, 0.0) = +1
- [Visual C++](/implementation.md#visual_cpp): ??

#### 備考
特定の環境で `constexpr` 指定されている場合がある。(独自拡張)
特定の環境では、早期に `constexpr` 対応されている場合がある:

- GCC 4.6.1 以上


## 参照
- [P0533R9 constexpr for `<cmath>` and `<cstdlib>`](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`のオーバーロードに統合し、拡張浮動小数点数型も扱えるようにした

0 comments on commit be98598

Please sign in to comment.