# 单精度浮点格式

**单精度浮点格式**是一种32位计算机数字格式，用于近似表示实数，由IEEE 754标准定义为binary32，历史上称为单格式。它对应C、C++和CUDA中的`float`数据类型，也对应Java的`float`，并且至今仍是图形学、游戏以及大部分机器学习领域的默认工作精度。<sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup><sup> • </sup><sup>[2](https://docs.oracle.com/javase/specs/jls/se26/html/jls-4.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 位布局 | 一个32位字中：1个符号位、8个指数位、23个小数（有效数）位；指数偏置为127<sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup><sup> • </sup><sup>[3](https://docs.oracle.com/cd/E19504-01/802-5885/xdrproto-22/index.html)</sup> |
| 标准参数 | N = 32，精度p = 24个有效位，E_min = −126，E_max = +127<sup>[4](https://dlmf.nist.gov/3.1)</sup> |
| 范围 | 最大有限值3.4028235e38f（≈ 3.40 × 10<sup>38</sup>）；最小正非零值1.40e-45f（一个次正规数）<sup>[5](https://cr.openjdk.org/~darcy/Ieee754TerminologyUpdate/2020-04-21/specs/float-terminology-jls.html)</sup><sup> • </sup><sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> |
| 精度 | 机器精度½ε = 0.596 × 10<sup>−7</sup>，约7–8个有效十进制数字<sup>[4](https://dlmf.nist.gov/3.1)</sup><sup> • </sup><sup>[6](https://people.cas.sc.edu/rorden/simd/index.html)</sup> |
| 特殊值 | 有符号零、有符号无穷大和Not-a-Number（NaN）值，以及用于渐进下溢的次正规数<sup>[2](https://docs.oracle.com/javase/specs/jls/se26/html/jls-4.html)</sup> |
| 命名 | IEEE 754-1985中称为单格式；2008年修订版更名为binary32，IEEE 754-2019沿用此名<sup>[7](https://ethw.org/Milestones%3AIEEE_Standard_754_for_Binary_Floating-Point_Arithmetic%2C_1985)</sup><sup> • </sup><sup>[4](https://dlmf.nist.gov/3.1)</sup> |
| 硬件支持状况 | 所有具备计算能力的NVIDIA GPU均支持遵循IEEE 754的32位整数和单精度算术，但有文档记录的偏差<sup>[8](https://developer.nvidia.com/cuda/faq)</sup> |

## 结构与编码

该格式将一个32位字分为三个连续字段：位0–22为23位小数f，位23–30为8位偏置指数e，位31为1位符号s。<sup>[9](https://docs.oracle.com/cd/E19422-01/819-3693/ncg_math.html)</sup> 对于正规值，所表示的数为

\[ (-1)^{s} \times 1.f \times 2^{e-127} \]

其中有效数的前导1是隐含的，因此23个存储的小数位可提供24位精度。<sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup><sup> • </sup><sup>[3](https://docs.oracle.com/cd/E19504-01/802-5885/xdrproto-22/index.html)</sup> 对于次正规值，公式变为\( (-1)^{s} \times 0.f \times 2^{1-127} \)，这将可表示范围向下渐进扩展，而不是直接跳到零。<sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup>

CUDA文档中的一个计算示例：值−192等于\( (-1)^{1} \times 2^{7} \times 1.5 \)，因此它被编码为负号、指数字段7 + 127 = 134（二进制10000110），以及第一位为1的小数字段。<sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup>

由于小数字段是有限的，大多数实数无法精确表示；例如分数2/3具有无限循环的二进制展开，必须进行舍入。默认舍入模式为就近舍入、平局取偶，IEEE 754还定义了向零舍入、向正无穷舍入和向负无穷舍入。<sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup><sup> • </sup><sup>[10](https://docs.nvidia.com/cuda/pdf/Floating_Point_on_NVIDIA_GPU.pdf)</sup>

## 范围与精度

8位指数给出E_min = −126和E_max = +127，因此正规值的量级范围约为1.18 × 10<sup>−38</sup>到约3.40 × 10<sup>38</sup>。<sup>[4](https://dlmf.nist.gov/3.1)</sup><sup> • </sup><sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> 次正规数向下延伸至2<sup>−149</sup>，即最小的正非正规数。<sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> 机器精度，即1与下一个更大可表示数之间的距离，为\( 2^{-23} \)，给出机器精度0.596 × 10<sup>−7</sup>；在实践中这被描述为7–8个有效十进制数字，而双精度为15–16个数字。<sup>[4](https://dlmf.nist.gov/3.1)</sup><sup> • </sup><sup>[6](https://people.cas.sc.edu/rorden/simd/index.html)</sup>

该格式还为有符号零、有符号无穷大和NaN保留了编码。NaN源于无效运算，如零除以零，IEEE 754允许多个不同的NaN位模式，以便诊断信息可以携带在有效载荷中。<sup>[2](https://docs.oracle.com/javase/specs/jls/se26/html/jls-4.html)</sup>

## 源自IEEE 754标准

在标准化之前，20世纪60年代和70年代的每条计算机产品线都支持各自的范围、精度和舍入行为，有些机器的行为极不稳定，以至于程序员要插入像X = (X + X) − X这样的赋值技巧来强制结果准确。可靠的可移植数值软件变得如此昂贵，以至于只有大型组织才负担得起。<sup>[11](https://people.eecs.berkeley.edu/~wkahan/ieee754status/754story.html)</sup>

1976年，Intel的John Palmer说服公司为其即将推出的浮点协处理器制定算术标准，并聘请了William Kahan作为顾问。Kahan是加州大学伯克利分校电气工程与计算机科学教授，曾分析过商用机器中算术异常的成本。<sup>[11](https://people.eecs.berkeley.edu/~wkahan/ieee754status/754story.html)</sup><sup> • </sup><sup>[7](https://ethw.org/Milestones%3AIEEE_Standard_754_for_Binary_Floating-Point_Arithmetic%2C_1985)</sup> Kahan、他的学生Jerome Coonen和访问教授Harold Stone编写了一份称为K-C-S的规范草案，IEEE p754工作组在经过长期争论后采纳了它，争论尤其集中在渐进下溢上——正是这一设计选择赋予了次正规数在binary32中的作用。<sup>[11](https://people.eecs.berkeley.edu/~wkahan/ieee754status/754story.html)</sup> 该标准于1985年获批，而Intel于1980年交付了8087协处理器，即其首个目标产品。<sup>[7](https://ethw.org/Milestones%3AIEEE_Standard_754_for_Binary_Floating-Point_Arithmetic%2C_1985)</sup>

1985年版将32位格式命名为单精度；2008年修订版将其更名为binary32，而现行的IEEE 754-2019版——754-2008的小幅修订——保留了该名称。<sup>[4](https://dlmf.nist.gov/3.1)</sup><sup> • </sup><sup>[12](https://standards.ieee.org/ieee/754/6210/)</sup> Java相应更新了其语言规范：自Java SE 15起，该语言遵循2019版，其`float`类型由binary32格式定义。<sup>[2](https://docs.oracle.com/javase/specs/jls/se26/html/jls-4.html)</sup>

## 实际应用

单精度以精度换取更快的速度和更少的存储占用。科学软件通常默认使用双精度以避免范围和精度问题，而单精度用于大型问题以节省内存，也用于图像处理等不需要更多有效数字的领域。<sup>[13](https://www.math.hkust.edu.hk/~machas/scientific-computing.pdf)</sup><sup> • </sup><sup>[14](https://www.mathworks.com/help/parallel-computing/measure-and-improve-gpu-performance.html)</sup>

**GPU与机器学习。** 所有具备计算能力的NVIDIA GPU均支持遵循IEEE 754的32位整数和单精度算术，但存在轻微偏差，例如缺少动态可配置的舍入模式，以及将信号NaN作为静默NaN处理。<sup>[8](https://developer.nvidia.com/cuda/faq)</sup><sup> • </sup><sup>[15](https://docs.nvidia.com/cuda/archive/9.2/cuda-c-programming-guide/)</sup> 深度学习推动硬件向更低精度格式发展：NVIDIA随Volta架构推出的Tensor Cores以FP16和TF32等格式加速矩阵运算，而一块拥有108个流式多处理器、运行频率1.41 GHz的A100 GPU具有156 TF32 TFLOPS和312 FP16 TFLOPS的峰值密集吞吐量。<sup>[16](https://docs.nvidia.com/deeplearning/performance/dl-performance-gpu-background/)</sup> 神经网络传统上以binary32训练，而bfloat16和posits等压缩格式已被研究作为更紧凑地表示binary32值而不显著损失精度的方法。<sup>[17](https://arxiv.org/abs/2309.07158)</sup> 在硬件方面，NVIDIA的Ada Lovelace架构相对于上一代将每个CUDA核心的FP32运算速率提高了一倍。<sup>[18](https://www.nvidia.com/en-in/technologies/ada-architecture/)</sup>

**平台注意事项。** 实现以有文档记录的方式偏离标准。在NVIDIA GPU上，全局内存上的原子单精度浮点加法始终以刷零模式运行，而共享内存上的相同操作则保留非正规数支持。<sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> 舍入还与运算顺序相互作用：由于每个操作都会舍入，\( \mathrm{rn}(\mathrm{rn}(A+B)+C) \)和\( \mathrm{rn}(A+\mathrm{rn}(B+C)) \)可能不同，且两者都不必等于正确舍入的精确和。<sup>[1](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> 在x86主机上，80位双扩展寄存器可能产生与纯32位计算不同的结果，除非强制降低精度。<sup>[19](https://docs.nvidia.com/cuda/archive/9.2/cuda-c-best-practices-guide/index.html)</sup>

## References

1. [5.5. Floating-Point Computation, CUDA Programming Guide, NVIDIA](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)
2. [Chapter 4. Types, Values, and Variables, Java Language Specification, Java SE 26, Oracle](https://docs.oracle.com/javase/specs/jls/se26/html/jls-4.html)
3. [Floating Point, XDR Protocol Specification, ONC+ Developer's Guide, Oracle](https://docs.oracle.com/cd/E19504-01/802-5885/xdrproto-22/index.html)
4. [DLMF §3.1 Arithmetics and Error Measures, NIST Digital Library of Mathematical Functions](https://dlmf.nist.gov/3.1)
5. [Update to IEEE 754-2019 Terminology, Java Language Specification change, OpenJDK](https://cr.openjdk.org/~darcy/Ieee754TerminologyUpdate/2020-04-21/specs/float-terminology-jls.html)
6. [Scientific mathematics, Rorden's SIMD notes, University of South Carolina](https://people.cas.sc.edu/rorden/simd/index.html)
7. [Milestones: IEEE Standard 754 for Binary Floating-Point Arithmetic, 1985, Engineering and Technology History Wiki](https://ethw.org/Milestones%3AIEEE_Standard_754_for_Binary_Floating-Point_Arithmetic%2C_1985)
8. [CUDA FAQ, NVIDIA Developer](https://developer.nvidia.com/cuda/faq)
9. [Chapter 2, IEEE Arithmetic, Numerical Computation Guide, Oracle](https://docs.oracle.com/cd/E19422-01/819-3693/ncg_math.html)
10. [Floating Point and IEEE 754, NVIDIA white paper](https://docs.nvidia.com/cuda/pdf/Floating_Point_on_NVIDIA_GPU.pdf)
11. [An Interview with the Old Man of Floating-Point, William Kahan with Charles Severance, 1998](https://people.eecs.berkeley.edu/~wkahan/ieee754status/754story.html)
12. [IEEE SA, IEEE 754-2019 Standard for Floating-Point Arithmetic](https://standards.ieee.org/ieee/754/6210/)
13. [Scientific Computing, HKUST lecture notes](https://www.math.hkust.edu.hk/~machas/scientific-computing.pdf)
14. [Measure and Improve GPU Performance, MATLAB & Simulink, MathWorks](https://www.mathworks.com/help/parallel-computing/measure-and-improve-gpu-performance.html)
15. [CUDA Toolkit 9.2 Programming Guide, Floating-Point Standard](https://docs.nvidia.com/cuda/archive/9.2/cuda-c-programming-guide/)
16. [GPU Performance Background User's Guide, NVIDIA Docs](https://docs.nvidia.com/deeplearning/performance/dl-performance-gpu-background/)
17. [Compressed Real Numbers for AI: a case-study using a RISC-V CPU, arXiv:2309.07158](https://arxiv.org/abs/2309.07158)
18. [Ada Lovelace Architecture, NVIDIA](https://www.nvidia.com/en-in/technologies/ada-architecture/)
19. [CUDA Best Practices Guide, IEEE 754 Compliance and x86 80-bit Computations, NVIDIA](https://docs.nvidia.com/cuda/archive/9.2/cuda-c-best-practices-guide/index.html)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 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/single-precision-floating-point-format

English original: https://www.edgepedia.org/single-precision-floating-point-format
