Help wanted!
The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable. You can also use the original English version as a reference.
Float32、Float64
型はCの型と同等です:
Float32
-float
Float64
-double
可能な限り整数形式でデータを格納することをお勧めします。 たとえば、固定精度の数値を、金額やページの読み込み時間などの整数値にミリ秒単位で変換します。
浮動小数点数の使用
- 浮動小数点数を使用した計算では、丸め誤差が生じることがあります。
SELECT 1 - 0.9
┌───────minus(1, 0.9)─┐
│ 0.09999999999999998 │
└─────────────────────┘
- 計算の結果は、計算方法(コンピュータシステムのプロセッサタイプおよびアーキテクチャ)に依存する。
- 浮動小数点計算では、無限大などの数値が生成されることがあります (
Inf
)と “not-a-number” (NaN
). これは、計算結果を処理するときに考慮する必要があります。 - テキストから浮動小数点数を解析する場合、結果が最も近いマシン表現可能な数値ではない可能性があります。
NaNおよびInf
標準のSQLとは対照的に、ClickHouseは浮動小数点数の次のカテゴリをサポートしています:
Inf
– Infinity.
SELECT 0.5 / 0
┌─divide(0.5, 0)─┐
│ inf │
└────────────────┘
-Inf
– Negative infinity.
SELECT -0.5 / 0
┌─divide(-0.5, 0)─┐
│ -inf │
└─────────────────┘
NaN
– Not a number.
SELECT 0 / 0
┌─divide(0, 0)─┐
│ nan │
└──────────────┘
See the rules for `NaN` sorting in the section [ORDER BY clause](../sql_reference/statements/select/order-by.md).