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 SafeAddInt32(a, b int32) int32
- func SafeConvertInt32(a int64) int32
- func SafeConvertInt8(a int64) (int8, error)
- func SafeConvertUint8(a int64) (uint8, error)
- func SafeSubInt32(a, b int32) int32
- type Fraction
Constants ¶
This section is empty.
Variables ¶
var ErrOverflowInt32 = errors.New("int32 overflow")
var ErrOverflowInt8 = errors.New("int8 overflow")
var ErrOverflowUint8 = errors.New("uint8 overflow")
Functions ¶
func SafeAddInt32 ¶ added in v0.34.0
SafeAddInt32 adds two int32 integers If there is an overflow this will panic
func SafeConvertInt32 ¶ added in v0.34.0
SafeConvertInt32 takes a int and checks if it overflows If there is an overflow this will panic
func SafeConvertInt8 ¶ added in v0.34.0
SafeConvertInt8 takes an int64 and checks if it overflows If there is an overflow it returns an error
func SafeConvertUint8 ¶ added in v0.34.0
SafeConvertUint8 takes an int64 and checks if it overflows If there is an overflow it returns an error
func SafeSubInt32 ¶ added in v0.34.0
SafeSubInt32 subtracts two int32 integers If there is an overflow this will panic
Types ¶
type Fraction ¶
type Fraction struct { // The portion of the denominator in the faction, e.g. 2 in 2/3. Numerator int64 `json:"numerator"` // The value by which the numerator is divided, e.g. 3 in 2/3. Must be // positive. Denominator int64 `json:"denominator"` }
Fraction defined in terms of a numerator divided by a denominator in int64 format.
func ParseFraction ¶ added in v0.34.0
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.