Monday, July 22, 2024
HomeGolangThe utmost and minimal worth of the int varieties in Go (Golang)

The utmost and minimal worth of the int varieties in Go (Golang)



To get the utmost and minimal worth of assorted integer varieties in Go, use the math bundle constants. For instance, to get the minimal worth of the int64 sort, which is -9223372036854775808, use the math.MinInt64 fixed. To get the utmost worth of the int64 sort, which is 9223372036854775807, use the math.MaxInt64. To verify the minimal and most values of various int varieties, see the next instance and its output.

For unsigned integer varieties, solely the max fixed is accessible as a result of the minimal worth of unsigned varieties is all the time 0.

bundle foremost

import (
    "fmt"
    "math"
)

func foremost() {
    // int
    fmt.Printf("int min - max: %d - %dn", math.MinInt, math.MaxInt)
    // int8
    fmt.Printf("int8 min - max: %d - %dn", math.MinInt8, math.MaxInt8)
    // int16
    fmt.Printf("int16 min - max: %d - %dn", math.MinInt16, math.MaxInt16)
    // int32
    fmt.Printf("int32 min - max: %d - %dn", math.MinInt32, math.MaxInt32)
    // int64
    fmt.Printf("int64 min - max: %d - %dn", math.MinInt64, math.MaxInt64)

    // unsigned
    // uint
    fmt.Printf("uint min - max: %d - %dn", uint(0), uint(math.MaxUint))
    // uint8
    fmt.Printf("uint8 min - max: %d - %dn", 0, math.MaxUint8)
    // uint16
    fmt.Printf("uint16 min - max: %d - %dn", 0, math.MaxUint16)
    // uint32
    fmt.Printf("uint32 min - max: %d - %dn", 0, math.MaxUint32)
    // uint64
    fmt.Printf("uint64 min - max: %d - %dn", 0, uint64(math.MaxUint64))
}

Output:

int min - max: -9223372036854775808 - 9223372036854775807
int8 min - max: -128 - 127
int16 min - max: -32768 - 32767
int32 min - max: -2147483648 - 2147483647
int64 min - max: -9223372036854775808 - 9223372036854775807
uint min - max: 0 - 18446744073709551615
uint8 min - max: 0 - 255
uint16 min - max: 0 - 65535
uint32 min - max: 0 - 4294967295
uint64 min - max: 0 - 18446744073709551615
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments