// Go supports high precision values in
// numeric constants, and an untyped constant
// takes the type needed by its context.
// However, when assigned to a variable, or
// when operations are performed on it, then
// it may have an error.
package main
import "fmt"
func needInt(x int) int {
return x * 10 + 1
}
func needFloat(x float64) float64 {
return x * 0.1
}
func main() {
const (
Big = 1 << 100
Small = Big >> 99
)
// The first statement causes an overflow:
// fmt.Println("Type: %T, Value: %v", Big, Big)
// fmt.Println("Type: %T, Value: %v", Small, Small)
fmt.Println(needInt(Small))
fmt.Println(needFloat(Small))
fmt.Println(needFloat(Big))
// This, too, causes an overflow
// fmt.Println(needInt(Big))
}
To embed this program on your website, copy the following code and paste it into your website's HTML: