safemath

package
v0.0.0-...-49ff46f Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOverflowAdd = errors.New("integer overflow in addition")
	ErrOverflowMul = errors.New("integer overflow in multiplication")
	ErrOverflowSub = errors.New("integer overflow in subtraction")
	ErrDivByZero   = errors.New("divide by zero")
)

Functions

func CheckedAddU128

func CheckedAddU128(a, b wide.Uint128) (wide.Uint128, error)

CheckedAddU128 adds two uint128's together, returning an error in the event of an overflow.

func CheckedAddU16

func CheckedAddU16(a, b uint16) (uint16, error)

CheckedAddU16 adds two uint16's together, returning an error in the event of an overflow.

func CheckedAddU32

func CheckedAddU32(a, b uint32) (uint32, error)

CheckedAddU32 adds two uint32's together, returning an error in the event of an overflow.

func CheckedAddU64

func CheckedAddU64(a, b uint64) (uint64, error)

CheckedAddU64 adds two uint64's together, returning an error in the event of an overflow.

func CheckedAddU8

func CheckedAddU8(a, b uint8) (uint8, error)

CheckedAddU8 adds two uint8's together, returning an error in the event of an overflow.

func CheckedDivU128

func CheckedDivU128(a, b wide.Uint128) (wide.Uint128, error)

CheckedDivU128 multiplies two uint128's together, returning an error in the event of a would-be div-by-0

func CheckedDivU16

func CheckedDivU16(a, b uint16) (uint16, error)

CheckedDivU16 computes `a / b` for two uint16's, returning an error in the event that b is 0

func CheckedDivU32

func CheckedDivU32(a, b uint32) (uint32, error)

CheckedDivU32 computes `a / b` for two uint32's, returning an error in the event that b is 0

func CheckedDivU64

func CheckedDivU64(a, b uint64) (uint64, error)

CheckedDivU64 computes `a / b` for two uint64's, returning an error in the event that b is 0

func CheckedDivU8

func CheckedDivU8(a, b uint8) (uint8, error)

CheckedDivU8 computes `a / b` for two uint8's, returning an error in the event that b is 0

func CheckedMulU128

func CheckedMulU128(a, b wide.Uint128) (wide.Uint128, error)

CheckedMulU128 multiplies two uint128's together, returning an error in the event of an overflow.

func CheckedMulU16

func CheckedMulU16(a, b uint16) (uint16, error)

CheckedMulU16 multiplies two uint16's together, returning an error in the event of an overflow.

func CheckedMulU32

func CheckedMulU32(a, b uint32) (uint32, error)

CheckedMulU32 multiplies two uint32's together, returning an error in the event of an overflow.

func CheckedMulU64

func CheckedMulU64(a, b uint64) (uint64, error)

CheckedMulU64 multiplies two uint64's together, returning an error in the event of an overflow.

func CheckedMulU8

func CheckedMulU8(a, b uint8) (uint8, error)

CheckedMulU8 multiplies two uint8's together, returning an error in the event of an overflow.

func CheckedSubU16

func CheckedSubU16(a, b uint16) (uint16, error)

CheckedSubU16 computes `a - b` for two uint16's, returning an error in the event that a is smaller than b

func CheckedSubU32

func CheckedSubU32(a, b uint32) (uint32, error)

CheckedSubU32 computes `a - b` for two uint32's, returning an error in the event that a is smaller than b

func CheckedSubU64

func CheckedSubU64(a, b uint64) (uint64, error)

CheckedSubU64 computes `a - b` for two uint64's, returning an error in the event that a is smaller than b

func CheckedSubU8

func CheckedSubU8(a, b uint8) (uint8, error)

CheckedSubU8 computes `a - b` for two uint8's returning an error in the event that a is smaller than b

func SaturatingAddU128

func SaturatingAddU128(a, b wide.Uint128) wide.Uint128

func SaturatingAddU16

func SaturatingAddU16(a, b uint16) uint16

SaturatingAddU16 adds two uint16's together and saturates at the numerical boundary if an overflow would have occurred.

func SaturatingAddU32

func SaturatingAddU32(a, b uint32) uint32

SaturatingAddU32 adds two uint32's together and saturates at the numerical boundary if an overflow would have occurred.

func SaturatingAddU64

func SaturatingAddU64(a, b uint64) uint64

SaturatingAddU64 adds two uint64's together and saturates at the numerical boundary if an overflow would have occurred.

func SaturatingAddU8

func SaturatingAddU8(a, b uint8) uint8

SaturatingAddU8 adds two uint8's together and saturates at the numerical boundary if an overflow would have occurred.

func SaturatingMulU16

func SaturatingMulU16(a, b uint16) uint16

SaturatingMulU16 multiplies two uint16's together and saturates at the numerical boundary if an overflow would have occurred.

func SaturatingMulU32

func SaturatingMulU32(a, b uint32) uint32

SaturatingMulU32 multiplies two uint32's together and saturates at the numerical boundary if an overflow would have occurred.

func SaturatingMulU64

func SaturatingMulU64(a, b uint64) uint64

SaturatingMulU64 multiplies two uint64's together and saturates at the numerical boundary if an overflow would have occurred.

func SaturatingMulU8

func SaturatingMulU8(a, b uint8) uint8

SaturatingMulU8 multiplies two uint8's together and saturates at the numerical boundary if an overflow would have occurred.

func SaturatingPow

func SaturatingPow(n uint64, m uint32) uint64

func SaturatingSubU16

func SaturatingSubU16(a, b uint16) uint16

SaturatingSubU16 computes `a - b` for two uint16's and saturates at the numerical boundary (zero) if an underflow would have occurred.

func SaturatingSubU32

func SaturatingSubU32(a, b uint32) uint32

SaturatingSubU32 computes `a - b` for two uint32's and saturates at the numerical boundary (zero) if an underflow would have occurred.

func SaturatingSubU64

func SaturatingSubU64(a, b uint64) uint64

SaturatingSubU64 computes `a - b` for two uint64's and saturates at the numerical boundary (zero) if an underflow would have occurred.

func SaturatingSubU8

func SaturatingSubU8(a, b uint8) uint8

SaturatingSubU8 computes `a - b` for two uint8's and saturates at the numerical boundary if an underflow would have occurred.

Types

This section is empty.

Jump to

Keyboard shortcuts

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