cashu-feni
cashu-feni copied to clipboard
int64 casting returns different result based on `GOARCH`
What version of Go are you using (go version
)?
$ go version go1.19.1 darwin/arm64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="on" GOARCH="arm64" GOBIN="" GOCACHE="/Users/humble/Library/Caches/go-build" GOENV="/Users/humble/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/humble/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/humble/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.19.1" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tt/fs3zvlp53cgf_dtv5hhyc6cc0000gn/T/go-build2158361161=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Found some compatibility issues with arm64
and amd64
Due to this, I have changed all int64 amounts to uint64 to prevent this "bug".
Another solution would be reducing the MAX_ORDER
of mints to 63
Script
package main
import (
"fmt"
"math"
)
func main() {
pow := math.Pow(float64(2), float64(64))
inti := int64(pow)
fmt.Println(inti)
}
Casting int64 returns different results based on GOARCH
.
~/go/src/github.com/gohumble/cashu-feni arm_amd* 14:58:24
❯ go run cmd/cashu/test.go
9223372036854775807
~/go/src/github.com/gohumble/cashu-feni arm_amd* 14:58:34
❯ GOARCH=amd64 go run cmd/cashu/test.go
-9223372036854775808
What did you expect to see?
amd64 build should return the same int64 value
What did you see instead?
amd64 builds return different int64 values
temporarily fixed in #31 by using uint64 instead of int64.