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 ¶
- func Add(a, b int) (int, bool)
- func Add16(a, b int16) (int16, bool)
- func Add16p(a, b int16) int16
- func Add32(a, b int32) (int32, bool)
- func Add32p(a, b int32) int32
- func Add64(a, b int64) (int64, bool)
- func Add64p(a, b int64) int64
- func Add8(a, b int8) (int8, bool)
- func Add8p(a, b int8) int8
- func Addp(a, b int) int
- func Div(a, b int) (int, bool)
- func Div16(a, b int16) (int16, bool)
- func Div16p(a, b int16) int16
- func Div32(a, b int32) (int32, bool)
- func Div32p(a, b int32) int32
- func Div64(a, b int64) (int64, bool)
- func Div64p(a, b int64) int64
- func Div8(a, b int8) (int8, bool)
- func Div8p(a, b int8) int8
- func Divp(a, b int) int
- func Mul(a, b int) (int, bool)
- func Mul16(a, b int16) (int16, bool)
- func Mul16p(a, b int16) int16
- func Mul32(a, b int32) (int32, bool)
- func Mul32p(a, b int32) int32
- func Mul64(a, b int64) (int64, bool)
- func Mul64p(a, b int64) int64
- func Mul8(a, b int8) (int8, bool)
- func Mul8p(a, b int8) int8
- func Mulp(a, b int) int
- func Quotient(a, b int) (int, int, bool)
- func Quotient16(a, b int16) (int16, int16, bool)
- func Quotient32(a, b int32) (int32, int32, bool)
- func Quotient64(a, b int64) (int64, int64, bool)
- func Quotient8(a, b int8) (int8, int8, bool)
- func Sub(a, b int) (int, bool)
- func Sub16(a, b int16) (int16, bool)
- func Sub16p(a, b int16) int16
- func Sub32(a, b int32) (int32, bool)
- func Sub32p(a, b int32) int32
- func Sub64(a, b int64) (int64, bool)
- func Sub64p(a, b int64) int64
- func Sub8(a, b int8) (int8, bool)
- func Sub8p(a, b int8) int8
- func Subp(a, b int) int
Functions ¶
func Add ¶
Add sums two ints, returning the result and a boolean status.
func Add16 ¶
Add16 performs + operation on two int16 operands returning a result and status
func Add16p ¶
Add16p is the unchecked panicing version of Add16
func Add32 ¶
Add32 performs + operation on two int32 operands returning a result and status
func Add32p ¶
Add32p is the unchecked panicing version of Add32
func Add64 ¶
Add64 performs + operation on two int64 operands returning a result and status
func Add64p ¶
Add64p is the unchecked panicing version of Add64
func Add8 ¶
Add8 performs + operation on two int8 operands returning a result and status
func Add8p ¶
Add8p is the unchecked panicing version of Add8
func Addp ¶
Addp returns the sum of two ints, panicking on overflow
func Div ¶
Div returns the quotient of two ints and a boolean status
func Div16 ¶
Div16 performs / operation on two int16 operands returning a result and status
func Div16p ¶
Div16p is the unchecked panicing version of Div16
func Div32 ¶
Div32 performs / operation on two int32 operands returning a result and status
func Div32p ¶
Div32p is the unchecked panicing version of Div32
func Div64 ¶
Div64 performs / operation on two int64 operands returning a result and status
func Div64p ¶
Div64p is the unchecked panicing version of Div64
func Div8 ¶
Div8 performs / operation on two int8 operands returning a result and status
func Div8p ¶
Div8p is the unchecked panicing version of Div8
func Divp ¶
Divp returns the quotient of two ints, panicking on overflow.
func Mul ¶
Mul returns the product of two ints and a boolean status.
func Mul16 ¶
Mul16 performs * operation on two int16 operands returning a result and status
func Mul16p ¶
Mul16p is the unchecked panicing version of Mul16
func Mul32 ¶
Mul32 performs * operation on two int32 operands returning a result and status
func Mul32p ¶
Mul32p is the unchecked panicing version of Mul32
func Mul64 ¶
Mul64 performs * operation on two int64 operands returning a result and status
func Mul64p ¶
Mul64p is the unchecked panicing version of Mul64
func Mul8 ¶
Mul8 performs * operation on two int8 operands returning a result and status
func Mul8p ¶
Mul8p is the unchecked panicing version of Mul8
func Mulp ¶
Mulp returns the product of two ints, panicking on overflow.
func Quotient ¶
Quotient returns the quotient, remainder and status of two ints
func Quotient16 ¶
Quotient16 performs + operation on two int16 operands returning a quotient, a remainder and status
func Quotient32 ¶
Quotient32 performs + operation on two int32 operands returning a quotient, a remainder and status
func Quotient64 ¶
Quotient64 performs + operation on two int64 operands returning a quotient, a remainder and status
func Quotient8 ¶
Quotient8 performs + operation on two int8 operands returning a quotient, a remainder and status
func Sub ¶
Sub returns the difference of two ints and a boolean status.
func Sub16 ¶
Sub16 performs - operation on two int16 operands returning a result and status
func Sub16p ¶
Sub16p is the unchecked panicing version of Sub16
func Sub32 ¶
Sub32 performs - operation on two int32 operands returning a result and status
func Sub32p ¶
Sub32p is the unchecked panicing version of Sub32
func Sub64 ¶
Sub64 performs - operation on two int64 operands returning a result and status
func Sub64p ¶
Sub64p is the unchecked panicing version of Sub64
func Sub8 ¶
Sub8 performs - operation on two int8 operands returning a result and status
func Sub8p ¶
Sub8p is the unchecked panicing version of Sub8
func Subp ¶
Subp returns the difference of two ints, panicking on overflow.
Source Files ¶
- Version
- v0.0.0-20211019200055-46fa312c352c (latest)
- Published
- Oct 19, 2021
- Platform
- js/wasm
- Imports
- 1 packages
- Last checked
- now –
Tools for package owners.