27 lines
777 B
Go
27 lines
777 B
Go
// Package integer provides utilities for working with integer data.
|
|
package integer
|
|
|
|
// UnsignedMin returns the minimum value that an unsigned integer of the
|
|
// specified width can represent.
|
|
func UnsignedMin (width int) uint64 {
|
|
return 0
|
|
}
|
|
|
|
// UnsignedMax returns the maximum value that an unsigned integer of the
|
|
// specified width can represent.
|
|
func UnsignedMax (width int) uint64 {
|
|
return (1 << width) - 1
|
|
}
|
|
|
|
// SignedMin returns the minimum value that a signed integer of the specified
|
|
// width can represent.
|
|
func SignedMin (width int) int64 {
|
|
return -1 - int64(UnsignedMax(width) / 2)
|
|
}
|
|
|
|
// SignedMax returns the maximum value that a signed integer of the specified
|
|
// width can represent.
|
|
func SignedMax (width int) int64 {
|
|
return int64(UnsignedMax(width) / 2)
|
|
}
|