Types

Go+ has built-in support for rational numbers:

We introduce rational numbers as primitive Go+ types. We use suffix r to denote rational literals. For example, 1r << 200 means a big int whose value is equal to 2^200.

By default, 1r will have the type of bigint. And 4/5r means the rational constant 45. It will have the type of bigrat.

a := 1r << 200 b := bigint(1 << 200) c := 4/5r d := bigrat(a) - 1/3r + 3*1/2r println a, b, c, d r1 := 1r br := bigrat(1r) // Casting rational numbers works like other primitive types cr := bigrat(1) // Casting normal numbers also works like other primitive types println r1/3 // 0 println br/3 // 1/3 println cr/3 // 1/3

Go+ primitive types are

bool
int8    int16   int32   int    int64    int128
uint8   uint16  uint32  uint   uint64   uint128
uintptr (similar to C's size_t)
byte (alias for uint8)
rune (alias for int32, represents a Unicode code point)
string
float32 float64
complex64 complex128
bigint bigrat
unsafe.Pointer (similar to C's void*)
any (alias for Go's interface{})

The example shows variables of several types, and also that variable declarations may be “factored” into blocks, as with import statements.

import ( "math/cmplx" ) var ( ToBe bool = false MaxInt uint64 = 1<<64 - 1 z complex128 = cmplx.sqrt(-5 + 12i) ) printf "Type: %T Value: %v\n", ToBe, ToBe printf "Type: %T Value: %v\n", MaxInt, MaxInt printf "Type: %T Value: %v\n", z, z

The int, uint, and uintptr types are usually 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems. When you need an integer value you should use int unless you have a specific reason to use a sized or unsigned integer type.

Next example: Integers