Documentation
¶
Index ¶
- Constants
- func DivDown[T constraints.Integer](a, b T) T
- func DivUp[T constraints.Integer](a, b T) T
- func Float32[T constraints.Integer](i T) float32
- func Float64[T constraints.Integer](i T) float64
- func GCD[T constraints.Integer](a, b T) T
- func GCDX[T constraints.Integer](a, b T) (gcd, x, y T)
- func Idx(idx, ln int) (int, bool)
- func Int[T constraints.Integer](i T) int
- func Int16[T constraints.Integer](i T) int16
- func Int32[T constraints.Integer](i T) int32
- func Int64[T constraints.Integer](i T) int64
- func Int8[T constraints.Integer](i T) int8
- func LCM[T constraints.Integer](a, b T) T
- func LCMN[T constraints.Integer](ns ...T) T
- func Mod[T constraints.Integer](a, b T) T
- func Prod[T Number](ns ...T) T
- func ProdFn[T Number](a, b T) T
- func Range[T Number](start, x, end T) T
- func Reduce[T Number](fn Reducer[T], ts []T) (t T)
- func SumFn[T Number](a, b T) T
- func Uint[T constraints.Integer](i T) uint
- func Uint16[T constraints.Integer](i T) uint16
- func Uint32[T constraints.Integer](i T) uint32
- func Uint64[T constraints.Integer](i T) uint64
- func Uint8[T constraints.Integer](i T) uint8
- type Combinator
- type CombinatorFactory
- type Number
- type Reducer
Constants ¶
const ( MaxU uint = ^uint(0) MaxU8 uint8 = ^uint8(0) MaxU16 uint16 = ^uint16(0) MaxU32 uint32 = ^uint32(0) MaxU64 uint64 = ^uint64(0) MaxI int = int(MaxU >> 1) MaxI8 int8 = int8(MaxU8 >> 1) MaxI16 int16 = int16(MaxU16 >> 1) MaxI32 int32 = int32(MaxU32 >> 1) MaxI64 int64 = int64(MaxU64 >> 1) MinI int = ^MaxI MinI8 int8 = ^MaxI8 MinI16 int16 = ^MaxI16 MinI32 int32 = ^MaxI32 MinI64 int64 = ^MaxI64 )
Provide Max value for all integer types and min value for all signed integers.
Variables ¶
This section is empty.
Functions ¶
func DivDown ¶
func DivDown[T constraints.Integer](a, b T) T
DivDown returns a/b rounding down. This is the Go default, but defining the desired behavior can be more explicit.
func Float32 ¶
func Float32[T constraints.Integer](i T) float32
Float32 converts any integer type to an float32
func Float64 ¶
func Float64[T constraints.Integer](i T) float64
Float64 converts any integer type to an float64
func GCD ¶
func GCD[T constraints.Integer](a, b T) T
GCD finds the greatest common denominator of a and b.
func GCDX ¶
func GCDX[T constraints.Integer](a, b T) (gcd, x, y T)
GCDX implements the extended GCD algorithm. I do not understand what x and y represent.
func Idx ¶
Idx provides a relative index to the given length. So a value of -1 will return the ln-1. The bool indicates if the index is in range.
func Int16 ¶
func Int16[T constraints.Integer](i T) int16
Int16 converts any integer type to an int16
func Int32 ¶
func Int32[T constraints.Integer](i T) int32
Int32 converts any integer type to an int32
func Int64 ¶
func Int64[T constraints.Integer](i T) int64
Int64 converts any integer type to an int64
func LCM ¶
func LCM[T constraints.Integer](a, b T) T
LCM finds the least common multiple of a and b.
func LCMN ¶
func LCMN[T constraints.Integer](ns ...T) T
LCMN finds the least common multiple of all integers in ns
func Mod ¶
func Mod[T constraints.Integer](a, b T) T
Mod provides a version of modulus consistent with most other languages and calculators.
In Go, mod (%) will return a negative if either a or b is negative. In most other languages and calculators the sign will always match b.
func Range ¶
func Range[T Number](start, x, end T) T
Range checks that x is within the defined range. If it is less than start, start is returned. If it is greater than end, end is returned.
func Reduce ¶
Reduce calls fn on the first two elements of the slice, then for every element after that calls the function with the previous result as the first argument and the element as the second.
func Uint16 ¶
func Uint16[T constraints.Integer](i T) uint16
Uint16 converts any integer type to an uint16
func Uint32 ¶
func Uint32[T constraints.Integer](i T) uint32
Uint32 converts any integer type to an uint32
func Uint64 ¶
func Uint64[T constraints.Integer](i T) uint64
Uint64 converts any integer type to an uint64
func Uint8 ¶
func Uint8[T constraints.Integer](i T) uint8
Uint8 converts any integer type to an uint8
Types ¶
type Combinator ¶
type Combinator[I constraints.Integer] func(idx I) []I
Combinator represents a list of combinations that can be returned by index.
func Cross ¶
func Cross[I constraints.Integer](lns ...I) (Combinator[I], I)
Cross produces every combination lengths.
func Pair ¶
func Pair[I constraints.Integer](lns ...I) (Combinator[I], I)
Pair loops through the provided indexes until they all end simultaneously. If the lengths are all the same, this will be a single cycle.
type CombinatorFactory ¶
type CombinatorFactory[I constraints.Integer] func(lns ...I) (c Combinator[I], ln I)
CombinatorFactory takes a slice of integers and produces a combinator for them.
type Number ¶
type Number interface { constraints.Integer | constraints.Float }