Closed
Description
What version of Go are you using (go version
)?
$ go version go1.18.2 linux/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="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/root/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/root/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64" GOVCS="" GOVERSION="go1.18.2" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" 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 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3141436172=/tmp/go-build -gno-record-gcc-switches"
What did you do?
package main
import "runtime"
func main() {
var f64 float64 = -2.99
println(runtime.GOARCH)
println("casting float64 to uint64 given negative num", f64, uint64(f64))
}
amd64 result:
amd64
casting float64 to uint64 given negative num -2.990000e+000 18446744073709551614
arm64 result:
arm64
casting float64 to uint64 given negative num -2.990000e+000 0
What did you expect to see?
The behavior of casting a negative float to unsigned int should be the same on different platforms, just like rust.
What did you see instead?
var x float64 = -2.99
uint64(x) == 0