UNPKG

sussy-util

Version:
158 lines (157 loc) 6.66 kB
import { Point } from '.'; declare class BetterMath { private static readonly instance; private constructor(); /** * Round a number to a specified number of decimal places. * @param {number} value - The number to round. * @param {number} digit - The number of digits to round to. * @returns The rounded value. */ round(value: number, digit: number): number; /** * Calculate the square of a number. * @param {number} num - The number to calculate the square of. * @returns {number} The square of the number. */ square(num: number): number; /** * Calculate the cube of a number. * @param {number} num - The number to calculate the cube of. * @returns {number} The cube of the number. */ cube(num: number): number; /** * Calculates the total distance between points along a given path. * * @param {Point[]} path - An array of Point objects representing the path. * @returns {number} The total distance along the path. */ distance(path: Point[]): number; /** * Calculates the greatest common divisor (GCD) of two numbers using the Euclidean algorithm. * * @param {number} a - The first number. * @param {number} b - The second number. * @returns {number} The greatest common divisor of the two input numbers. */ greatestCommonDivisor(a: number, b: number): number; /** * Calculates the greatest common divisor (GCD) of two numbers using the Euclidean algorithm. * * @param {number} a - The first number. * @param {number} b - The second number. * @returns {number} The greatest common divisor of the two input numbers. */ gcd(a: number, b: number): number; /** * It returns the lowest common denominator of two numbers. * @param {number} a - number, b: number * @param {number} b - number - The second number to find the lowest common denominator of. * @returns The lowest common denominator of two numbers. */ lowestCommonDenominator(a: number, b: number): number; /** * It returns the lowest common denominator of two numbers. * @param {number} a - number, b: number * @param {number} b - number - The second number to find the lowest common denominator of. * @returns The lowest common denominator of two numbers. */ lcd(a: number, b: number): number; /** * It takes an array of numbers, adds them together, divides the sum by the number of elements in * the array, and returns the result * @param {number[]} numbers - number[] - An array of numbers to average. * @returns The average of the numbers in the array. */ calculateAverage(numbers: number[]): number; /** * It takes an array of numbers, adds them together, divides the sum by the number of elements in * the array, and returns the result * @param {number[]} numbers - number[] - An array of numbers to average. * @returns The average of the numbers in the array. */ avg(numbers: number[]): number; /** * If the number is less than or equal to 1, return 1, otherwise return the number multiplied by * the factorial of the number minus 1 * @param {number} num - number - The number to calculate the factorial of. * @returns The factorial of the number passed in. */ factorial(num: number): number; /** * Calculate the factorial of a number using an iterative approach. * @param {number} num - The number to calculate the factorial of. * @returns {number} The factorial of the number. */ factorialIterative(num: number): number; /** * @param {number[]} values - number[] - The array of numbers to get the median of. * @returns The median of the array. */ median(values: number[]): number; /** * Calculate the nth root of a number. * @param {number} number - The number. * @param {number} n - The root to calculate. * @returns {number} The nth root of the number. * @throws {Error} Cannot calculate even root of a negative number. */ nthRoot(number: number, n: number): number; /** * Calculate the logarithm of a number with a specified base. * @param {number} number - The number. * @param {number} base - The base of the logarithm. * @returns {number} The logarithm of the number with the specified base. */ logarithm(number: number, base: number): number; /** * Calculate the number of permutations of r elements from a set of n elements. * @param {number} n - The total number of elements. * @param {number} r - The number of elements to select. * @returns {number} The number of permutations. * @throws {Error} n must be greater than or equal to r in permutations. */ permutations(n: number, r: number): number; /** * Calculate the number of combinations of r elements from a set of n elements. * @param {number} n - The total number of elements. * @param {number} r - The number of elements to select. * @returns {number} The number of combinations. * @throws {Error} n must be greater than or equal to r in combinations. */ combinations(n: number, r: number): number; /** * Convert degrees to radians. * @param {number} degrees - The value in degrees. * @returns {number} The value in radians. */ degreesToRadians(degrees: number): number; /** * Convert radians to degrees. * @param {number} radians - The value in radians. * @returns {number} The value in degrees. */ radiansToDegrees(radians: number): number; /** * Calculate the factorial of a number using memoization. * @param {number} num - The number to calculate the factorial of. * @param {Map<number, number>} memo - A memoization map to store computed results (optional). * @returns {number} The factorial of the number. */ factorialWithMemoization(num: number, memo?: Map<number, number>): number; /** * Counts the number of decimal digits in the fractional part of a number. * * @param {number} number - The input number to count decimal digits for. * @returns {number} The count of decimal digits in the fractional part of the input number. */ countDecimalDigits(number: number): number; /** * Get the instance of the BetterMath class (Singleton pattern). * @returns {BetterMath} The instance of the BetterMath class. */ static getInstance(): BetterMath; } declare const _default: BetterMath; export default _default;