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

cmd/compile: Mac M1 bug #62725

Closed
egonelbre opened this issue Sep 19, 2023 · 2 comments
Closed

cmd/compile: Mac M1 bug #62725

egonelbre opened this issue Sep 19, 2023 · 2 comments
Labels
arch-arm64 compiler/runtime Issues related to the Go compiler and/or runtime. OS-Darwin

Comments

@egonelbre
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.21.1 darwin/arm64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

Mac M1

What did you do?

package main

import (
	"math"
	"time"
)

func main() {
	period := uint(30)
	x := time.Time{}
	counter := int64(math.Floor(float64(x.Unix()) / float64(period)))
	counter2 := uint64(math.Floor(float64(x.Unix()) / float64(period)))
	println(counter, counter2)
	// Output: -2071186560 0
}

What did you expect to see?

I would've expected counter2 == 18446744071638365056. It does work when running with GOARCH=amd64 go run .

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 19, 2023
@bcmills
Copy link
Contributor

bcmills commented Sep 19, 2023

Per https://go.dev/ref/spec#Conversions, “In all non-constant conversions involving floating-point or complex values, if the result type cannot represent the value the conversion succeeds but the result value is implementation-dependent.”

Since uint64 cannot represent a negative value, the result here is implementation-dependent.

@egonelbre
Copy link
Contributor Author

Ah, indeed I forgot about that.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-arm64 compiler/runtime Issues related to the Go compiler and/or runtime. OS-Darwin
Projects
None yet
Development

No branches or pull requests

4 participants