知识卡片
显式选择溢出语义
常规整数运算溢出的反应取决于检查设置。算法需要确定行为时,checked_* 可返回 None,wrapping_* 执行固定宽度回绕,overflowing_* 同时报告溢出标志,saturating_* 截到上下界。计数器或配额运算应先确定超界属于哪种业务结果,再选方法。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 常见编程概念 Data Types · 查看原书依据
To explicitly handle the possibility of overflow, you can use these families of methods provided by the standard library for primitive numeric types:
参考来源
- 位置:《The Rust Programming Language(第2版)》第03章 常见编程概念(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c03.xhtml`,块 0083)
- 结论依据:原文列出四类整数溢出方法,区分构建配置的默认反应。
- 原始内容:To explicitly handle the possibility of overflow, you can use these families of methods provided by the standard library for primitive numeric types: