Documentation ¶
Index ¶
- Variables
- func MaxInt(a, b int) int
- func MaxInt64(a, b int64) int64
- func MinInt(a, b int) int
- func MinInt64(a, b int64) int64
- func MustConvertInt32[T Integer](a T) int32
- func MustConvertUint32[T Integer](a T) uint32
- func SafeAddClipInt64(a, b int64) int64
- func SafeAddInt32(a, b int32) (int32, error)
- func SafeAddInt64(a, b int64) (int64, error)
- func SafeConvertInt32[T Integer](a T) (int32, error)
- func SafeConvertInt8(a int64) (int8, error)
- func SafeConvertUint32[T Integer](a T) (uint32, error)
- func SafeConvertUint8(a int64) (uint8, error)
- func SafeMulInt64(a, b int64) (int64, bool)
- func SafeSubClipInt64(a, b int64) int64
- func SafeSubInt32(a, b int32) (int32, error)
- func SafeSubInt64(a, b int64) (int64, bool)
- type Fraction
- type Integer
Constants ¶
This section is empty.
Variables ¶
var ErrOverflowInt32 = errors.New("int32 overflow")
var ErrOverflowInt64 = errors.New("int64 overflow")
var ErrOverflowInt8 = errors.New("int8 overflow")
var ErrOverflowUint32 = errors.New("uint32 overflow")
var ErrOverflowUint8 = errors.New("uint8 overflow")
Functions ¶
func MustConvertInt32 ¶ added in v1.3.0
MustConvertInt32 takes an Integer and converts it to int32. Panics if the conversion overflows.
func MustConvertUint32 ¶ added in v1.3.0
MustConvertInt32 takes an Integer and converts it to int32. Panics if the conversion overflows.
func SafeAddClipInt64 ¶ added in v1.3.0
SafeAddClipInt64 adds two int64 integers and clips the result to the int64 range.
func SafeAddInt32 ¶
SafeAddInt32 adds two int32 integers.
func SafeAddInt64 ¶ added in v1.3.0
SafeAddInt64 adds two int64 integers.
func SafeConvertInt32 ¶
SafeConvertInt32 takes a int and checks if it overflows.
func SafeConvertInt8 ¶
SafeConvertInt8 takes an int64 and checks if it overflows.
func SafeConvertUint32 ¶ added in v1.3.0
SafeConvertInt32 takes a int and checks if it overflows.
func SafeConvertUint8 ¶
SafeConvertUint8 takes an int64 and checks if it overflows.
func SafeMulInt64 ¶ added in v1.3.0
func SafeSubClipInt64 ¶ added in v1.3.0
func SafeSubInt32 ¶
SafeSubInt32 subtracts two int32 integers.
func SafeSubInt64 ¶ added in v1.3.0
Types ¶
type Fraction ¶
type Fraction struct { // The portion of the denominator in the faction, e.g. 2 in 2/3. Numerator uint64 `json:"numerator"` // The value by which the numerator is divided, e.g. 3 in 2/3. Denominator uint64 `json:"denominator"` }
Fraction defined in terms of a numerator divided by a denominator in uint64 format. Fraction must be positive.
func ParseFraction ¶
ParseFractions takes the string of a fraction as input i.e "2/3" and converts this to the equivalent fraction else returns an error. The format of the string must be one number followed by a slash (/) and then the other number.