ints

package
v0.0.0-...-ef20d55 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
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 DivUp

func DivUp[T constraints.Integer](a, b T) T

DivUp returns a/b rounding up.

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

func Idx(idx, ln int) (int, bool)

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 Int

func Int[T constraints.Integer](i T) int

Int converts any integer type to an int

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 Int8

func Int8[T constraints.Integer](i T) int8

Int8 converts any integer type to an int8

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 Prod

func Prod[T Number](ns ...T) T

Prod returns the product of all integers in ns

func ProdFn

func ProdFn[T Number](a, b T) T

ProdFn wraps a*b as a function

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

func Reduce[T Number](fn Reducer[T], ts []T) (t T)

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 SumFn

func SumFn[T Number](a, b T) T

SumFn wraps a+b as a function.

func Uint

func Uint[T constraints.Integer](i T) uint

Uint converts any integer type to an uint

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
}

type Reducer

type Reducer[T Number] func(T, T) T

func (Reducer[T]) Reduce

func (fn Reducer[T]) Reduce(ts []T) (t T)

Jump to

Keyboard shortcuts

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