overflow

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 1 Imported by: 0

README

overflow

Check for integer overflow in Golang arithmetic and type conversion.

Other language README: 中文版

Install

This is still a maintenance fork until it is merged upstream.

This repository forks from johncgriffin/overflow and adds overflow detection for unsigned integer arithmetic and type conversions between integers.

It has been well tested and benchmarked, and passed the code security scan provided by Github Workflow.

CodeQL

go get github.com/rwxe/overflow

In order to be compatible with the old code and keep the code simple and readable, the new code still does not use generics, but uses templates to generate code. So the majority of repetitive code is generated by overflow_template.sh.

If you have to change an algorithm, change it there and regenerate the Go code via:

go generate
Synopsis
Arithmetic overflow detection
import "github.com/rwxe/overflow"

func main() {
    addend := math.MaxInt64 - 5
    for i := 0; i < 10; i++ {
        sum, ok := overflow.Add(addend, i)
        fmt.Printf("%v+%v -> (%v,%v)\n", addend, i, sum, ok)
    }
}

yields the output

9223372036854775802+0 -> (9223372036854775802,true)
9223372036854775802+1 -> (9223372036854775803,true)
9223372036854775802+2 -> (9223372036854775804,true)
9223372036854775802+3 -> (9223372036854775805,true)
9223372036854775802+4 -> (9223372036854775806,true)
9223372036854775802+5 -> (9223372036854775807,true)
9223372036854775802+6 -> (0,false)
9223372036854775802+7 -> (0,false)
9223372036854775802+8 -> (0,false)
9223372036854775802+9 -> (0,false)

For (u)int types, provide (U)Add, (U)Sub, (U)Mul, (U)Div, (U)Quotient, etc.

Type conversion overflow detection
func main() {
    var i uint
    for i = math.MaxInt - 5; i <= math.MaxInt+5; i++ {
        ret, ok := overflow.UintToInt(i)
        fmt.Printf("%v -> (%v,%v)\n", i, ret, ok)
    }
}

yields the output

9223372036854775802 -> (9223372036854775802,true)
9223372036854775803 -> (9223372036854775803,true)
9223372036854775804 -> (9223372036854775804,true)
9223372036854775805 -> (9223372036854775805,true)
9223372036854775806 -> (9223372036854775806,true)
9223372036854775807 -> (9223372036854775807,true)
9223372036854775808 -> (-9223372036854775808,false)
9223372036854775809 -> (-9223372036854775807,false)
9223372036854775810 -> (-9223372036854775806,false)
9223372036854775811 -> (-9223372036854775805,false)
9223372036854775812 -> (-9223372036854775804,false)

Provide UintToInt, IntToUint, Uint64ToInt32, Int32ToUint64, etc.

Get absolute value
func main() {
    normalAbs := func(x int64) int64 {
        if x < 0 {
            x = -x
        }
        return x
    }
    var i1, j1, k1 int64 = -9007199254740993, -9007199254740993, -9007199254740993
    fmt.Println(int64(math.Abs(float64(i1))))
    fmt.Println(normalAbs(j1))
    fmt.Println(overflow.Abs64(k1))

    var i2, j2, k2 int64 = math.MinInt64, math.MinInt64, math.MinInt64
    fmt.Println(int64(math.Abs(float64(i2))))
    fmt.Println(normalAbs(j2))
    fmt.Println(overflow.Abs64(k2))
}

yields the output

9007199254740992 // Mantissa overflow, precision lost
9007199254740993
9007199254740993 true
-9223372036854775808
-9223372036854775808
-9223372036854775808 false // Overflow detected

For int, provides an absolute value including overflow detection.

Stay calm and panic

There's a good case to be made that a panic is an unidiomatic but proper response. If you believe that there's no valid way to continue your program after math goes wayward, you can use the easier Addp, Mulp, Subp, Divp, IntToUintp, Absp etc, which return the normal result or panic.

Performance considerations

Compared to integer safe libraries in other languages (e.g. C++), this library uses some seemingly slow operations, such as division. But that doesn't mean these methods will be slow. In fact, because of Go's automatic inlining strategy for short functions and compiler optimizations, these operations are actually very fast in benchmark tests, lightning fast.

