-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
Description
What version of Go are you using (go version
)?
$ go version go version go1.16.6 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="" GOARCH="arm64" GOBIN="" GOCACHE="/Users/asdine/Library/Caches/go-build" GOENV="/Users/asdine/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/asdine/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/asdine/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/opt/homebrew/Cellar/go/1.16.6/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/opt/homebrew/Cellar/go/1.16.6/libexec/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.16.6" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/asdine/code/github.com/genjidb/genji/go.mod" 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/z3/f6p4jtl563s0z7gth5c_ydlc0000gn/T/go-build1754120130=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Calling math.Abs(math.MinInt64)
then converting to an int64 doesn't overflow on mac silicon.
package main
import (
"fmt"
"math"
)
func main() {
a := int64(math.MinInt64)
b := math.Abs(math.MinInt64)
c := math.Float64bits(b)
d := int64(b)
fmt.Println(a, b, c, d)
// on x86 cpus:
// -9223372036854775808 9.223372036854776e+18 4890909195324358656 -9223372036854775808
// on silicon:
// -9223372036854775808 9.223372036854776e+18 4890909195324358656 9223372036854775807
}
https://play.golang.org/p/xAYEJonoDAW
I'm not sure if this is a bug or something specific to the Silicon architecture.
What did you expect to see?
I was expecting the int64 to overflow and be negative. This is important to detect overflows and return a proper error when that happens.
What did you see instead?
The number doesn't overflow and stays positive