知识卡片
定宽数值的成本与边界
定宽数值的名字直接给出表示和位宽,如 i16 是 16 位有符号整数、f32 是 32 位浮点数。固定的存储大小使常见运算可以借用处理器的数值指令,同时限制了可表达的范围或精度。若问题要求保留任意大的整数或精确分数,就要考虑相应的任意精度整数或有理数表示。
关联阅读:[[显式选择整数溢出策略]]、[[浮点精度与特殊值]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 定宽数字与机器字
原书出处 · 1 处
- Fundamental Types 定宽数字与机器字 · 查看原书依据
Fixed-width numeric types can overflow or lose precision, but they are adequate for most applications and can be thousands of times faster than
参考来源
- 位置:《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#numeric-types`
- 结论依据:原文将基础类型与硬件表示对应,明确给出定宽类型在速度、范围与精度之间的取舍。
- 原始内容:Fixed-width numeric types can overflow or lose precision, but they are adequate for most applications and can be thousands of times faster than