In addition, Go defines the overflow behavior of signed integers, making the detection of signed integer overflow simple and efficient.

Note that using //go:noinline in your business function will not affect the inlining of the library function. Only disabling global inlining through -gcflags="-l" will affect the inlining of this library function.

Basis and dependencies

The library is developed based on Go's official compiler implementation (gc) and language specifications.

License

MIT LICENSE

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int) (int, bool)

Abs get absolute value of an int, returning the result and a ok result indicating whether the operation is safe.

func Abs16

func Abs16(x int16) (int16, bool)

Abs16 performs absolute value operation on an int16 operand returning a result and a ok result indicating whether the operation is safe.

func Abs32

func Abs32(x int32) (int32, bool)

Abs32 performs absolute value operation on an int32 operand returning a result and a ok result indicating whether the operation is safe.

func Abs64

func Abs64(x int64) (int64, bool)

Abs64 performs absolute value operation on an int64 operand returning a result and a ok result indicating whether the operation is safe.

func Abs8

func Abs8(x int8) (int8, bool)

Abs8 performs absolute value operation on an int8 operand returning a result and a ok result indicating whether the operation is safe.

func Absp

func Absp(x int) int

Absp returns the absolute value, panicking on overflow

func Add

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

Add sums two ints, returning the result and a ok result indicating whether the operation is safe.

func Add16

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

Add16 performs + operation on two int16 operands returning a result and a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 ok result indicating whether the operation is safe.

func Div16

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

Div16 performs / operation on two int16 operands returning a result and a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 Int16ToInt8

func Int16ToInt8(x int16) (int8, bool)

Int16ToInt8 converts an int16 value to int8. returning a converted value and a ok result indicating whether the operation is safe.

func Int16ToUint16

func Int16ToUint16(x int16) (uint16, bool)

Int16ToUint16 converts an int16 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.

func Int16ToUint32

func Int16ToUint32(x int16) (uint32, bool)

Int16ToUint32 converts an int16 value to uint32. returning a converted value and a ok result indicating whether the operation is safe.

func Int16ToUint64

func Int16ToUint64(x int16) (uint64, bool)

Int16ToUint64 converts an int16 value to uint64. returning a converted value and a ok result indicating whether the operation is safe.

func Int16ToUint8

func Int16ToUint8(x int16) (uint8, bool)

Int16ToUint8 converts an int16 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.

func Int32ToInt16

func Int32ToInt16(x int32) (int16, bool)

Int32ToInt16 converts an int32 value to int16. returning a converted value and a ok result indicating whether the operation is safe.

func Int32ToInt8

func Int32ToInt8(x int32) (int8, bool)

Int32ToInt8 converts an int32 value to int8. returning a converted value and a ok result indicating whether the operation is safe.

func Int32ToUint16

func Int32ToUint16(x int32) (uint16, bool)

Int32ToUint16 converts an int32 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.

func Int32ToUint32

func Int32ToUint32(x int32) (uint32, bool)

Int32ToUint32 converts an int32 value to uint32. returning a converted value and a ok result indicating whether the operation is safe.

func Int32ToUint64

func Int32ToUint64(x int32) (uint64, bool)

Int32ToUint64 converts an int32 value to uint64. returning a converted value and a ok result indicating whether the operation is safe.

func Int32ToUint8

func Int32ToUint8(x int32) (uint8, bool)

Int32ToUint8 converts an int32 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.

func Int64ToInt16

func Int64ToInt16(x int64) (int16, bool)

Int64ToInt16 converts an int64 value to int16. returning a converted value and a ok result indicating whether the operation is safe.

func Int64ToInt32

func Int64ToInt32(x int64) (int32, bool)

Int64ToInt32 converts an int64 value to int32. returning a converted value and a ok result indicating whether the operation is safe.

func Int64ToInt8

func Int64ToInt8(x int64) (int8, bool)

Int64ToInt8 converts an int64 value to int8. returning a converted value and a ok result indicating whether the operation is safe.

func Int64ToUint16

func Int64ToUint16(x int64) (uint16, bool)

Int64ToUint16 converts an int64 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.

func Int64ToUint32

func Int64ToUint32(x int64) (uint32, bool)

Int64ToUint32 converts an int64 value to uint32. returning a converted value and a ok result indicating whether the operation is safe.

func Int64ToUint64

func Int64ToUint64(x int64) (uint64, bool)

Int64ToUint64 converts an int64 value to uint64. returning a converted value and a ok result indicating whether the operation is safe.

func Int64ToUint8

func Int64ToUint8(x int64) (uint8, bool)

Int64ToUint8 converts an int64 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.

func Int8ToUint16

func Int8ToUint16(x int8) (uint16, bool)

Int8ToUint16 converts an int8 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.

func Int8ToUint32

func Int8ToUint32(x int8) (uint32, bool)

Int8ToUint32 converts an int8 value to uint32. returning a converted value and a ok result indicating whether the operation is safe.

func Int8ToUint64

func Int8ToUint64(x int8) (uint64, bool)

Int8ToUint64 converts an int8 value to uint64. returning a converted value and a ok result indicating whether the operation is safe.

func Int8ToUint8

func Int8ToUint8(x int8) (uint8, bool)

Int8ToUint8 converts an int8 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.

func IntToUint

func IntToUint(x int) (uint, bool)

IntToUint converts an int value to uint. returning a converted value and a bool value indicating whether the operation is safe.

func IntToUintp

func IntToUintp(x int) uint

IntToUintp converts an uint value to int, panicking on overflow.

func Mul

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

Mul returns the product of two ints and a ok result indicating whether the operation is safe.

func Mul16

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

Mul16 performs * operation on two int16 operands returning a result and a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 ok result indicating whether the operation is safe.

func Quotient16

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

Quotient16 performs + operation on two int16 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.

func Quotient32

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

Quotient32 performs + operation on two int32 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.

func Quotient64

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

Quotient64 performs + operation on two int64 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.

func Quotient8

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

Quotient8 performs + operation on two int8 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.

func Sub

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

Sub returns the difference of two ints and a ok result indicating whether the operation is safe.

func Sub16

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

Sub16 performs - operation on two int16 operands returning a result and a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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 a ok result indicating whether the operation is safe.

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.

func UAdd

func UAdd(a, b uint) (uint, bool)

UAdd sums two uints, returning the result and a ok result indicating whether the operation is safe.

func UAdd16

func UAdd16(a, b uint16) (uint16, bool)

UAdd16 performs + operation on two uint16 operands returning a result and a ok result indicating whether the operation is safe.

func UAdd16p

func UAdd16p(a, b uint16) uint16

UAdd16p is the unchecked panicing version of UAdd16

func UAdd32

func UAdd32(a, b uint32) (uint32, bool)

UAdd32 performs + operation on two uint32 operands returning a result and a ok result indicating whether the operation is safe.

func UAdd32p

func UAdd32p(a, b uint32) uint32

UAdd32p is the unchecked panicing version of UAdd32

func UAdd64

func UAdd64(a, b uint64) (uint64, bool)

UAdd64 performs + operation on two uint64 operands returning a result and a ok result indicating whether the operation is safe.

func UAdd64p

func UAdd64p(a, b uint64) uint64

UAdd64p is the unchecked panicing version of UAdd64

func UAdd8

func UAdd8(a, b uint8) (uint8, bool)

UAdd8 performs + operation on two uint8 operands returning a result and a ok result indicating whether the operation is safe.

func UAdd8p

func UAdd8p(a, b uint8) uint8

UAdd8p is the unchecked panicing version of UAdd8

func UAddp

func UAddp(a, b uint) uint

UAddp returns the sum of two uints, panicking on overflow

func UDiv

func UDiv(a, b uint) (uint, bool)

UDiv returns the quotient of two uints and a ok result indicating whether the operation is safe.

func UDiv16

func UDiv16(a, b uint16) (uint16, bool)

UDiv16 performs / operation on two uint16 operands returning a result and a ok result indicating whether the operation is safe.

func UDiv16p

func UDiv16p(a, b uint16) uint16

UDiv16p is the unchecked panicing version of UDiv16

func UDiv32

func UDiv32(a, b uint32) (uint32, bool)

UDiv32 performs / operation on two uint32 operands returning a result and a ok result indicating whether the operation is safe.

func UDiv32p

func UDiv32p(a, b uint32) uint32

UDiv32p is the unchecked panicing version of UDiv32

func UDiv64

func UDiv64(a, b uint64) (uint64, bool)

UDiv64 performs / operation on two uint64 operands returning a result and a ok result indicating whether the operation is safe.

func UDiv64p

func UDiv64p(a, b uint64) uint64

UDiv64p is the unchecked panicing version of UDiv64

func UDiv8

func UDiv8(a, b uint8) (uint8, bool)

UDiv8 performs / operation on two uint8 operands returning a result and a ok result indicating whether the operation is safe.

func UDiv8p

func UDiv8p(a, b uint8) uint8

UDiv8p is the unchecked panicing version of UDiv8

func UDivp

func UDivp(a, b uint) uint

UDivp returns the quotient of two uints, panicking on overflow.

func UMul

func UMul(a, b uint) (uint, bool)

UMul returns the product of two uints and a ok result indicating whether the operation is safe.

func UMul16

func UMul16(a, b uint16) (uint16, bool)

UMul16 performs * operation on two uint16 operands returning a result and a ok result indicating whether the operation is safe.

func UMul16p

func UMul16p(a, b uint16) uint16

UMul16p is the unchecked panicing version of UMul16

func UMul32

func UMul32(a, b uint32) (uint32, bool)

UMul32 performs * operation on two uint32 operands returning a result and a ok result indicating whether the operation is safe.

func UMul32p

func UMul32p(a, b uint32) uint32

UMul32p is the unchecked panicing version of UMul32

func UMul64

func UMul64(a, b uint64) (uint64, bool)

UMul64 performs * operation on two uint64 operands returning a result and a ok result indicating whether the operation is safe.

func UMul64p

func UMul64p(a, b uint64) uint64

UMul64p is the unchecked panicing version of UMul64

func UMul8

func UMul8(a, b uint8) (uint8, bool)

UMul8 performs * operation on two uint8 operands returning a result and a ok result indicating whether the operation is safe.

func UMul8p

func UMul8p(a, b uint8) uint8

UMul8p is the unchecked panicing version of UMul8

func UMulp

func UMulp(a, b uint) uint

UMulp returns the product of two uints, panicking on overflow.

func UQuotient

func UQuotient(a, b uint) (uint, uint, bool)

UQuotient returns the quotient, remainder and ok result indicating whether the operation is safe.

func UQuotient16

func UQuotient16(a, b uint16) (uint16, uint16, bool)

UQuotient16 performs + operation on two uint16 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.

func UQuotient32

func UQuotient32(a, b uint32) (uint32, uint32, bool)

UQuotient32 performs + operation on two uint32 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.

func UQuotient64

func UQuotient64(a, b uint64) (uint64, uint64, bool)

UQuotient64 performs + operation on two uint64 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.

func UQuotient8

func UQuotient8(a, b uint8) (uint8, uint8, bool)

UQuotient8 performs + operation on two uint8 operands returning a quotient, a remainder and a ok result indicating whether the operation is safe.

func USub

func USub(a, b uint) (uint, bool)

USub returns the difference of two uints and a ok result indicating whether the operation is safe.

func USub16

func USub16(a, b uint16) (uint16, bool)

USub16 performs - operation on two uint16 operands returning a result and a ok result indicating whether the operation is safe.

func USub16p

func USub16p(a, b uint16) uint16

USub16p is the unchecked panicing version of USub16

func USub32

func USub32(a, b uint32) (uint32, bool)

USub32 performs - operation on two uint32 operands returning a result and a ok result indicating whether the operation is safe.

func USub32p

func USub32p(a, b uint32) uint32

USub32p is the unchecked panicing version of USub32

