basic/base-type/numbers #644
Replies: 56 comments 65 replies
-
use num::complex::Complex; fn main() { println!("{} + {}i", result.re, result.im) |
Beta Was this translation helpful? Give feedback.
-
既然要演示提高可读性,这是中文教程,1_000_000是不是写成 100_0000 更合适。 |
Beta Was this translation helpful? Give feedback.
-
所有领导都是人,简单的很。 |
Beta Was this translation helpful? Give feedback.
-
关于位运算,无符号应该是逻辑右移,有符号是算术左移。 |
Beta Was this translation helpful? Give feedback.
-
& 位与 相同位置均为1时则为1,否则 |
Beta Was this translation helpful? Give feedback.
-
"所有跟 NaN 交互的操作,都会返回一个 NaN,而且 NaN 不能用来比较" |
Beta Was this translation helpful? Give feedback.
-
当检测到整型溢出时,Rust 会按照补码循环溢出(two’s complement wrapping)的规则处理。 如果是按照这个规则编译,那运行结果将不符合预期,比如说: |
Beta Was this translation helpful? Give feedback.
-
前端垃圾小白提问: |
Beta Was this translation helpful? Give feedback.
-
这个版本float类型的to_bits 方法好像无法使用了 |
Beta Was this translation helpful? Give feedback.
-
刚刚测试, |
Beta Was this translation helpful? Give feedback.
-
“在当使用 --release 参数进行 release 模式构建时,Rust 不检测溢出。”
构建:
版本:
|
Beta Was this translation helpful? Give feedback.
-
for i in 1..=5 { 好像加 = 和不加 = 都可以? |
Beta Was this translation helpful? Give feedback.
-
建议用 |
Beta Was this translation helpful? Give feedback.
-
请教各位, (!b) value is -4 |
Beta Was this translation helpful? Give feedback.
-
// 类型标注 |
Beta Was this translation helpful? Give feedback.
-
“固定精度的十进制小数,常用于货币相关的场景” |
Beta Was this translation helpful? Give feedback.
-
需要注意的是位非运算符 |
Beta Was this translation helpful? Give feedback.
-
艾丽根特,速怕艾丽根特! |
Beta Was this translation helpful? Give feedback.
-
溢出部分有点难以理解,这里贴一个知乎的部分内容:
原贴地址:知乎 |
Beta Was this translation helpful? Give feedback.
-
在Rust中,数值类型主要分为整数类型和浮点数类型,它们之间的区别主要体现在数值范围和精度上。
总体而言,选择合适的数值类型取决于所需的精度和范围。例如,如果需要较大范围的整数或者更高的精度,可以选择相应的整数或浮点数类型。 by chatGPT |
Beta Was this translation helpful? Give feedback.
-
类型转换那里真的太精彩了,建议大家跳转过去看看 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
fn main() {
let x = (-42.0_f32).sqrt();
if x.is_nan() {
println!("未定义的数学行为")
}
} 为什么println这行有无分号都能运行?是Rust的特性? |
Beta Was this translation helpful? Give feedback.
-
a <<= b; 大佬们这句用来干嘛的啊 没太看懂 |
Beta Was this translation helpful? Give feedback.
-
首先会去做同步,然后再运行 |
Beta Was this translation helpful? Give feedback.
-
Rust默认的整数类型不是i32吗?我定义了两个变量,一个是默认类型,一个是i8类型,但是它们也是可以进行运算的,代码如下:
如果将变量b换成i16也是可以运算的,但如果显示的将变量a定义为i32或者其他与b不同的类型,那么就无法进行运算了,所以编译器是会在运算的时候将未显式指定的数据类型偷偷换成显式指定的变量的那种数据类型吗? |
Beta Was this translation helpful? Give feedback.
-
fn main() { |
Beta Was this translation helpful? Give feedback.
-
rust对于溢出的规则是不是改了,为什么我--release还是无法通过编译 |
Beta Was this translation helpful? Give feedback.
-
basic/base-type/numbers
https://course.rs/basic/base-type/numbers.html
Beta Was this translation helpful? Give feedback.
All reactions