overflow

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package overflow offers overflow-checked integer arithmetic operations for all signed and unsigned integer types. Each of the operations returns a result,bool combination.

The functions support all types convertible to unsigned or signed integer types. The modulo % operation is not present, as it is always safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add[N Number](a, b N) (N, bool)

Add sums two numbers, returning the result and a boolean status.

func Addp

func Addp[N Number](a, b N) N

Addp returns the sum of two numbers, panicking on overflow.

func Div

func Div[N Number](a, b N) (N, bool)

Div returns the quotient of two numbers and a boolean status.

func Divp

func Divp[N Number](a, b N) N

Divp returns the quotient of two numbers, panicking on overflow.

func Mul

func Mul[N Number](a, b N) (N, bool)

Mul returns the multiplication of two numbers and a boolean status.

func Mulp

func Mulp[N Number](a, b N) N

Mulp returns the product of two numbers, panicking on overflow.

func Sub

func Sub[N Number](a, b N) (N, bool)

Sub returns the difference of two numbers and a boolean status.

func Subp

func Subp[N Number](a, b N) N

Subp returns the difference of two numbers, panicking on overflow.

Types

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

Number is a type constraint for all integer values, signed and unsigned.

Jump to

Keyboard shortcuts

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