# 机器精度

机器精度是指在给定的浮点系统中，加上 1.0 后能产生不同于 1.0 的结果的最小正数。<sup>[1](https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Machine-Epsilon.html)</sup> 它衡量系统的精度：即 1.0 与下一个可表示数之间的间距，而在常见的形式化用法中，它也是单次算术运算相对舍入误差的一个上界。<sup>[2](https://en.cppreference.com/cpp/types/numeric_limits/epsilon)</sup><sup> • </sup><sup>[3](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义（区间形式） | 1.0 与该浮点类型下一个可表示值之间的差<sup>[2](https://en.cppreference.com/cpp/types/numeric_limits/epsilon)</sup> |
| IEEE 单精度（float） | \( 2^{-23} \)，约 1.192e-07<sup>[1](https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Machine-Epsilon.html)</sup> |
| IEEE 双精度 | \( 2^{-52} \)，约 2.220e-16<sup>[1](https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Machine-Epsilon.html)</sup> |
| x86 扩展精度（long double） | \( 2^{-63} \)，约 1.084e-19<sup>[1](https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Machine-Epsilon.html)</sup> |
| 单位舍入误差 | 使 \( 1 + \chi \) 的浮点表示大于 1 的最小正数 \( \chi \)；对于就近舍入，它等于区间精度的一半<sup>[4](https://www.cs.utexas.edu/~flame/laff/alaff/chapter06-summary.html)</sup><sup> • </sup><sup>[5](https://technav.ieee.org/topic/roundoff-errors/)</sup> |
| 语言访问方式 | C 宏 `FLT_EPSILON`、`DBL_EPSILON`、`LDBL_EPSILON`；C++ `std::numeric_limits<T>::epsilon()`；Python `sys.float_info.epsilon`<sup>[6](https://en.cppreference.com/c/types/limits)</sup><sup> • </sup><sup>[7](https://docs.python.org/3/library/math.html)</sup> |

## 两种定义

区间定义是指 1.0 与下一个更大的可表示数之间的间隙，这也是 C 和 C++ 语言常量所返回的值。<sup>[2](https://en.cppreference.com/cpp/types/numeric_limits/epsilon)</sup><sup> • </sup><sup>[6](https://en.cppreference.com/c/types/limits)</sup> 德克萨斯大学线性代数课程笔记将其定义为最小的正浮点数 \( \chi \)，使得表示 \( 1 + \chi \) 的浮点数大于 1。<sup>[4](https://www.cs.utexas.edu/~flame/laff/alaff/chapter06-summary.html)</sup>

在就近舍入算术下，这两个值中一个是另一个的两倍。IEEE 技术导航器专题页面指出，舍入结果的相对误差以单位舍入误差为界，通常写作 \( u \)，在就近舍入下等于机器精度的一半。<sup>[5](https://technav.ieee.org/topic/roundoff-errors/)</sup> 当时供职于施乐帕洛阿尔托研究中心的戴维·戈德堡（David Goldberg） 在其 1991 年的综述《每个计算机科学家都应该知道的浮点算术知识》（《ACM 计算综述》）中采取了相反的约定：令 \( \epsilon = (\beta/2)\beta^{-p} \)，其中 \( \beta \) 为基数，\( p \) 为精度，则将一个实数舍入到最近浮点数的相对误差总是以 \( \epsilon \) 为界，他称之为机器精度。<sup>[3](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)</sup> 特雷费森（Trefethen）和鲍（Bau）在《数值线性代数》中回避了这一约定问题，将 \( \epsilon_{\mathrm{machine}} \) 定义为标准舍入误差公理成立的最小数值；在截断而非舍入中间结果的机器上，这些公理可能仅在将 \( \epsilon_{\mathrm{machine}} \) 替换为其两倍值时才成立，不过对于 IEEE 算术而言，这一变化并无显著差异。<sup>[8](https://www.stat.uchicago.edu/~lekheng/courses/309/books/Trefethen-Bau.pdf)</sup>

## 常见格式中的值

GNU C 语言手册以十六进制浮点字面量给出了三种标准 C 浮点类型的机器精度常量：`float` 为 `0x1p-23`（约 1.192e-07），`double` 为 `0x1p-52`（约 2.220e-16），`long double` 为 `0x1p-63`（约 1.084e-19）。<sup>[1](https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Machine-Epsilon.html)</sup> 这些值直接来自 IEEE 754 二进制格式的有效数宽度：单精度为 24 位精度，双精度为 53 位，x86 扩展格式为 64 位，因此 1.0 处的间隙比最后一个有效数位低一个 2 的幂。<sup>[1](https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Machine-Epsilon.html)</sup>

标准库设施也暴露了相同的值。C 提供了宏 `FLT_EPSILON`、`DBL_EPSILON` 和 `LDBL_EPSILON`，定义为每种类型下 1.0 与下一个可表示值之间的差。<sup>[6](https://en.cppreference.com/c/types/limits)</sup> C++ 通过 `std::numeric_limits<T>::epsilon()` 暴露相同的量，对于三种浮点类型分别返回 `FLT_EPSILON`、`DBL_EPSILON` 或 `LDBL_EPSILON`。<sup>[2](https://en.cppreference.com/cpp/types/numeric_limits/epsilon)</sup> Python 将其作为 `sys.float_info.epsilon` 暴露，对应平台的 double 类型。<sup>[7](https://docs.python.org/3/library/math.html)</sup> Swift 的 `ulpOfOne` 属性——即 1.0 的最后一位单位——与这些 C 宏相对应，其文档描述为有时被称为 ε 或机器精度。<sup>[9](https://developer.apple.com/documentation/swift/float/ulpofone-1s81z?changes=_9)</sup>

## 在误差分析中的作用

机器精度为舍入误差界设定了尺度。迈克尔·奥弗顿（Michael Overton）在其 SIAM 著作《IEEE 浮点算术数值计算》中给出了相对舍入误差界 \( |\hat{x} - x|/|x| < \epsilon \)，其中 \( \epsilon \) 表示机器精度；当舍入模式为就近舍入时，该界会多出一个 1/2 的因子。对其应用 \( -\log_{10} \) 可近似得出舍入值与原始值共有多少位十进制数字——对于 IEEE 单精度大约为七位或更多。<sup>[10](https://ethw-images.s3.us-east-va.perf.cloud.ovh.us/ieee/3/36/Numerical_Computing_with_IEEE_Floating_Point_Arithmetic.pdf)</sup> 在基本运算的标准误差模型中，\( a \) op \( b \) 的计算结果满足 \( \mathrm{fl}(a \; \mathrm{op} \; b) = (a \; \mathrm{op} \; b)(1 + \delta) \)，其中 \( |\delta| \le u \)，因此单位舍入误差限制了每次运算的相对误差；大多数计算机，尤其是实现 IEEE 标准算术的计算机，都遵循这一模型。<sup>[11](https://www.sciencedirect.com/science/article/pii/B9780444642073000068)</sup>

该量也进入实际比较之中。由于浮点结果在多次运算中累积舍入误差，用类型的原始 ε 来测试两个计算值是否相等是一种常见但微妙的习惯用法；cppreference 中 `std::numeric_limits<T>::epsilon()` 的示例按被比较值的指数来缩放 ε，因为相邻可表示数之间的间隙随着离 1.0 的每个二进制数量级而翻倍。<sup>[2](https://en.cppreference.com/cpp/types/numeric_limits/epsilon)</sup> Python 的 `math.ulp(x)` 函数（在 3.9 版本中加入）返回浮点数最低有效位的值，因此大于正有限数 \( x \) 的第一个浮点数为 \( x + \mathrm{ulp}(x) \)，将 1.0 处的固定间隙推广到整个范围。<sup>[7](https://docs.python.org/3/library/math.html)</sup>

## 标准背景

现代硬件中机器精度的值源自 IEEE 浮点算术标准 IEEE 754，该标准于 1985 年首次发布，并于 2008 年和 2019 年修订。<sup>[5](https://technav.ieee.org/topic/roundoff-errors/)</sup> 当前生效的修订版 IEEE 754-2019 于 2019 年 6 月 13 日由 IEEE SA 标准委员会批准，2019 年 7 月 22 日发布，取代了 754-2008；它规定了二进制和十进制浮点算术的交换格式和算术格式，其结果和异常由输入值、运算序列和目标格式唯一确定。<sup>[12](https://standards.ieee.org/ieee/754/6210/)</sup> 由于该标准固定了二进制格式的有效数宽度，程序可以在任何符合标准的实现上依赖相同的 ε 值，这正是 C 和 C++ 常量能够跨机器移植的原因。<sup>[6](https://en.cppreference.com/c/types/limits)</sup>

## References

1. [Machine Epsilon, GNU C Language Manual](https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Machine-Epsilon.html)
2. [std::numeric_limits<T>::epsilon, cppreference.com](https://en.cppreference.com/cpp/types/numeric_limits/epsilon)
3. [David Goldberg (1991). What Every Computer Scientist Should Know About Floating-Point Arithmetic. ACM Computing Surveys 23(1), 5–48 (Oracle reprint)](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)
4. [ALAFF Chapter 6 Summary: Machine epsilon (unit roundoff), University of Texas at Austin](https://www.cs.utexas.edu/~flame/laff/alaff/chapter06-summary.html)
5. [Roundoff errors, IEEE Technology Navigator](https://technav.ieee.org/topic/roundoff-errors/)
6. [Numeric limits, cppreference.com](https://en.cppreference.com/c/types/limits)
7. [math — Mathematical functions, Python 3 documentation](https://docs.python.org/3/library/math.html)
8. [Lloyd N. Trefethen and David Bau III. Numerical Linear Algebra, Part III: Conditioning and Stability](https://www.stat.uchicago.edu/~lekheng/courses/309/books/Trefethen-Bau.pdf)
9. [ulpOfOne, Apple Developer Documentation](https://developer.apple.com/documentation/swift/float/ulpofone-1s81z?changes=_9)
10. [Michael Overton. Numerical Computing with IEEE Floating Point Arithmetic, SIAM](https://ethw-images.s3.us-east-va.perf.cloud.ovh.us/ieee/3/36/Numerical_Computing_with_IEEE_Floating_Point_Arithmetic.pdf)
11. [Numerical methods, ScienceDirect](https://www.sciencedirect.com/science/article/pii/B9780444642073000068)
12. [IEEE 754-2019, IEEE Standard for Floating-Point Arithmetic, IEEE SA](https://standards.ieee.org/ieee/754/6210/)

---
*Initially written Oct 15, 2026 · Edited: Oct 25, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Arithmetic and number systems › Computational arithmetic › Floating-point and mixed-precision arithmetic

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/machine-epsilon

English original: https://www.edgepedia.org/machine-epsilon
