math

package
v0.0.0-...-68053d7 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const MaxInt = int(MaxUint >> 1)

MaxInt is the max int value.

View Source
const MaxUint = ^uint(0)

MaxUint is the largest uint value.

View Source
const MinInt = -MaxInt - 1

MinInt is the smallest (negative) int value.

Variables

This section is empty.

Functions

func ChooseNUint32

func ChooseNUint32(ints []uint32, n int) [][]uint32

ChooseNUint32 returns distinct groups of n uint32s from the inputs. It assumes the inputs are distinct too.

func ExtendedGCD

func ExtendedGCD(a, b int) (gcd, quotientA, quotientB, bézoutCoefficientA, bézoutCoefficientB int)

func GCD

func GCD(a, b int) int

GCD uses the Euclidean algorithm to calculate the GCD of a and b.

func LCM

func LCM(a, b int) int

LCM computes the least common multiple of a and b. It doesn't handle negative numbers. If either a or b is zero, it returns zero.

func ModExp

func ModExp(base, exponent, m int) int

ModExp returns base ** exponent, mod m.

func ModGeometricSum

func ModGeometricSum(r, n, m int) (int, error)

ModGeometricSum returns the sum of the first n terms of the sequence rⁿ, starting with r⁰, modulo m. eg: ModGeometricSum(37, 5, 10000001) = (1 + 37 + 37² + 37³ + 37⁴) mod 10000001 = 1926221 eg: ModGeometricSum(37, 5, 101) = (1 + 37 + 37² + 37³ + 37⁴) mod 101 = 50

func ModInv

func ModInv(x, m int) (int, error)

ModInv calculates the modular multiplicative inverse of x, modulo m. If gcd(x,m) != 1, it returns an error.

func ModMul

func ModMul(a, b, m int) int

ModMul return a * b, mod m.

func MultiGCD

func MultiGCD(nums ...int) int

MultiGCD computes the GCD of multiple numbers.

func MultiLCM

func MultiLCM(nums ...int) int

MultiLCM computes the LCM of multiple numbers.

func Sieve

func Sieve(n int)

func SlowPrimesLessThanOrEqualTo

func SlowPrimesLessThanOrEqualTo(target int) []int

func Sort3

func Sort3(a, b, c int) (int, int, int)

Sort3 sorts three ints in ascending order.

Types

type Factor

type Factor struct {
	Prime int
	Count int
}

func PrimeFactors

func PrimeFactors(n int) []Factor

Jump to

Keyboard shortcuts

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