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 Abs(x int) (int, bool)
- func Abs16(x int16) (int16, bool)
- func Abs32(x int32) (int32, bool)
- func Abs64(x int64) (int64, bool)
- func Abs8(x int8) (int8, bool)
- func Absp(x int) int
- 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 Int16ToInt8(x int16) (int8, bool)
- func Int16ToUint16(x int16) (uint16, bool)
- func Int16ToUint32(x int16) (uint32, bool)
- func Int16ToUint64(x int16) (uint64, bool)
- func Int16ToUint8(x int16) (uint8, bool)
- func Int32ToInt16(x int32) (int16, bool)
- func Int32ToInt8(x int32) (int8, bool)
- func Int32ToUint16(x int32) (uint16, bool)
- func Int32ToUint32(x int32) (uint32, bool)
- func Int32ToUint64(x int32) (uint64, bool)
- func Int32ToUint8(x int32) (uint8, bool)
- func Int64ToInt16(x int64) (int16, bool)
- func Int64ToInt32(x int64) (int32, bool)
- func Int64ToInt8(x int64) (int8, bool)
- func Int64ToUint16(x int64) (uint16, bool)
- func Int64ToUint32(x int64) (uint32, bool)
- func Int64ToUint64(x int64) (uint64, bool)
- func Int64ToUint8(x int64) (uint8, bool)
- func Int8ToUint16(x int8) (uint16, bool)
- func Int8ToUint32(x int8) (uint32, bool)
- func Int8ToUint64(x int8) (uint64, bool)
- func Int8ToUint8(x int8) (uint8, bool)
- func IntToUint(x int) (uint, bool)
- func IntToUintp(x int) uint
- 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
- func UAdd(a, b uint) (uint, bool)
- func UAdd16(a, b uint16) (uint16, bool)
- func UAdd16p(a, b uint16) uint16
- func UAdd32(a, b uint32) (uint32, bool)
- func UAdd32p(a, b uint32) uint32
- func UAdd64(a, b uint64) (uint64, bool)
- func UAdd64p(a, b uint64) uint64
- func UAdd8(a, b uint8) (uint8, bool)
- func UAdd8p(a, b uint8) uint8
- func UAddp(a, b uint) uint
- func UDiv(a, b uint) (uint, bool)
- func UDiv16(a, b uint16) (uint16, bool)
- func UDiv16p(a, b uint16) uint16
- func UDiv32(a, b uint32) (uint32, bool)
- func UDiv32p(a, b uint32) uint32
- func UDiv64(a, b uint64) (uint64, bool)
- func UDiv64p(a, b uint64) uint64
- func UDiv8(a, b uint8) (uint8, bool)
- func UDiv8p(a, b uint8) uint8
- func UDivp(a, b uint) uint
- func UMul(a, b uint) (uint, bool)
- func UMul16(a, b uint16) (uint16, bool)
- func UMul16p(a, b uint16) uint16
- func UMul32(a, b uint32) (uint32, bool)
- func UMul32p(a, b uint32) uint32
- func UMul64(a, b uint64) (uint64, bool)
- func UMul64p(a, b uint64) uint64
- func UMul8(a, b uint8) (uint8, bool)
- func UMul8p(a, b uint8) uint8
- func UMulp(a, b uint) uint
- func UQuotient(a, b uint) (uint, uint, bool)
- func UQuotient16(a, b uint16) (uint16, uint16, bool)
- func UQuotient32(a, b uint32) (uint32, uint32, bool)
- func UQuotient64(a, b uint64) (uint64, uint64, bool)
- func UQuotient8(a, b uint8) (uint8, uint8, bool)
- func USub(a, b uint) (uint, bool)
- func USub16(a, b uint16) (uint16, bool)
- func USub16p(a, b uint16) uint16
- func USub32(a, b uint32) (uint32, bool)
- func USub32p(a, b uint32) uint32
- func USub64(a, b uint64) (uint64, bool)
- func USub64p(a, b uint64) uint64
- func USub8(a, b uint8) (uint8, bool)
- func USub8p(a, b uint8) uint8
- func USubp(a, b uint) uint
- func Uint16ToInt16(x uint16) (int16, bool)
- func Uint16ToInt8(x uint16) (int8, bool)
- func Uint16ToUint8(x uint16) (uint8, bool)
- func Uint32ToInt16(x uint32) (int16, bool)
- func Uint32ToInt32(x uint32) (int32, bool)
- func Uint32ToInt8(x uint32) (int8, bool)
- func Uint32ToUint16(x uint32) (uint16, bool)
- func Uint32ToUint8(x uint32) (uint8, bool)
- func Uint64ToInt16(x uint64) (int16, bool)
- func Uint64ToInt32(x uint64) (int32, bool)
- func Uint64ToInt64(x uint64) (int64, bool)
- func Uint64ToInt8(x uint64) (int8, bool)
- func Uint64ToUint16(x uint64) (uint16, bool)
- func Uint64ToUint32(x uint64) (uint32, bool)
- func Uint64ToUint8(x uint64) (uint8, bool)
- func Uint8ToInt8(x uint8) (int8, bool)
- func UintToInt(x uint) (int, bool)
- func UintToIntp(x uint) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
Abs get absolute value of an int, returning the result and a ok result indicating whether the operation is safe.
func Abs16 ¶
Abs16 performs absolute value operation on an int16 operand returning a result and a ok result indicating whether the operation is safe.
func Abs32 ¶
Abs32 performs absolute value operation on an int32 operand returning a result and a ok result indicating whether the operation is safe.
func Abs64 ¶
Abs64 performs absolute value operation on an int64 operand returning a result and a ok result indicating whether the operation is safe.
func Abs8 ¶
Abs8 performs absolute value operation on an int8 operand returning a result and a ok result indicating whether the operation is safe.
func Add ¶
Add sums two ints, returning the result and a ok result indicating whether the operation is safe.
func Add16 ¶
Add16 performs + operation on two int16 operands returning a result and a ok result indicating whether the operation is safe.
func Add32 ¶
Add32 performs + operation on two int32 operands returning a result and a ok result indicating whether the operation is safe.
func Add64 ¶
Add64 performs + operation on two int64 operands returning a result and a ok result indicating whether the operation is safe.
func Add8 ¶
Add8 performs + operation on two int8 operands returning a result and a ok result indicating whether the operation is safe.
func Div ¶
Div returns the quotient of two ints and a ok result indicating whether the operation is safe.
func Div16 ¶
Div16 performs / operation on two int16 operands returning a result and a ok result indicating whether the operation is safe.
func Div32 ¶
Div32 performs / operation on two int32 operands returning a result and a ok result indicating whether the operation is safe.
func Div64 ¶
Div64 performs / operation on two int64 operands returning a result and a ok result indicating whether the operation is safe.
func Div8 ¶
Div8 performs / operation on two int8 operands returning a result and a ok result indicating whether the operation is safe.
func Int16ToInt8 ¶
Int16ToInt8 converts an int16 value to int8. returning a converted value and a ok result indicating whether the operation is safe.
func Int16ToUint16 ¶
Int16ToUint16 converts an int16 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.
func Int16ToUint32 ¶
Int16ToUint32 converts an int16 value to uint32. returning a converted value and a ok result indicating whether the operation is safe.
func Int16ToUint64 ¶
Int16ToUint64 converts an int16 value to uint64. returning a converted value and a ok result indicating whether the operation is safe.
func Int16ToUint8 ¶
Int16ToUint8 converts an int16 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.
func Int32ToInt16 ¶
Int32ToInt16 converts an int32 value to int16. returning a converted value and a ok result indicating whether the operation is safe.
func Int32ToInt8 ¶
Int32ToInt8 converts an int32 value to int8. returning a converted value and a ok result indicating whether the operation is safe.
func Int32ToUint16 ¶
Int32ToUint16 converts an int32 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.
func Int32ToUint32 ¶
Int32ToUint32 converts an int32 value to uint32. returning a converted value and a ok result indicating whether the operation is safe.
func Int32ToUint64 ¶
Int32ToUint64 converts an int32 value to uint64. returning a converted value and a ok result indicating whether the operation is safe.
func Int32ToUint8 ¶
Int32ToUint8 converts an int32 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.
func Int64ToInt16 ¶
Int64ToInt16 converts an int64 value to int16. returning a converted value and a ok result indicating whether the operation is safe.
func Int64ToInt32 ¶
Int64ToInt32 converts an int64 value to int32. returning a converted value and a ok result indicating whether the operation is safe.
func Int64ToInt8 ¶
Int64ToInt8 converts an int64 value to int8. returning a converted value and a ok result indicating whether the operation is safe.
func Int64ToUint16 ¶
Int64ToUint16 converts an int64 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.
func Int64ToUint32 ¶
Int64ToUint32 converts an int64 value to uint32. returning a converted value and a ok result indicating whether the operation is safe.
func Int64ToUint64 ¶
Int64ToUint64 converts an int64 value to uint64. returning a converted value and a ok result indicating whether the operation is safe.
func Int64ToUint8 ¶
Int64ToUint8 converts an int64 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.
func Int8ToUint16 ¶
Int8ToUint16 converts an int8 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.
func Int8ToUint32 ¶
Int8ToUint32 converts an int8 value to uint32. returning a converted value and a ok result indicating whether the operation is safe.
func Int8ToUint64 ¶
Int8ToUint64 converts an int8 value to uint64. returning a converted value and a ok result indicating whether the operation is safe.
func Int8ToUint8 ¶
Int8ToUint8 converts an int8 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.
func IntToUint ¶
IntToUint converts an int value to uint. returning a converted value and a bool value indicating whether the operation is safe.
func IntToUintp ¶
IntToUintp converts an uint value to int, panicking on overflow.
func Mul ¶
Mul returns the product of two ints and a ok result indicating whether the operation is safe.
func Mul16 ¶
Mul16 performs * operation on two int16 operands returning a result and a ok result indicating whether the operation is safe.
func Mul32 ¶
Mul32 performs * operation on two int32 operands returning a result and a ok result indicating whether the operation is safe.
func Mul64 ¶
Mul64 performs * operation on two int64 operands returning a result and a ok result indicating whether the operation is safe.
func Mul8 ¶
Mul8 performs * operation on two int8 operands returning a result and a ok result indicating whether the operation is safe.
func Quotient ¶
Quotient returns the quotient, remainder and ok result indicating whether the operation is safe.
func Quotient16 ¶
Quotient16 performs + operation on two int16 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.
func Quotient32 ¶
Quotient32 performs + operation on two int32 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.
func Quotient64 ¶
Quotient64 performs + operation on two int64 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.
func Quotient8 ¶
Quotient8 performs + operation on two int8 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.
func Sub ¶
Sub returns the difference of two ints and a ok result indicating whether the operation is safe.
func Sub16 ¶
Sub16 performs - operation on two int16 operands returning a result and a ok result indicating whether the operation is safe.
func Sub32 ¶
Sub32 performs - operation on two int32 operands returning a result and a ok result indicating whether the operation is safe.
func Sub64 ¶
Sub64 performs - operation on two int64 operands returning a result and a ok result indicating whether the operation is safe.
func Sub8 ¶
Sub8 performs - operation on two int8 operands returning a result and a ok result indicating whether the operation is safe.
func UAdd ¶
UAdd sums two uints, returning the result and a ok result indicating whether the operation is safe.
func UAdd16 ¶
UAdd16 performs + operation on two uint16 operands returning a result and a ok result indicating whether the operation is safe.
func UAdd32 ¶
UAdd32 performs + operation on two uint32 operands returning a result and a ok result indicating whether the operation is safe.
func UAdd64 ¶
UAdd64 performs + operation on two uint64 operands returning a result and a ok result indicating whether the operation is safe.
func UAdd8 ¶
UAdd8 performs + operation on two uint8 operands returning a result and a ok result indicating whether the operation is safe.
func UDiv ¶
UDiv returns the quotient of two uints and a ok result indicating whether the operation is safe.
func UDiv16 ¶
UDiv16 performs / operation on two uint16 operands returning a result and a ok result indicating whether the operation is safe.
func UDiv32 ¶
UDiv32 performs / operation on two uint32 operands returning a result and a ok result indicating whether the operation is safe.
func UDiv64 ¶
UDiv64 performs / operation on two uint64 operands returning a result and a ok result indicating whether the operation is safe.
func UDiv8 ¶
UDiv8 performs / operation on two uint8 operands returning a result and a ok result indicating whether the operation is safe.
func UMul ¶
UMul returns the product of two uints and a ok result indicating whether the operation is safe.
func UMul16 ¶
UMul16 performs * operation on two uint16 operands returning a result and a ok result indicating whether the operation is safe.
func UMul32 ¶
UMul32 performs * operation on two uint32 operands returning a result and a ok result indicating whether the operation is safe.
func UMul64 ¶
UMul64 performs * operation on two uint64 operands returning a result and a ok result indicating whether the operation is safe.
func UMul8 ¶
UMul8 performs * operation on two uint8 operands returning a result and a ok result indicating whether the operation is safe.
func UQuotient ¶
UQuotient returns the quotient, remainder and ok result indicating whether the operation is safe.
func UQuotient16 ¶
UQuotient16 performs + operation on two uint16 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.
func UQuotient32 ¶
UQuotient32 performs + operation on two uint32 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.
func UQuotient64 ¶
UQuotient64 performs + operation on two uint64 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.
func UQuotient8 ¶
UQuotient8 performs + operation on two uint8 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.
func USub ¶
USub returns the difference of two uints and a ok result indicating whether the operation is safe.
func USub16 ¶
USub16 performs - operation on two uint16 operands returning a result and a ok result indicating whether the operation is safe.
func USub32 ¶
USub32 performs - operation on two uint32 operands returning a result and a ok result indicating whether the operation is safe.
func USub64 ¶
USub64 performs - operation on two uint64 operands returning a result and a ok result indicating whether the operation is safe.
func USub8 ¶
USub8 performs - operation on two uint8 operands returning a result and a ok result indicating whether the operation is safe.
func Uint16ToInt16 ¶
Uint16ToInt16 converts an uint16 value to int16. returning a converted value and a ok result indicating whether the operation is safe.
func Uint16ToInt8 ¶
Uint16ToInt8 converts an uint16 value to int8. returning a converted value and a ok result indicating whether the operation is safe.
func Uint16ToUint8 ¶
Uint16ToUint8 converts an uint16 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.
func Uint32ToInt16 ¶
Uint32ToInt16 converts an uint32 value to int16. returning a converted value and a ok result indicating whether the operation is safe.
func Uint32ToInt32 ¶
Uint32ToInt32 converts an uint32 value to int32. returning a converted value and a ok result indicating whether the operation is safe.
func Uint32ToInt8 ¶
Uint32ToInt8 converts an uint32 value to int8. returning a converted value and a ok result indicating whether the operation is safe.
func Uint32ToUint16 ¶
Uint32ToUint16 converts an uint32 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.
func Uint32ToUint8 ¶
Uint32ToUint8 converts an uint32 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.
func Uint64ToInt16 ¶
Uint64ToInt16 converts an uint64 value to int16. returning a converted value and a ok result indicating whether the operation is safe.
func Uint64ToInt32 ¶
Uint64ToInt32 converts an uint64 value to int32. returning a converted value and a ok result indicating whether the operation is safe.
func Uint64ToInt64 ¶
Uint64ToInt64 converts an uint64 value to int64. returning a converted value and a ok result indicating whether the operation is safe.
func Uint64ToInt8 ¶
Uint64ToInt8 converts an uint64 value to int8. returning a converted value and a ok result indicating whether the operation is safe.
func Uint64ToUint16 ¶
Uint64ToUint16 converts an uint64 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.
func Uint64ToUint32 ¶
Uint64ToUint32 converts an uint64 value to uint32. returning a converted value and a ok result indicating whether the operation is safe.
func Uint64ToUint8 ¶
Uint64ToUint8 converts an uint64 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.
func Uint8ToInt8 ¶
Uint8ToInt8 converts an uint8 value to int8. returning a converted value and a ok result indicating whether the operation is safe.
func UintToInt ¶
UintToInt converts an uint value to int. returning a converted value and a bool value indicating whether the operation is safe.
func UintToIntp ¶
UintToIntp converts an uint value to int, panicking on overflow.
Types ¶
This section is empty.