Constants in Go do not automatically have a type. From the language specification Constants section: <https://golang.org/ref/spec#Constants>
An untyped constant has a *default type* which is the type to which the constant is implicitly converted in contexts where a typed value is required, for instance, in a short variable declaration <https://golang.org/ref/spec#Short_variable_declarations> such as i := 0 where there is no explicit type. The default type of an untyped constant is bool, rune, int, float64, complex128 or string respectively, depending on whether it is a boolean, rune, integer, floating-point, complex, or string constant. Although *Big* has no type, it must be converted to a real typed value to be passes to* fmt.Print()*. As described above, the default conversion to *int* is used, and it does not fit, hence the error. This actually has nothing to do with *%T* or* fmt.Print()* as can be seen in my modified example https://play.golang.org/p/dWXjcgEglU. There the* x := Big* also gives the same error. For starters, to deal with numbers bigger than 64 bits, you will need to use the math/big package <https://golang.org/pkg/math/big/>. However, I do not believe there is any way to create a* big.Int* constant in go. So you would either have to settle for a regular global variable, or have Big be a string constant of "1267650600228229401496703205376", and use big.Int.SetString() <https://golang.org/pkg/math/big/#Int.SetString> in your code (which would not be very efficient.) Jake On Wednesday, November 8, 2017 at 1:02:58 PM UTC-5, k1at...@gmail.com wrote: > > Hello, i'm absolute beginner > > Could you help me ? > > > package main > > import "fmt" > > const ( > // Create a huge number by shifting a 1 bit left 100 places. > // In other words, the binary number that is 1 followed by 100 zeroes. > Big = 1 << 100 > // Shift it right again 99 places, so we end up with 1<<1, or 2. > Small = Big >> 99 > ) > > func needInt(x int) int { return x*10 + 1 } > func needFloat(x float64) float64 { > return x * 0.1 > } > > func main() { > //fmt.Println(needInt(Small)) > //fmt.Println(needFloat(Small)) > > //fmt.Println(needFloat(Big)) > fmt.Printf("%T", Big) > // What is the problem with this ???? from golang tour 16. page > > } > > > tmp/sandbox854410474/main.go:23:13: constant 1267650600228229401496703205376 > overflows int > > > thanks Attila Kovács > > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.