mirror of
https://github.com/golang/go.git
synced 2026-06-27 19:30:52 +00:00
math/big: reduce x1,x2 via subtraction
This avoids a mulWW to recalculate the same thing. Also remove prevRhat, as we can detect overflow by comparision of rhat against vn1. Change-Id: I35f9c4fc96ccc271d4c68f41b744bd71b1756585 Reviewed-on: https://go-review.googlesource.com/c/go/+/467556 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Joel Sing <joel@sing.id.au> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
69a99fdcbb
commit
250d0eb6ee
1 changed files with 8 additions and 5 deletions
|
|
@ -676,16 +676,19 @@ func (q nat) divBasic(stk *stack, u, v nat) {
|
|||
ujn2 := u[j+n-2]
|
||||
for greaterThan(x1, x2, rhat, ujn2) { // x1x2 > r̂ u[j+n-2]
|
||||
qhat--
|
||||
prevRhat := rhat
|
||||
rhat += vn1
|
||||
// If r̂ overflows, then
|
||||
// r̂ u[j+n-2]v[n-1] is now definitely > x1 x2.
|
||||
if rhat < prevRhat {
|
||||
if rhat < vn1 {
|
||||
break
|
||||
}
|
||||
// TODO(rsc): No need for a full mulWW.
|
||||
// x2 += vn2; if x2 overflows, x1++
|
||||
x1, x2 = mulWW(qhat, vn2)
|
||||
|
||||
// Maintain (x1, x2) = qhat * vn2.
|
||||
// Since we did qhat-- we need to do (x1, x2) -= vn2.
|
||||
if vn2 > x2 {
|
||||
x1--
|
||||
}
|
||||
x2 -= vn2
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue