Commit b7bfb54e authored by Robert Griesemer's avatar Robert Griesemer

math/big: fix aliasing bug in Float.Quo

TBR r, adonovan

Change-Id: I1a38e2d724bf1147c7307a7e5ae855c42c60428c
Reviewed-on: https://go-review.googlesource.com/4875Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent a809dc7a
...@@ -967,12 +967,16 @@ func (z *Float) uquo(x, y *Float) { ...@@ -967,12 +967,16 @@ func (z *Float) uquo(x, y *Float) {
// to shorten x for faster division. But we must be extra careful // to shorten x for faster division. But we must be extra careful
// with rounding in that case. // with rounding in that case.
// Compute d before division since there may be aliasing of x.mant
// (via xadj) or y.mant with z.mant.
d := len(xadj) - len(y.mant)
// divide // divide
var r nat var r nat
z.mant, r = z.mant.div(nil, xadj, y.mant) z.mant, r = z.mant.div(nil, xadj, y.mant)
// determine exponent // determine exponent
e := int64(x.exp) - int64(y.exp) - int64(len(xadj)-len(y.mant)-len(z.mant))*_W e := int64(x.exp) - int64(y.exp) - int64(d-len(z.mant))*_W
// normalize mantissa // normalize mantissa
z.setExp(e - int64(fnorm(z.mant))) z.setExp(e - int64(fnorm(z.mant)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment