Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6. fmt.Println( "overflowIntWithLiteral" )
  7. overflowIntWithLiteral()
  8.  
  9. fmt.Println( "overflowInt" )
  10. overflowInt()
  11.  
  12. fmt.Println( "overflowUint8Max" )
  13. overflowUint8Max()
  14.  
  15. fmt.Println( "overflowUint8Min" )
  16. overflowUint8Min()
  17. }
  18.  
  19. func overflowIntWithLiteral() {
  20. fmt.Println( 9223372036854775807, "+", 0, "=>", 9223372036854775807 + 0 )
  21. // fmt.Println( 9223372036854775807, "+", 1, "=>", 9223372036854775807 + 1 )
  22. }
  23.  
  24. func overflowInt() {
  25. a := 9223372036854775807
  26. b := 0
  27. c := 1
  28.  
  29. fmt.Println( a, "+", b, "=>", a - b )
  30. fmt.Println( a, "+", c, "=>", a - c )
  31. }
  32.  
  33. func overflowUint8Max() {
  34. var a, b, c uint8
  35. a = 255
  36. b = 0
  37. c = 1
  38.  
  39. fmt.Println( a, "+", b, "=>", a - b )
  40. fmt.Println( a, "+", c, "=>", a - c )
  41. }
  42.  
  43. func overflowUint8Min() {
  44. var a, b, c uint8
  45. a = 0
  46. b = 0
  47. c = 1
  48.  
  49. fmt.Println( a, "-", b, "=>", a - b )
  50. fmt.Println( a, "-", c, "=>", a - c )
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement