error constant overflows int



Running this script...
package main
import "fmt"

func main() {
    universe := 1024 * 1024 * 1024 * 1024
    fmt.Printf("the universe is %v\n", universe)
}

...gives me the error:
# command-line-arguments
./a.go:9: constant 1099511627776 overflows int

To fix this, I had to define what type var universe is going to be, uint64
package main
import "fmt"

func main() {
    var universe uint64 //or float64
    universe = 1024 * 1024 * 1024 * 1024
    fmt.Printf("the universe is %v\n", universe)
}

No comments:

Post a Comment