You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:
Run "go version" and compare against
http://golang.org/doc/devel/release.html If a newer version of Go exists,
install it and retry what you did to reproduce the problem.
Thanks.
What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. Compile the below code:
package main
import (
"fmt"
)
func main() {
fmt.Printf("%v\n", 1.0 / 2)
i := 2
fmt.Printf("%v\n", 1.0 / i)
}
What is the expected output?
(Compile error)
What do you see instead?
0.5
0
Which compiler are you using (5g, 6g, 8g, gccgo)?
6g
Which operating system are you using?
Linux
Which version are you using? (run 'go version')
go version go1.1 linux/amd64
Please provide any additional information below.
I understood the reason but it is surprising. If I use the number literal '1.1' instead
of '1.0', a compile error happens. This looks inconsistent to me. I think it is better
to raise an error when dividing a floating-point number literal by an integer.
The text was updated successfully, but these errors were encountered:
The output is correct, please check the language specification about how are constants,
and expression involving constants, treated. BTW, that handling is IMO pretty consistent.
#WorkingAsIntended
This is consequence of constant conversion.
The relevant rule of the spec is in the binary op section: "Except for shift operations,
if one operand is an untyped constant and the other operand is not, the constant is
converted to the type of the other operand."
The text was updated successfully, but these errors were encountered: