Skip to content

Commit

Permalink
fix: upgrade apd lib to version without bug (#1399)
Browse files Browse the repository at this point in the history
Addresses #1152 

After debugging for a bit it became apparent the sign was being dropped
during the operation in the `apd` module. Upgrading to the latest
version fixes this.

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
  • Loading branch information
deelawn authored Dec 4, 2023
1 parent 2a66adc commit 5bc611a
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion contribs/gnokeykc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions contribs/gnokeykc/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/op_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"math/big"

"github.com/cockroachdb/apd"
"github.com/cockroachdb/apd/v3"
)

// ----------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions gnovm/pkg/gnolang/op_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
"strings"

"github.com/cockroachdb/apd"
"github.com/cockroachdb/apd/v3"
)

func (m *Machine) doOpEval() {
Expand Down Expand Up @@ -160,8 +160,7 @@ func (m *Machine) doOpEval() {
panic(fmt.Sprintf("error computing exponent: %v", err))
}
// Step 3 make Decimal from mantissa and exp.
var dValue *big.Int
dValue = new(big.Int)
dValue := new(apd.BigInt)
_, ok := dValue.SetString(hexString, 16)
if !ok {
panic(fmt.Sprintf("can't convert %s to decimal", value))
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/op_inc_dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"math/big"

"github.com/cockroachdb/apd"
"github.com/cockroachdb/apd/v3"
)

func (m *Machine) doOpInc() {
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/op_unary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"math/big"

"github.com/cockroachdb/apd"
"github.com/cockroachdb/apd/v3"
)

func (m *Machine) doOpUpos() {
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"unsafe"

"github.com/cockroachdb/apd"
"github.com/cockroachdb/apd/v3"

"github.com/gnolang/gno/tm2/pkg/crypto"
)
Expand Down
4 changes: 2 additions & 2 deletions gnovm/pkg/gnolang/values_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"
"strconv"

"github.com/cockroachdb/apd"
"github.com/cockroachdb/apd/v3"
)

// t cannot be nil or untyped or DataByteType.
Expand Down Expand Up @@ -1113,7 +1113,7 @@ func ConvertUntypedBigintTo(dst *TypedValue, bv BigintValue, t Type) {
return // done
case BigdecKind:
dst.T = t
dst.V = BigdecValue{V: apd.NewWithBigInt(bi, 0)}
dst.V = BigdecValue{V: apd.NewWithBigInt(new(apd.BigInt).SetMathBigInt(bi), 0)}
return // done
default:
panic(fmt.Sprintf(
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/values_conversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math"
"testing"

"github.com/cockroachdb/apd"
"github.com/cockroachdb/apd/v3"
"github.com/stretchr/testify/require"
)

Expand Down
19 changes: 19 additions & 0 deletions gnovm/tests/files/math4.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

func main() {
println(-3.0 * 1.0 / 2.0) // -1.5
println(-3.0 * 1.0 / 2) // -1.5
println(-3.0 * 1 / 2.0) // -1.5

println(-3 * 1.0 / 2.0) // 1.5
println(-3 * 1.0 / 2) // 1.5
println(-3 * 1 / 2.0) // 1.5
}

// Output:
// -1.5
// -1.5
// -1.5
// -1.5
// -1.5
// -1.5
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/cockroachdb/apd v1.1.0
github.com/cockroachdb/apd/v3 v3.2.1
github.com/davecgh/go-spew v1.1.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
github.com/dgraph-io/badger/v3 v3.2103.4
Expand Down Expand Up @@ -60,7 +60,6 @@ require (
github.com/gorilla/sessions v1.2.1 // indirect
github.com/klauspost/compress v1.12.3 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down
5 changes: 2 additions & 3 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion misc/loop/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dgraph-io/badger/v3 v3.2103.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions misc/loop/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5bc611a

Please sign in to comment.