知识卡片

普通读书笔记卡 · 6074.a.6 · 生成模型:未记录

数值运算随类型解释

理解等级:中级

对整数做除法会向零截断,例如 −5 除以 3 得 −1。浮点计算有 f32 和 f64 两种精度,表达小数仍会面临有限精度。计算比率时先确认输入类型与目标精度,避免整数阶段已经丢掉小数部分。

相关卡片 [[整数类型声明可表示域]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 常见编程概念 Data Types · 查看原书依据

      Rust supports the basic mathematical operations you’d expect for all the number types: addition, subtraction, multiplication, division, and remainder. Integer division truncates toward zero to the nearest integer. The following code shows how you’d use each numeric operation in a let statement:

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第03章 常见编程概念(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c03.xhtml`,块 0095) - 结论依据:同一除法运算符在整数类型上截向零,书中另列浮点精度。 - 原始内容:Rust supports the basic mathematical operations you’d expect for all the number types: addition, subtraction, multiplication, division, and remainder. Integer division truncates toward zero to the nearest integer. The following code shows how you’d use each numeric operation in a let statement: