recmo / uint

Rust Uint crate using const-generics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`algorithms/div/knuth`: Can we re-use `r` here somehow? The problem is we can not just

github-actions opened this issue · comments

On 2022-10-24 @recmo wrote in fb3aa20 “Merge pull request #172 from recmo/div2”:

Can we re-use r here somehow? The problem is we can not just
shift the r or borrow because we need to accurately reproduce
the remainder and carry in the middle of a limb.

                    let (r, borrow) = r.overflowing_sub(u128::from(borrow));
                    numerator[j + n - 2] = r.low();
                    numerator[j + n - 1] = r.high();
                    borrow
                } else {
                    // OPT: Can we re-use `r` here somehow? The problem is we can not just
                    // shift the `r` or `borrow` because we need to accurately reproduce
                    // the remainder and carry in the middle of a limb.
                    let borrow = submul_nx1(&mut numerator[j..j + n], divisor, q);
                    let n2 = numerator.get(j + n).copied().unwrap_or_default();
                    borrow != n2
                };

From src/algorithms/div/knuth.rs:150