Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79d7e85
commit afa0dc5
Showing
5 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# stdfloat | ||
* stdfloat[meta header] | ||
* cpp23[meta cpp] | ||
|
||
`<stdfloat>`ヘッダでは、実装定義の拡張浮動小数点数型を定義する。 | ||
|
||
これらの拡張浮動小数点数型は、ISO/IEC/IEEE 60559 (IEEE 754) 浮動小数点数規格に従った内部表現をもつことが規定される。 | ||
|
||
|
||
| 名前 | 説明 | 対応バージョン | | ||
|------|------|----------------| | ||
| [`float16_t`](stdfloat/float16_t.md) | 16ビット半精度の浮動小数点数型 | C++23 | | ||
| [`float32_t`](stdfloat/float32_t.md.nolink) | 32ビット単精度の浮動小数点数型 | C++23 | | ||
| [`float64_t`](stdfloat/float64_t.md.nolink) | 64ビット倍精度の浮動小数点数型 | C++23 | | ||
| [`float128_t`](stdfloat/float128_t.md.nolink) | 128ビット四倍精度の浮動小数点数型 | C++23 | | ||
| [`bfloat16_t`](stdfloat/bfloat16_t.md.nolink) | 16ビットのbrain floating point型 | C++23 | | ||
|
||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
## 参照 | ||
- [P1467R9 Extended floating-point types and standard names](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# float16_t | ||
* stdfloat[meta header] | ||
* std[meta namespace] | ||
* type-alias[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
namespace std { | ||
#if defined(__STDCPP_FLOAT16_T__) | ||
using float16_t = implementation-defined; | ||
#endif | ||
} | ||
``` | ||
## 概要 | ||
16ビット半精度の浮動小数点数型。 | ||
### 内部表現 | ||
ISO/IEC/IEEE 60559 (IEEE 754) 浮動小数点数規格のbinary16フォーマットをもつ。 | ||
| 符号ビット数 | 指数ビット数 | 仮数ビット数 | 最大指数 | | ||
|--------------|--------------|--------------|----------| | ||
| 1 | 5 | 10 | 15 | | ||
### リテラル | ||
値にサフィックスとして`f16`もしくは`F16`を指定することで、`std::float16_t`のリテラルとすることができる。 | ||
```cpp | ||
std::float16_t a = 1.0f16; | ||
std::float16_t b = 2.0F16; | ||
``` | ||
|
||
|
||
### 順位 | ||
浮動小数点数の変換で使用される順位 (rank) は、以下のように定義される: | ||
|
||
- `long double` > `double` > `float`のように、`long double`が最も高い順位をもつ | ||
- 同じ値集合をもつ2つの拡張浮動小数点数型は、同じ順位をもつ | ||
- 標準浮動小数点数型と同じ値集合をもつ拡張浮動小数点数型は、同じ順位をもつ | ||
- 標準浮動小数点数型より多くの値集合をもつ拡張浮動小数点数型は、`double`と同じ順位をもつ | ||
|
||
注意として、浮動小数点数型`T1`の値集合が浮動小数点数型`T2`の値集合の部分集合でも上位集合でもない場合、浮動小数点数型`T1`と`T2`の変換順位は順位通りではない。これは、一方の型が他方より大きな範囲と低い精度の両方を持つ場合に起こり得る。 | ||
|
||
順位が同じ浮動小数点数型は、サブ順位 (subrank) で順序付けられる。拡張浮動小数点数は、標準浮動小数点数型よりも大きなサブ順位をもつ。 | ||
|
||
|
||
### 昇格と変換 | ||
C言語の名残と後方互換性のために、オーバーロード解決での`float`から`double`への変換は昇格と見なされるが、ほかの浮動小数点数型では昇格はない。 | ||
|
||
2つの浮動小数点型の少なくとも一方が拡張浮動小数点型である場合、変換先の型が変換元の型より大きいか等しい場合にのみ、2つの浮動小数点型間の変換が暗黙的に行われる。いかなる暗黙の変換も損失なく、値を正確に保持する。潜在的に損失のある変換はすべて明示的でなければならない。 | ||
|
||
小さい精度への変換は、`()`と`{}`による直接初期化、もしくは明示的なキャストのみ許可される。 | ||
|
||
```cpp | ||
void f(std::float16_t); | ||
void g() { | ||
std::float16_t a = 1.0; // エラー!小さい精度への暗黙変換はできない | ||
std::float16_t b(2.0); // OK : 直接初期化 | ||
std::float16_t c{3.0}; // OK : 直接初期化 | ||
a = 4.0; // エラー!小さい精度への暗黙変換はできない | ||
f(5.0); // エラー!小さい精度への暗黙変換はできない | ||
f(static_cast<std::float16_t>(5.0)); // OK : 明示的なキャスト | ||
} | ||
``` | ||
### オーバーロード解決 | ||
TBD | ||
- 浮動小数点数型`FP1`と浮動小数点数型`FP2`の間のいずれかの方向への変換は、`FP1`と算術型`T3`の間の同じ方向への変換よりも優先される | ||
```cpp | ||
int f(std::float32_t); | ||
int f(std::float64_t); | ||
int f(long long); | ||
float x; | ||
std::float16_t y; | ||
int i = f(x); // f(std::float32_t)が呼び出される。 | ||
// floatとstd::float32_tが同じ変換順位をもつ | ||
int j = f(y); // エラー!曖昧。変換ランクが等しくない | ||
``` | ||
* std::float32_t[link float32_t.md.nolink] | ||
* std::float64_t[link float32_t.md.nolink] | ||
|
||
|
||
|
||
## 備考 | ||
- この型は、C23で定義されるオプションキーワード`_Float16`の別名として定義されることになるだろう | ||
- この型は、`_Float16`と相互運用できることが望ましい | ||
- この型は、`__STDCPP_FLOAT16_T__`マクロが定義されない場合、定義されない | ||
- ISO/IEC/IEEE 60559 (IEEE 754) のbinary16フォーマットが実装される環境でこのマクロは定義される | ||
|
||
|
||
## 例 | ||
```cpp example | ||
``` | ||
|
||
### 出力 | ||
``` | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): | ||
- [GCC](/implementation.md#gcc): | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
|