DEV Community

indiewebdev
indiewebdev

Posted on

Golang Notes - 8

Overflows

var x uint8 = 255
x++
fmt.Println(x) // overflow, x = 0

var b int8 = 127
fmt.Println("%d\n", b+1) // overflow, b -128

f := float32(math.MaxFloat32)
f *= 1.2
fmt.Println(f) // overflows to infinite, +Inf
Enter fullscreen mode Exit fullscreen mode

use math/big package for big numbers

Top comments (0)