The maximum value for an int type in Go

前端 未结 10 928
无人共我
无人共我 2021-01-29 19:09

How does one specify the maximum value representable for an unsigned integer type?

I would like to know how to initialize min in the loop below

10条回答
  •  失恋的感觉
    2021-01-29 19:39

    A lightweight package contains them (as well as other int types limits and some widely used integer functions):

    import (
        "fmt"
        "/go-imath/ix"
        "/go-imath/ux"
    )
    ...
    fmt.Println(ix.Minimal) // Output: -2147483648 (32-bit) or -9223372036854775808 (64-bit)
    fmt.Println(ix.Maximal) // Output: 2147483647 or 9223372036854775807
    fmt.Println(ux.Minimal) // Output: 0
    fmt.Println(ux.Maximal) // Output: 4294967295 or 18446744073709551615
    

提交回复
热议问题