提问人:Nyxynyx 提问时间:1/17/2022 最后编辑:Ken WhiteNyxynyx 更新时间:1/17/2022 访问量:1433
u128 的平方根
Square root of a u128
答:
5赞
kmdreko
1/17/2022
#1
您可以从 num crate 中使用 Roots
特征(或直接从 num-integer crate 中使用):
pub fn sqrt(&self) -> Self
返回整数的截断主平方根 –
⌊√x⌋
这是求解 in ,四舍五入到零。结果将 满足。
r
r² = x
r² ≤ x < (r+1)²
use num::integer::Roots; // 0.4.0
fn main() {
let a: u128 = 42;
let b = a.sqrt();
assert!(b == 6);
}
评论
0赞
not 0x12
3/3/2022
这会在内部处理 u64,但会损失精度
评论