Last active
August 29, 2015 14:04
-
-
Save bachue/38c993dc27f754871d15 to your computer and use it in GitHub Desktop.
Go could throw exception when type overflow, but not always.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func main() { | |
fmt.Printf("%d\n", int8(math.Pow(2, 10))) // => 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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