umath

package
v0.8.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Len

func Len[T any](slice []T) uint64

Len returns the length of the slice as a uint64. This convenience function to avoid gosec complaining about uint64(len(slice)).

func NewBigInt

func NewBigInt(i uint64) *big.Int

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 Subtract

func Subtract(a, b uint64) (uint64, bool)

Subtract returns a - b and true if a >= b, otherwise 0 and false.

func SubtractOrZero

func SubtractOrZero(a, b uint64) uint64

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.

func ToUint32

func ToUint32[N constraints.Integer](i N) (uint32, error)

ToUint32 returns i as an uint32 or an error if it cannot be represented as such.

func ToUint64

func ToUint64[N constraints.Integer](i N) (uint64, error)

ToUint64 returns i as an uint64 or an error if it cannot be represented as such.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL