MathExt

package
v0.2.23 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add added in v0.2.18

func Add(n1, n2 []int, base int) ([]int, error)

Both n1 and n2 must be LSD first and of the same base.

func BaseToDec added in v0.2.18

func BaseToDec(n []int, base int) (int, error)

LSD n[0]

func DecToBase added in v0.2.18

func DecToBase(n, base int) ([]int, error)

LSD result[0]

func GreatestCommonDivisor

func GreatestCommonDivisor(a, b int) int

GreatestCommonDivisor is a function that calculates the greatest common divisor (GCD) of two integers using the Euclidean algorithm.

Parameters:

  • a, b: The two integers to find the GCD of.

Returns:

  • int: The GCD of the two input numbers.

func IsValidNumber added in v0.2.18

func IsValidNumber(n []int, base int) bool

func NewErrInvalidBase added in v0.2.18

func NewErrInvalidBase() error

func PrimeFactorization

func PrimeFactorization(inputNumber int) (map[int]int, error)

PrimeFactorization is a function that performs prime factorization on an input number.

Panics with an error of type *ErrInvalidParameter if the input number is 0.

In the resulting map, no prime factor will have a value of 1, except for 1 and -1, which is represented as [1: 1]. Finally, negative numbers are converted to positive numbers.

Parameters:

  • inputNumber: The number to factorize.

Returns:

  • map[int]int: A map where the keys are the prime factors and the values are their respective powers.

func Subtract added in v0.2.18

func Subtract(n1, n2 []int, base int) ([]int, error)

LSD n[0]

Types

type ErrInvalidBase added in v0.2.18

type ErrInvalidBase struct{}

func (*ErrInvalidBase) Error added in v0.2.18

func (e *ErrInvalidBase) Error() string

Jump to

Keyboard shortcuts

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