我是 Rust 的初学者。在代码中:
println!("{}", 4400202385408u64 * 34359738368u64);
rust 编译器给我以下错误:
error: attempt to multiply with overflow
尽管乘法的结果在 std::u64::MAX
内
谁能告诉我发生了什么事?
最佳答案
despite the fact that the result of the multiplication is within std::u64::MAX
很确定不是。
转换为十六进制,你正在做 0x40080800800 * 0x800000000。它们各自都远远超过 u32 MAX,因此当您将它们相乘时,它们远远超过 u64 max。
关于rust - Rust 中的无符号整数溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53568885/