Skip to content

Instantly share code, notes, and snippets.

@bachue
Last active August 29, 2015 14:04
Show Gist options
  • Save bachue/38c993dc27f754871d15 to your computer and use it in GitHub Desktop.
Save bachue/38c993dc27f754871d15 to your computer and use it in GitHub Desktop.
Go could throw exception when type overflow, but not always.
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("%d\n", int8(math.Pow(2, 10))) // => 0
}
package main
import (
"fmt"
)
func main() {
var f float64 = 129
fmt.Printf("%d\n", int8(f)) // => -127
fmt.Printf("%d\n", int8(float64(129))) // => constant 129 overflows int8
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment