Add package for determining integer sizes
This commit is contained in:
parent
4da8ecd25f
commit
c88ba16bdc
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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user