Documentation ¶
Index ¶
- func AVG(elems []float64) (float64, bool)
- func Add(n1, n2 []int, base int) []int
- func ApproximateConvergence(values []*big.Float, n int) (*big.Float, error)
- func BaseToDec(n []int, base int) (int, error)
- func BigFloatDivision(numerator, denominator int) (*big.Float, error)
- func CalculateConvergence(series Serieser, upperLimit int, delta int) (values []*big.Float, err error)
- func DecToBase(n, base int) []int
- func GreatestCommonDivisor(a, b int) int
- func IntToBigInt(n int) *big.Int
- func IsValidNumber(n []int, base int) bool
- func PrimeFactorization(inputNumber int) map[int]int
- func SQM(elems []float64) (float64, bool)
- func Subtract(n1, n2 []int, base int) ([]int, error)
- type ErrSubtractionUnderflow
- type LinearRegression
- type Serieser
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.
- bool: False if the slice is empty. True otherwise.
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. Nil if the base is less than or equal to 0.
func ApproximateConvergence ¶ added in v0.3.31
ApproximateConvergence approximates the convergence of a series. It calculates the average of the last n values.
Parameters:
- n: The number of values to calculate the average.
Returns:
- *big.Float: The average of the last n values.
- error: An error if the calculation fails.
Errors:
- *uc.ErrInvalidParameter: If n is less than or equal to 0 or if there are not enough values to calculate the average.
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 conversion failed.
Errors:
- *errors.ErrInvalidParameter: The base is less than or equal to 0.
- *errors.ErrOutOfBounds: A digit in the number is out of bounds for the given base.
func BigFloatDivision ¶ added in v0.3.19
BigFloatDivision is a function that performs division on two integers and returns the result as a big.Float.
Parameters:
- numerator: The numerator of the division.
- denominator: The denominator of the division.
Returns:
- *big.Float: The result of the division as a big.Float.
- error: An error of type *ErrInvalidParameter if the numerator is negative or the denominator is less than or equal to 0.
func CalculateConvergence ¶ added in v0.3.19
func CalculateConvergence(series Serieser, upperLimit int, delta int) (values []*big.Float, err error)
CalculateConvergence calculates the convergence of a series. It calculates the quotient of the ith term and the (i+delta)th term.
Parameters:
- series: The series to calculate the convergence.
- upperLimit: The upper limit of the series to calculate the convergence.
- delta: The difference between the terms to calculate the convergence.
Returns:
- *ConvergenceResult: The convergence result.
- error: An error if the calculation fails.
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. Nil if base is less than or equal to 0.
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 IntToBigInt ¶ added in v0.3.19
IntToBigInt converts an integer to a big.Int.
Parameters:
- n: The integer to convert.
Returns:
- *big.Int: The big.Int representation of the integer.
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. Nil 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.
- bool: False if the slice is empty. True otherwise.
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 subtraction failed.
Errors:
- *ErrSubtractionUnderflow: The subtraction resulted in a negative number.
- *errors.ErrInvalidParameter: The base is less than or equal to 0.
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.
type LinearRegression ¶ added in v0.3.19
type LinearRegression struct { // A is the coefficient of the linear regression. A *big.Float // B is the exponent of the linear regression. B *big.Float }
LinearRegression is a struct that holds the equation of a linear regression.
func NewLinearRegression ¶ added in v0.3.19
func NewLinearRegression() *LinearRegression
NewLinearRegression creates a new LinearRegression.
Returns:
- LinearRegression: The new LinearRegression.
func (*LinearRegression) FindEquation ¶ added in v0.3.19
func (l *LinearRegression) FindEquation(values []*big.Float) bool
FindEquation is a method of ConvergenceResult that finds the equation of the series that best fits the convergence values.
The equation is of the form y = a * x^b.
Returns:
- bool: False if there are less than 2 values to calculate the equation. True otherwise.
func (*LinearRegression) String ¶ added in v0.3.19
func (lr *LinearRegression) String() string
String implements the fmt.Stringer interface.
Format: y = a * x^b
type Serieser ¶ added in v0.3.19
type Serieser interface { // Term returns the nth term of the series. // // Parameters: // - n: The term number. // // Returns: // - *big.Int: The nth term of the series. // - error: An error if the term cannot be calculated. Term(n int) (*big.Int, error) }
Serieser is an interface for series.