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

spec: non-integral constant can be converted to int #11350

Closed
dvyukov opened this issue Jun 23, 2015 · 1 comment
Closed

spec: non-integral constant can be converted to int #11350

dvyukov opened this issue Jun 23, 2015 · 1 comment
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Jun 23, 2015

The program is:

package a
const a int = 1-1/1e100
const b int = 1-1/1e300

gotype rejects both assignments.
gc rejects only the first one with "constant 1 truncated to integer", but accepts the second one.

The spec says:

This rounding may cause a floating-point constant expression to be invalid in an integer context, even if it would be integral when calculated using infinite precision.

http://golang.org/ref/spec#Constant_expressions
But it does not say the opposite -- FP const may be valid in int context, even if it is not integral when calculated using infinite precision. I think it should say so.

The second point is that "constant 1 truncated to integer" error does not make sense.

@griesemer
Copy link
Contributor

https://go-review.googlesource.com/11369 addresses the spec issue.

Split out #11371 as a separate cmd/compile error.

@mikioh mikioh modified the milestones: Go1.5, Unplanned Jun 24, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
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