aboutsummaryrefslogtreecommitdiff
path: root/src/math/big/float.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2015-02-24 11:24:27 -0800
committerRobert Griesemer <gri@golang.org>2015-02-24 21:30:04 +0000
commitc651fdc0cf2ba7986ce0a0a23b4dbb44b6ecdae3 (patch)
treefc2fc44c0ef6a76ec146b68f7d47fd622016f5c9 /src/math/big/float.go
parentaff84b171c4188cc79bc23bffa3b284b6c02c2d7 (diff)
downloadgo-c651fdc0cf2ba7986ce0a0a23b4dbb44b6ecdae3.tar.xz
math/big: change Float.SetMantExp to always multiply mant by 2**exp
Change-Id: If840e647376a2141f8c17729f7ef251bfff13f5f Reviewed-on: https://go-review.googlesource.com/5810 Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/math/big/float.go')
-rw-r--r--src/math/big/float.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/math/big/float.go b/src/math/big/float.go
index a89ef1021a..015f1645b6 100644
--- a/src/math/big/float.go
+++ b/src/math/big/float.go
@@ -219,22 +219,24 @@ func (x *Float) MantExp() (mant *Float, exp int) {
return
}
-// SetMantExp is the inverse of MantExp. It sets z to mant × 2**exp and
-// and returns z. The result z has the same precision and rounding mode
-// as mant.
+// SetMantExp sets z to mant × 2**exp and and returns z.
+// The result z has the same precision and rounding mode
+// as mant. SetMantExp is an inverse of MantExp but does
+// not require 0.5 <= |mant| < 1.0. Specifically:
+//
+// new(Float).SetMantExp(x.MantExp()).Cmp(x) == 0
//
// Special cases are:
//
// z.SetMantExp( ±0, exp) = ±0
// z.SetMantExp(±Inf, exp) = ±Inf
//
-// The result is ±Inf if the magnitude of exp is > MaxExp.
func (z *Float) SetMantExp(mant *Float, exp int) *Float {
z.Copy(mant)
if len(z.mant) == 0 || z.exp == infExp {
return z
}
- z.setExp(int64(exp))
+ z.setExp(int64(z.exp) + int64(exp))
return z
}