Skip to content

Instantly share code, notes, and snippets.

@inancgumus
Last active October 11, 2017 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inancgumus/d9452570bc178cf9cc07f6e2c2f308a2 to your computer and use it in GitHub Desktop.
Save inancgumus/d9452570bc178cf9cc07f6e2c2f308a2 to your computer and use it in GitHub Desktop.
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