Last active
October 11, 2017 19:49
-
-
Save inancgumus/d9452570bc178cf9cc07f6e2c2f308a2 to your computer and use it in GitHub Desktop.
This file contains 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() { | |
// We can assign an untyped constant to any numeric-type variable | |
// Numeric types: | |
var ( | |
numComplex64 complex64 | |
numComplex128 complex128 | |
numFloat32 float32 | |
numFloat64 float64 | |
numInt8 int8 | |
numInt16 int16 | |
numInt32 int32 | |
numInt64 int64 | |
numUint8 uint8 | |
numUint16 uint16 | |
numUint32 uint32 | |
numUint64 uint64 | |
numByte byte // a type from uint8 | |
numRune rune // a type from int32 | |
) | |
// Untyped numeric constant | |
const untypedConstant = 1 | |
// Let's set untypedConstant to variables with different numeric types | |
numComplex64 = untypedConstant | |
numComplex128 = untypedConstant | |
numFloat32 = untypedConstant | |
numFloat64 = untypedConstant | |
numInt8 = untypedConstant | |
numInt16 = untypedConstant | |
numInt32 = untypedConstant | |
numInt64 = untypedConstant | |
numUint8 = untypedConstant | |
numUint16 = untypedConstant | |
numUint32 = untypedConstant | |
numUint64 = untypedConstant | |
numByte = untypedConstant | |
numRune = untypedConstant | |
// Let's see what they contain | |
fmt.Println(numComplex64, numComplex128, numFloat32, numFloat64, | |
numInt8, numInt16, numInt32, numInt64, | |
numUint8, numUint16, numUint32, numUint64, | |
numByte, numRune) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment