`pow`: A dedicated function avoiding full-sized shift.
- 主要语言
- Rust
- 星标
- 225
- 派生
- 70
- 平均合并
- 16 小时 54 分钟
- 30 天内合并 PR
- 8
描述
*On 2022-05-31 @recmo wrote in [`c1a0c34`](https://github.com/recmo/uint/commit/c1a0c34df8ab6d3411ad79c27b72ad812eff78e4) “Merge pull request #97 from recmo/isqrt”:*
A dedicated function avoiding full-sized shift.
```rust
#[allow(clippy::cast_sign_loss)] // fract >= 0.
let bits = (fract.exp2() * EXP2_63) as u64;
// Note: If `fract` is zero this will result in `u64::MAX`.
if shift >= 63 {
// OPT: A dedicated function avoiding full-sized shift.
Some(Self::try_from(bits).ok()?.checked_shl(shift - 63)?)
} else {
let shift = 63 - shift;
// Divide `bits` by `2^shift`, rounding to nearest.
let bits = (bits >> shift) + ((bits >> (shift - 1)) & 1);
```
*From [`src/pow.rs:129`](https://github.com/recmo/uint/blob/c1a0c34df8ab6d3411ad79c27b72ad812eff78e4/src/pow.rs#L129)*
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。