Skip to content

Commit

Permalink
Decimal: fix missing sign handling from (*Decimal).Float
Browse files Browse the repository at this point in the history
  • Loading branch information
db47h committed May 23, 2020
1 parent 02c6171 commit bdb92bb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,11 @@ func (x *Decimal) Float(z *big.Float) *big.Float {

switch x.form {
case zero:
return z.SetPrec(p)
z.SetPrec(p)
if x.neg != z.Signbit() {
z.Neg(z)
}
return z
case inf:
return z.SetInf(x.neg).SetPrec(p)
}
Expand All @@ -455,6 +459,9 @@ func (x *Decimal) Float(z *big.Float) *big.Float {
m := len(x.mant) * _DW
exp := int64(x.exp) - int64(m)
z = z.SetInt(&i)
if x.neg {
z.Neg(z)
}
// z = x·2**(m - x.exp)·5**(m - x.exp)

// normalize mantissa and apply 2 exponent
Expand Down

0 comments on commit bdb92bb

Please sign in to comment.