【发布时间】:2019-11-28 20:49:34
【问题描述】:
为什么 Rust 的 u64 原语需要 u32 指数?
error[E0308]: mismatched types
--> src/protagonists.rs:13:25
|
13 | return root.pow(self.secret) % prime;
| ^^^^^^^^^^^ expected u32, found u64
help: you can convert an `u64` to `u32` and panic if the converted value wouldn't fit
【问题讨论】:
-
考虑对于非 0 或 1 的值,最大可能的非溢出指数是 63。
-
谢谢,这也是我的假设,它只是让代码变得混乱(但这显然比出现运行时错误要好。
标签: types rust integer integer-arithmetic