Mryange commented on code in PR #2824:
URL: https://github.com/apache/doris-website/pull/2824#discussion_r2312774907


##########
i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/numeric/FLOATING-POINT.md:
##########
@@ -0,0 +1,181 @@
+---
+{
+    "title": "浮点类型 (FLOAT 和 DOUBLE)",
+    "language": "zh-CN"
+}
+---
+
+## 描述
+
+Doris 提供了两种浮点数据类型:`FLOAT` 和 `DOUBLE`。这些是可变精度的数值类型,遵循 IEEE 754 浮点算术标准。
+
+| 类型 | 别名 | 存储空间 | 描述 |
+|------|------|----------|------|
+| FLOAT | FLOAT4, REAL | 4 字节 | 单精度浮点数 |
+| DOUBLE | FLOAT8, DOUBLE PRECISION | 8 字节 | 双精度浮点数 |
+
+## 取值范围
+
+### FLOAT
+
+Doris 使用 IEEE-754 单精度浮点数,取值范围为:
+
+- -∞ (-Infinity)
+- [-3.402E+38, -1.175E-37]
+- 0
+- [1.175E-37, 3.402E+38]
+- +∞ (+Infinity)
+- NaN (不是数字)
+
+详情请参阅 [C++ float 
类型](https://en.cppreference.com/w/cpp/language/types.html#Standard_floating-point_types)
 和 [Wikipedia 
单精度浮点格式](https://en.wikipedia.org/wiki/Single-precision_floating-point_format)。
+
+### DOUBLE
+
+Doris 使用 IEEE-754 双精度浮点数,取值范围为:
+
+- -∞ (-Infinity)
+- [-1.79769E+308, -2.225E-307]
+- 0
+- [+2.225E-307, +1.79769E+308]
+- +∞ (+Infinity)
+- NaN (不是数字)
+
+详情请参阅 [C++ double 
类型](https://en.cppreference.com/w/cpp/language/types.html#Standard_floating-point_types)
 和 [Wikipedia 
双精度浮点格式](https://en.wikipedia.org/wiki/Double-precision_floating-point_format)。
+
+## 特殊值
+
+除了普通的数值外,浮点类型还有几个特殊值,这些值符合 IEEE 754 标准:
+
+- `Infinity` 或 `Inf`:正无穷大
+- `-Infinity` 或 `-Inf`:负无穷大
+- `NaN`:不是数字(Not a Number)
+
+可以通过 CAST 转换来生成这些特殊值:
+
+```sql
+mysql> select cast('NaN' as double), cast('inf' as double), cast('-Infinity' 
as double);
++-----------------------+-----------------------+-----------------------------+
+| cast('NaN' as double) | cast('inf' as double) | cast('-Infinity' as double) |
++-----------------------+-----------------------+-----------------------------+
+|                   NaN |              Infinity |                   -Infinity |
++-----------------------+-----------------------+-----------------------------+
+```
+
+浮点数还有一个不太直观的特性:存在两种不同的零值,即 `+0` 和 `-0`。
+虽然它们在大多数情况下被视为相等,但它们的符号位不同:
+
+```sql
+mysql> select cast('+0.0' as double), cast('-0.0' as double);
++------------------------+------------------------+
+| cast('+0.0' as double) | cast('-0.0' as double) |
++------------------------+------------------------+
+|                      0 |                     -0 |
++------------------------+------------------------+
+```
+
+## 浮点数运算
+
+### 算术运算
+
+Doris 的浮点数支持常见的加减乘除等算术运算。
+
+需要特别注意的是,Doris 在处理浮点数除以 0 的情况时,并不完全遵循 IEEE 754 标准。
+
+Doris 在这方面参考了 PostgreSQL 的实现,当除以 0 时不会生成特殊值,而是返回 SQL NULL:
+
+| 表达式 | PostgreSQL | IEEE 754 | Doris |
+|--------|------------|----------|-------|
+| 1.0 / 0.0 | 错误 | Infinity | NULL |
+| 0.0 / 0.0 | 错误 | NaN | NULL |
+| -1.0 / 0.0 | 错误 | -Infinity | NULL |
+| 'Infinity' / 'Infinity' | NaN | NaN | NaN |
+| 1.0 / 'Infinity' | 0.0 | 0.0 | 0 |
+| 'Infinity' - 'Infinity' | NaN | NaN | NaN |
+| 'Infinity' - 1.0 | Infinity | Infinity | Infinity |
+
+### 比较运算
+
+IEEE 标准定义的浮点数比较与通常的整数比较有一些重要区别。例如,负零和正零被视为相等,而任何 NaN 
值与任何其他值(包括它自身)比较时都不相等。所有有限浮点数都严格小于 +∞,严格大于 -∞。

Review Comment:
   > 这个跟PostgreSQL 是否一致?
   
   ``` C++
   static inline bool
   float8_eq(const float8 val1, const float8 val2)
   {
        return isnan(val1) ? isnan(val2) : !isnan(val2) && val1 == val2;
   }
   
   static inline bool
   float8_ge(const float8 val1, const float8 val2)
   {
        return isnan(val1) || (!isnan(val2) && val1 >= val2);
   }
   ````
   
   一致的,就是对Nan特殊处理了



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to