Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int64 casting returns different result based on GOARCH #33

Open
gohumble opened this issue Oct 16, 2022 · 1 comment
Open

int64 casting returns different result based on GOARCH #33

gohumble opened this issue Oct 16, 2022 · 1 comment

Comments

@gohumble
Copy link
Collaborator

gohumble commented Oct 16, 2022

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

@gohumble
Copy link
Collaborator Author

gohumble commented Oct 16, 2022

temporarily fixed in #31 by using uint64 instead of int64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant