知识卡片

普通读书笔记卡 · 10880.e · 生成模型:未记录

浮点精度与特殊值

理解等级:初级

f32 是 IEEE 754 单精度,至少约有 6 位十进制有效数字,f64 是双精度,至少约有 15 位。选择类型时要考虑误差容许量和范围。两者都有正负无穷、带符号的零和 NaN;MIN、MAX 表示最小和最大的有限值。书中用 -1.0 / f32::INFINITY 来展示带负号的零,即使比较数值时看不出这个符号,也可用 is_sign_negative() 判断。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|浮点值、字面量与显式转换,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#floating-point-types` - 结论依据:原文列出 IEEE 表示的特殊值、位宽与精度,并用除以无穷的例子说明零的符号。 - 原始内容:Both types follow the IEEE 754 floating point standard. They include positive and negative infinities, distinct positive and negative zero values, and a not-a-number