Documentation
¶
Overview ¶
Package safe provides safe casting operations for different data types.
Index ¶
- Constants
- Variables
- func Add32(x, y uint32) (uint32, error)
- func Add64(x, y uint64) (uint64, error)
- func Int8ToUint8(x int8) (uint8, error)
- func Int16ToUint16(x int16) (uint16, error)
- func Int32ToUint32(x int32) (uint32, error)
- func Int64ToInt32(x int64) (int32, error)
- func Int64ToUint32(x int64) (uint32, error)
- func Int64ToUint64(x int64) (uint64, error)
- func IntToInt8(x int) (int8, error)
- func IntToInt16(x int) (int16, error)
- func IntToInt32(x int) (int32, error)
- func IntToUint8(x int) (uint8, error)
- func IntToUint16(x int) (uint16, error)
- func IntToUint32(x int) (uint32, error)
- func IntToUint64(x int) (uint64, error)
- func Sub32(x, y uint32) (uint32, error)
- func Sub64(x, y uint64) (uint64, error)
- func Uint8ToInt8(x uint8) (int8, error)
- func Uint16ToInt16(x uint16) (int16, error)
- func Uint32ToInt(x uint32) (int, error)
- func Uint32ToInt32(x uint32) (int32, error)
- func Uint64ToInt(x uint64) (int, error)
- func Uint64ToInt32(x uint64) (int32, error)
- func Uint64ToInt64(x uint64) (int64, error)
- func Uint64ToUint32(x uint64) (uint32, error)
- func UintToUint8(x uint) (uint8, error)
- func UintToUint16(x uint) (uint16, error)
- func UintToUint32(x uint) (uint32, error)
Constants ¶
const IntSize = 32 << (^uint(0) >> 63) // taken from strconv.IntSize and math.intSize
IntSize is the size in bits of an int or uint value on the running platform. Either 32 or 64.
Variables ¶
var ( // An integer overflow occurred. ErrIntegerOverflow = errors.New("integer overflow occurred") // An integer underflow occurred. ErrIntegerUnderflow = errors.New("integer underflow occurred") )
Functions ¶
func Add32 ¶
Add two unsigned 32bit integers. Returns ErrIntegerOverflow if an overflow occurred.
func Add64 ¶
Add two unsigned 64bit integers. Returns ErrIntegerOverflow if an overflow occurred.
func Int8ToUint8 ¶
Cast from a signed 8bit integer to an unsigned 8bit integer. Return ErrIntegerUnderflow if x contains a negative number.
func Int16ToUint16 ¶
Cast from a signed 16bit integer to an unsigned 16bit integer. Return ErrIntegerUnderflow if x contains a negative number.
func Int32ToUint32 ¶
Cast from a signed 32bit integer to an unsigned 32bit integer. Return ErrIntegerUnderflow if x contains a negative number.
func Int64ToInt32 ¶
Downcast a signed 64bit integer to a signed 32bit integer. Returns ErrIntegerOverflow if an overflow occurred.
func Int64ToUint32 ¶
Downcast a signed 64bit integer to an unsigned 32bit integer. Returns ErrIntegerUnderflow if x is negative. Returns ErrIntegerOverflow if x is too big.
func Int64ToUint64 ¶
Cast from a signed 64bit integer to an unsigned 64bit integer. Return ErrIntegerUnderflow if x contains a negative number.
func IntToInt8 ¶
Cast from platform dependant signed integer to a signed 8bit integer. Return ErrIntegerUnderflow if x is too small. Return ErrIntegerOverflow if x is too big.
func IntToInt16 ¶
Cast from platform dependant signed integer to a signed 16bit integer. Return ErrIntegerUnderflow if x is too small. Return ErrIntegerOverflow if x is too big.
func IntToInt32 ¶
Cast from platform dependant signed integer to a signed 32bit integer. Return ErrIntegerUnderflow if x is too small. Return ErrIntegerOverflow if x is too big.
func IntToUint8 ¶
Cast from platform dependant signed integer to an unsigned 8bit integer. Return ErrIntegerUnderflow if x is too small. Return ErrIntegerOverflow if x is too big.
func IntToUint16 ¶
Cast from platform dependant signed integer to an unsigned 16bit integer. Return ErrIntegerUnderflow if x is too small. Return ErrIntegerOverflow if x is too big.
func IntToUint32 ¶
Cast from platform dependant signed integer to an unsigned 32bit integer. Return ErrIntegerUnderflow if x is too small. Return ErrIntegerOverflow if x is too big.
func IntToUint64 ¶
Cast from platform dependant signed integer to an unsigned 64bit integer. Return ErrIntegerUnderflow if x is too small.
func Sub32 ¶
Subtract two unsigned 32bit integers. Returns ErrIntegerUnderflow if an underflow occurred.
func Sub64 ¶
Subtract two unsigned 64bit integers. Returns ErrIntegerUnderflow if an underflow occurred.
func Uint8ToInt8 ¶
Cast from an unsigned 8bit integer to a signed 8bit integer. Return ErrIntegerOverflow if x is too big.
func Uint16ToInt16 ¶
Cast from an unsigned 16bit integer to a signed 16bit integer. Return ErrIntegerOverflow if x is too big.
func Uint32ToInt ¶
Cast from unsigned 32bit integer to platform dependant signed integer. Return ErrIntegerOverflow if x is too big.
func Uint32ToInt32 ¶
Cast from an unsigned 32bit integer to a signed 32bit integer. Return ErrIntegerOverflow if x is too big.
func Uint64ToInt ¶
Cast from unsigned 64bit integer to platform dependant signed integer. Return ErrIntegerOverflow if x is too big.
func Uint64ToInt32 ¶
Downcast an unsigned 64bit integer to a signed 32bit integer. Returns ErrIntegerOverflow if x is too big.
func Uint64ToInt64 ¶
Cast from an unsigned 64bit integer to a signed 64bit integer. Return ErrIntegerOverflow if x is too big.
func Uint64ToUint32 ¶
Downcast an unsigned 64bit integer to an unsigned 32bit integer. Returns ErrIntegerOverflow if an overflow occurred.
func UintToUint8 ¶
Cast from platform dependant unsigned integer to an unsigned 8bit integer. Return ErrIntegerOverflow if x is too big.
func UintToUint16 ¶
Cast from platform dependant unsigned integer to an unsigned 16bit integer. Return ErrIntegerOverflow if x is too big.
func UintToUint32 ¶
Cast from platform dependant unsigned integer to an unsigned 32bit integer. Return ErrIntegerOverflow if x is too big.
Types ¶
This section is empty.