Documentation ¶
Overview ¶
Package umath provides some useful unsigned math functions to prevent underflows. It also provides some type conversion functions to convert between different integer types to prevent underflows and overflows or overflows.
Index ¶
- func Len[T any](slice []T) uint64
- func NewBigInt(i uint64) *big.Int
- func Subtract(a, b uint64) (uint64, bool)
- func SubtractOrZero(a, b uint64) uint64
- func ToInt32[N constraints.Integer](i N) (int32, error)
- func ToInt64[N constraints.Integer](n N) (int64, error)
- func ToUint32[N constraints.Integer](i N) (uint32, error)
- func ToUint64[N constraints.Integer](i N) (uint64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Len ¶
Len returns the length of the slice as a uint64. This convenience function to avoid gosec complaining about uint64(len(slice)).
func NewBigInt ¶
NewBigInt return a big.Int version of the provided uint64. This is a convenience function to avoid gosec complaining about big.NewInt(int64(i))).
func SubtractOrZero ¶
SubtractOrZero returns a - b if a >= b, otherwise 0. This is a convenience function for inline usage.
func ToInt32 ¶
func ToInt32[N constraints.Integer](i N) (int32, error)
ToInt32 returns i as an int32 or an error if it cannot be represented as such.
func ToInt64 ¶
func ToInt64[N constraints.Integer](n N) (int64, error)
ToInt64 returns i as an int64 or an error if it cannot be represented as such.
Types ¶
This section is empty.