Nyx*_*nyx 3 int128 square-root rust
a的平方根如何u128计算?经过舍入后得到的数字可以是 a u128。
f64有一个f64::sqrt函数,但我认为我们不应该转换u128为f64.
您可以使用numRoots crate中的特征(或直接使用num-integer crate 中的特征):
\n\n\n
pub fn sqrt(&self) -> Self返回整数 \xe2\x80\x93 的截断主平方根
\n\xe2\x8c\x8a\xe2\x88\x9ax\xe2\x8c\x8b这是求解
\nrinr\xc2\xb2 = x,向零舍入。结果将\n满足r\xc2\xb2 \xe2\x89\xa4 x < (r+1)\xc2\xb2。
use num::integer::Roots; // 0.4.0\n\nfn main() {\n let a: u128 = 42;\n let b = a.sqrt();\n \n assert!(b == 6);\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1632 次 |
| 最近记录: |