overflow – github.com/JohnCGriffin/overflow Index | Files

package overflow

import "github.com/JohnCGriffin/overflow"

Package overflow offers overflow-checked integer arithmetic operations for int, int32, and int64. Each of the operations returns a result,bool combination. This was prompted by the need to know when to flow into higher precision types from the math.big library.

For instance, assuing a 64 bit machine:

10 + 20 -> 30 int(math.MaxInt64) + 1 -> -9223372036854775808

whereas

overflow.Add(10,20) -> (30, true) overflow.Add(math.MaxInt64,1) -> (0, false)

Add, Sub, Mul, Div are for int. Add64, Add32, etc. are specifically sized.

If anybody wishes an unsigned version, submit a pull request for code and new tests.

Index

Functions

func Add

func Add(a, b int) (int, bool)

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

func Add16

func Add16(a, b int16) (int16, bool)

Add16 performs + operation on two int16 operands returning a result and status

func Add16p

func Add16p(a, b int16) int16

Add16p is the unchecked panicing version of Add16

func Add32

func Add32(a, b int32) (int32, bool)

Add32 performs + operation on two int32 operands returning a result and status

func Add32p

func Add32p(a, b int32) int32

Add32p is the unchecked panicing version of Add32

func Add64

func Add64(a, b int64) (int64, bool)

Add64 performs + operation on two int64 operands returning a result and status

func Add64p

func Add64p(a, b int64) int64

Add64p is the unchecked panicing version of Add64

func Add8

func Add8(a, b int8) (int8, bool)

Add8 performs + operation on two int8 operands returning a result and status

func Add8p

func Add8p(a, b int8) int8

Add8p is the unchecked panicing version of Add8

func Addp

func Addp(a, b int) int

Addp returns the sum of two ints, panicking on overflow

func Div

func Div(a, b int) (int, bool)

Div returns the quotient of two ints and a boolean status

func Div16

func Div16(a, b int16) (int16, bool)

Div16 performs / operation on two int16 operands returning a result and status

func Div16p

func Div16p(a, b int16) int16

Div16p is the unchecked panicing version of Div16

func Div32

func Div32(a, b int32) (int32, bool)

Div32 performs / operation on two int32 operands returning a result and status

func Div32p

func Div32p(a, b int32) int32

Div32p is the unchecked panicing version of Div32

func Div64

func Div64(a, b int64) (int64, bool)

Div64 performs / operation on two int64 operands returning a result and status

func Div64p

func Div64p(a, b int64) int64

Div64p is the unchecked panicing version of Div64

func Div8

func Div8(a, b int8) (int8, bool)

Div8 performs / operation on two int8 operands returning a result and status

func Div8p

func Div8p(a, b int8) int8

Div8p is the unchecked panicing version of Div8

func Divp

func Divp(a, b int) int

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

func Mul

func Mul(a, b int) (int, bool)

Mul returns the product of two ints and a boolean status.

func Mul16

func Mul16(a, b int16) (int16, bool)

Mul16 performs * operation on two int16 operands returning a result and status

func Mul16p

func Mul16p(a, b int16) int16

Mul16p is the unchecked panicing version of Mul16

func Mul32

func Mul32(a, b int32) (int32, bool)

Mul32 performs * operation on two int32 operands returning a result and status

func Mul32p

func Mul32p(a, b int32) int32

Mul32p is the unchecked panicing version of Mul32

func Mul64

func Mul64(a, b int64) (int64, bool)

Mul64 performs * operation on two int64 operands returning a result and status

func Mul64p

func Mul64p(a, b int64) int64

Mul64p is the unchecked panicing version of Mul64

func Mul8

func Mul8(a, b int8) (int8, bool)

Mul8 performs * operation on two int8 operands returning a result and status

func Mul8p

func Mul8p(a, b int8) int8

Mul8p is the unchecked panicing version of Mul8

func Mulp

func Mulp(a, b int) int

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

func Quotient

func Quotient(a, b int) (int, int, bool)

Quotient returns the quotient, remainder and status of two ints

func Quotient16

func Quotient16(a, b int16) (int16, int16, bool)

Quotient16 performs + operation on two int16 operands returning a quotient, a remainder and status

func Quotient32

func Quotient32(a, b int32) (int32, int32, bool)

Quotient32 performs + operation on two int32 operands returning a quotient, a remainder and status

func Quotient64

func Quotient64(a, b int64) (int64, int64, bool)

Quotient64 performs + operation on two int64 operands returning a quotient, a remainder and status

func Quotient8

func Quotient8(a, b int8) (int8, int8, bool)

Quotient8 performs + operation on two int8 operands returning a quotient, a remainder and status

func Sub

func Sub(a, b int) (int, bool)

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

func Sub16

func Sub16(a, b int16) (int16, bool)

Sub16 performs - operation on two int16 operands returning a result and status

func Sub16p

func Sub16p(a, b int16) int16

Sub16p is the unchecked panicing version of Sub16

func Sub32

func Sub32(a, b int32) (int32, bool)

Sub32 performs - operation on two int32 operands returning a result and status

func Sub32p

func Sub32p(a, b int32) int32

Sub32p is the unchecked panicing version of Sub32

func Sub64

func Sub64(a, b int64) (int64, bool)

Sub64 performs - operation on two int64 operands returning a result and status

func Sub64p

func Sub64p(a, b int64) int64

Sub64p is the unchecked panicing version of Sub64

func Sub8

func Sub8(a, b int8) (int8, bool)

Sub8 performs - operation on two int8 operands returning a result and status

func Sub8p

func Sub8p(a, b int8) int8

Sub8p is the unchecked panicing version of Sub8

func Subp

func Subp(a, b int) int

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

Source Files

overflow.go overflow_impl.go

Version
v0.0.0-20211019200055-46fa312c352c (latest)
Published
Oct 19, 2021
Platform
js/wasm
Imports
1 packages
Last checked
now

Tools for package owners.