Add package for determining integer sizes
This commit is contained in:
17
integer/integer.go
Normal file
17
integer/integer.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package integer
|
||||
|
||||
func UnsignedMin(width int) uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func UnsignedMax(width int) uint64 {
|
||||
return (1 << width) - 1
|
||||
}
|
||||
|
||||
func SignedMin(width int) int64 {
|
||||
return -1 - int64(UnsignedMax(width) / 2)
|
||||
}
|
||||
|
||||
func SignedMax(width int) int64 {
|
||||
return int64(UnsignedMax(width) / 2)
|
||||
}
|
||||
Reference in New Issue
Block a user