Documentation ¶
Overview ¶
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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
Types ¶
This section is empty.