Documentation ¶
Index ¶
- func AVG(elems []float64) (float64, error)
- func Add(n1, n2 []int, base int) ([]int, error)
- func BaseToDec(n []int, base int) (int, error)
- func DecToBase(n, base int) ([]int, error)
- func GreatestCommonDivisor(a, b int) int
- func IsValidNumber(n []int, base int) bool
- func PrimeFactorization(inputNumber int) (map[int]int, error)
- func SQM(elems []float64) (float64, error)
- func Subtract(n1, n2 []int, base int) ([]int, error)
- type ErrSubtractionUnderflow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AVG ¶ added in v0.2.32
AVG calculates the average of a slice of float64 elements.
Parameters:
- elems: The elements to calculate the average of.
Returns:
- float64: The average of the elements.
- error: An error of type *ErrInvalidParameter if the slice is empty.
func Add ¶ added in v0.2.18
Add adds two numbers of the same base. Both numbers are Least Significant Digit (LSD) first.
Parameters:
- n1: The first number to add.
- n2: The second number to add.
- base: The base of the numbers.
Returns:
- []int: The sum of the two numbers.
- error: An error if the base is invalid.
func BaseToDec ¶ added in v0.2.18
BaseToDec converts a number of the given base to a decimal number. The number's Least Significant Digit (LSD) is at index 0.
Parameters:
- n: The number to convert.
- base: The base of the number.
Returns:
- int: The decimal number.
- error: An error if the base is invalid or the number is invalid for the given base.
func DecToBase ¶ added in v0.2.18
DecToBase converts a decimal number to a number of the given base. The number's Least Significant Digit (LSD) is at index 0.
Parameters:
- n: The decimal number to convert.
- base: The base of the result number.
Returns:
- []int: The number in the given base.
- error: An error if the base is invalid.
func GreatestCommonDivisor ¶
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
IsValidNumber checks if the given number is valid for the given base.
Parameters:
- n: The number to check.
- base: The base of the number.
Returns:
- bool: True if the number is valid for the given base, false otherwise.
func PrimeFactorization ¶
PrimeFactorization is a function that performs prime factorization on an input number.
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.
- error: An error of type *ErrInvalidParameter if the input number is 0.
Behaviors:
- The input number is converted to a positive number.
- The prime factors are sorted in ascending order.
- -1 and 1 are represented as [1: 1].
- The resulting map does not contain any prime factor with a value of 1.
func SQM ¶ added in v0.2.32
SQM calculates the Standard Quadratic Mean of a slice of float64 elements.
Parameters:
- elems: The elements to calculate the SQM of.
Returns:
- float64: The SQM of the elements.
- error: An error of type *ErrInvalidParameter if the slice is empty.
func Subtract ¶ added in v0.2.18
Subtract subtracts two numbers of the same base. Both numbers are Least Significant Digit (LSD) first.
Parameters:
- n1: The number to subtract from.
- n2: The number to subtract.
- base: The base of the numbers.
Returns:
- []int: The result of the subtraction.
- error: An error if the base is invalid or the subtraction resulted in a negative number.
Types ¶
type ErrSubtractionUnderflow ¶ added in v0.2.37
type ErrSubtractionUnderflow struct{}
ErrSubtractionUnderflow is an error that is returned when a subtraction operation results in a negative number.
func NewErrSubtractionUnderflow ¶ added in v0.2.37
func NewErrSubtractionUnderflow() *ErrSubtractionUnderflow
NewErrSubtractionUnderflow creates a new ErrSubtractionUnderflow error.
Returns:
- *ErrSubtractionUnderflow: The new ErrSubtractionUnderflow error.
func (*ErrSubtractionUnderflow) Error ¶ added in v0.2.37
func (e *ErrSubtractionUnderflow) Error() string
Error is a method of ErrSubtractionUnderflow that returns the message: "subtraction underflow".
Returns:
- string: The error message.