func USub64

func USub64(a, b uint64) (uint64, bool)

USub64 performs - operation on two uint64 operands returning a result and a ok result indicating whether the operation is safe.

func USub64p

func USub64p(a, b uint64) uint64

USub64p is the unchecked panicing version of USub64

func USub8

func USub8(a, b uint8) (uint8, bool)

USub8 performs - operation on two uint8 operands returning a result and a ok result indicating whether the operation is safe.

func USub8p

func USub8p(a, b uint8) uint8

USub8p is the unchecked panicing version of USub8

func USubp

func USubp(a, b uint) uint

USubp returns the difference of two uints, panicking on overflow.

func Uint16ToInt16

func Uint16ToInt16(x uint16) (int16, bool)

Uint16ToInt16 converts an uint16 value to int16. returning a converted value and a ok result indicating whether the operation is safe.

func Uint16ToInt8

func Uint16ToInt8(x uint16) (int8, bool)

Uint16ToInt8 converts an uint16 value to int8. returning a converted value and a ok result indicating whether the operation is safe.

func Uint16ToUint8

func Uint16ToUint8(x uint16) (uint8, bool)

Uint16ToUint8 converts an uint16 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.

func Uint32ToInt16

func Uint32ToInt16(x uint32) (int16, bool)

Uint32ToInt16 converts an uint32 value to int16. returning a converted value and a ok result indicating whether the operation is safe.

func Uint32ToInt32

func Uint32ToInt32(x uint32) (int32, bool)

Uint32ToInt32 converts an uint32 value to int32. returning a converted value and a ok result indicating whether the operation is safe.

func Uint32ToInt8

func Uint32ToInt8(x uint32) (int8, bool)

Uint32ToInt8 converts an uint32 value to int8. returning a converted value and a ok result indicating whether the operation is safe.

func Uint32ToUint16

func Uint32ToUint16(x uint32) (uint16, bool)

Uint32ToUint16 converts an uint32 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.

func Uint32ToUint8

func Uint32ToUint8(x uint32) (uint8, bool)

Uint32ToUint8 converts an uint32 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.

func Uint64ToInt16

func Uint64ToInt16(x uint64) (int16, bool)

Uint64ToInt16 converts an uint64 value to int16. returning a converted value and a ok result indicating whether the operation is safe.

func Uint64ToInt32

func Uint64ToInt32(x uint64) (int32, bool)

Uint64ToInt32 converts an uint64 value to int32. returning a converted value and a ok result indicating whether the operation is safe.

func Uint64ToInt64

func Uint64ToInt64(x uint64) (int64, bool)

Uint64ToInt64 converts an uint64 value to int64. returning a converted value and a ok result indicating whether the operation is safe.

func Uint64ToInt8

func Uint64ToInt8(x uint64) (int8, bool)

Uint64ToInt8 converts an uint64 value to int8. returning a converted value and a ok result indicating whether the operation is safe.

func Uint64ToUint16

func Uint64ToUint16(x uint64) (uint16, bool)

Uint64ToUint16 converts an uint64 value to uint16. returning a converted value and a ok result indicating whether the operation is safe.

func Uint64ToUint32

func Uint64ToUint32(x uint64) (uint32, bool)

Uint64ToUint32 converts an uint64 value to uint32. returning a converted value and a ok result indicating whether the operation is safe.

func Uint64ToUint8

func Uint64ToUint8(x uint64) (uint8, bool)

Uint64ToUint8 converts an uint64 value to uint8. returning a converted value and a ok result indicating whether the operation is safe.

func Uint8ToInt8

func Uint8ToInt8(x uint8) (int8, bool)

Uint8ToInt8 converts an uint8 value to int8. returning a converted value and a ok result indicating whether the operation is safe.

func UintToInt

func UintToInt(x uint) (int, bool)

UintToInt converts an uint value to int. returning a converted value and a bool value indicating whether the operation is safe.

func UintToIntp

func UintToIntp(x uint) int

UintToIntp converts an uint value to int, panicking on overflow.

Types

This section is empty.

Jump to

Keyboard shortcuts

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