diff options
| author | Robert Griesemer <gri@golang.org> | 2015-02-10 11:49:54 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2015-02-11 17:02:09 +0000 |
| commit | 950aa9f1bcdea247660a2393bf91506af249b539 (patch) | |
| tree | 5560ec0a9190b0fe95d44ddf4115188767f97738 /src/math/big/float.go | |
| parent | a15818fed3032d43e57c395c3fe8b46b37a5f1ea (diff) | |
| download | go-950aa9f1bcdea247660a2393bf91506af249b539.tar.xz | |
math/big: When result prec == 0, use at least prec == 64 for SetInt, SetRat.
This avoids surprises.
Change-Id: Iaae67da2d12e29c4e797ad6313e0895f7ce80cb1
Reviewed-on: https://go-review.googlesource.com/4480
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/math/big/float.go')
| -rw-r--r-- | src/math/big/float.go | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/math/big/float.go b/src/math/big/float.go index d911143864..a5c0549948 100644 --- a/src/math/big/float.go +++ b/src/math/big/float.go @@ -567,15 +567,15 @@ func fnorm(m nat) uint { } // SetInt sets z to the (possibly rounded) value of x and returns z. -// If z's precision is 0, it is changed to x.BitLen() (and rounding will have -// no effect). +// If z's precision is 0, it is changed to the larger of x.BitLen() +// or 64 (and rounding will have no effect). func (z *Float) SetInt(x *Int) *Float { // TODO(gri) can be more efficient if z.prec > 0 // but small compared to the size of x, or if there // are many trailing 0's. bits := uint(x.BitLen()) if z.prec == 0 { - z.prec = bits + z.prec = umax(bits, 64) } z.acc = Exact z.neg = x.neg @@ -595,9 +595,8 @@ func (z *Float) SetInt(x *Int) *Float { } // SetRat sets z to the (possibly rounded) value of x and returns z. -// If z's precision is 0, it is changed to the larger of a.BitLen() -// and b.BitLen(), where a and b are the numerator and denominator -// of x, respectively (x = a/b). +// If z's precision is 0, it is changed to the largest of a.BitLen(), +// b.BitLen(), or 64; with x = a/b. func (z *Float) SetRat(x *Rat) *Float { // TODO(gri) can be more efficient if x is an integer var a, b Float @@ -1110,6 +1109,7 @@ func (z *Float) Rsh(x *Float, s uint, mode RoundingMode) *Float { // 0 if x == y (incl. -0 == 0) // +1 if x > y // +// Infinities with matching sign are equal. func (x *Float) Cmp(y *Float) int { if debugFloat { x.validate() @@ -1118,7 +1118,6 @@ func (x *Float) Cmp(y *Float) int { mx := x.mag() my := y.mag() - switch { case mx < my: return -1 |
