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

fmt.Println fails to print math.MaxUint64 #19621

Closed
ghost opened this issue Mar 20, 2017 · 3 comments
Closed

fmt.Println fails to print math.MaxUint64 #19621

ghost opened this issue Mar 20, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Mar 20, 2017

Please answer these questions before submitting your issue. Thanks!

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

play.golang.org

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

play.golang.org

What did you do?

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.MaxUint64)
}

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

https://play.golang.org/p/5GARX4Q2Tc

What did you expect to see?

Successful compilation and math.MaxUint64 in standard output

What did you see instead?

main.go:9: constant 18446744073709551615 overflows int

@bradfitz
Copy link
Contributor

Working as intended per the language spec: https://golang.org/ref/spec#Constants

https://play.golang.org/p/-TM6jBzFpV

See also: https://blog.golang.org/constants

@robpike
Copy link
Contributor

robpike commented Mar 20, 2017

This is just a minor confusing property of the constants defined in the math package. They are all untyped constants (see blog.golang.org/constants), so by default they promote to type int in a call to Println.

@odeke-em
Copy link
Member

odeke-em commented Mar 20, 2017

I too was once surprised by almost the same error message, some 2 years ago https://twitter.com/odeke_et/status/664360654875267073 but @mattsiegel educated me.

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

No branches or pull requests

4 participants