Skip to content

Commit

Permalink
ensure signbit is set for Int64
Browse files Browse the repository at this point in the history
Updates: #76

Former-commit-id: 9384ac37e5b502b2f03e3545065e4c7c0d54f8a4 [formerly 8d7c469]
Former-commit-id: 52736a2
  • Loading branch information
ericlagergren committed Feb 1, 2018
1 parent cc974b8 commit 6752a26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions big.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,9 @@ func (x *Big) Int64() (int64, bool) {
}
su := int64(u)
if su >= 0 || x.Signbit() && su == -su {
if x.Signbit() {
su = -su
}
return su, true
}
return 0, false
Expand Down
4 changes: 2 additions & 2 deletions big_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (c Context) Quantize(z *Big, n int) *Big {
}

z.exp = n
if shift == 0 || z.compact == 0 {
if shift == 0 {
return z
}

Expand All @@ -359,7 +359,7 @@ func (c Context) Quantize(z *Big, n int) *Big {
}

if shift > 0 {
_ = checked.MulBigPow10(&z.unscaled, &z.unscaled, uint64(shift))
checked.MulBigPow10(&z.unscaled, &z.unscaled, uint64(shift))
z.precision = arith.BigLength(&z.unscaled)
} else {
z.quoBig(m, &z.unscaled, neg, arith.BigPow10(uint64(-shift)), 0)
Expand Down

0 comments on commit 6752a26

Please sign in to comment.