UNPKG

extra-bigint

Version:

A [BigInt] can represent whole numbers larger than 2⁵³ - 1 [(1)].<br>

277 lines (276 loc) • 9.51 kB
/** * Check if value is a bigint. * @param x a value * @returns is bigint? */ export declare function is(x: unknown): x is bigint; /** * Compare two bigints. * @param x a bigint * @param y another bigint * @returns x<y: -ve, x=y: 0, x>y: +ve */ export declare function compare(x: bigint, y: bigint): number; /** * Get the absolute of a bigint. * @param x a bigint * @returns |x| */ export declare function abs(x: bigint): bigint; /** * Get the sign of a bigint. * @param x a bigint * @returns x>0: 1n, x<0: -1n, x=0: 0n */ export declare function sign(x: bigint): bigint; /** * Perform floor-divison of two bigints (\\). * @param x dividend * @param y divisor * @returns ⌊x/y⌋ */ export declare function floorDiv(x: bigint, y: bigint): bigint; /** * Perform ceiling-divison of two bigints. * @param x dividend * @param y divisor * @returns ⌈x/y⌉ */ export declare function ceilDiv(x: bigint, y: bigint): bigint; /** * Perform rounded-divison of two bigints. * @param x divisor * @param y dividend * @returns [x/y] */ export declare function roundDiv(x: bigint, y: bigint): bigint; /** * Find the remainder of x/y with sign of x (truncated division). * @param x dividend * @param y divisor * @returns trunc(x % y) */ export declare function rem(x: bigint, y: bigint): bigint; /** * Find the remainder of x/y with sign of y (floored division). * @param x dividend * @param y divisor * @returns floor(x % y) */ export declare function mod(x: bigint, y: bigint): bigint; /** * Find the remainder of x/y with +ve sign (euclidean division). * @param x dividend * @param y divisor * @returns x/y>0: floor(x % y), x/y<0: ceil(x % y) */ export declare function modp(x: bigint, y: bigint): bigint; /** * Constrain a bigint within a minimum and a maximum value. * @param x a bigint * @param minv minimum value * @param maxv maximum value * @returns x<min: min, x>max: max, x */ export declare function constrain(x: bigint, minv: bigint, maxv: bigint): bigint; export { constrain as clamp }; /** * Re-map a bigint from one range to another. * @param x a bigint * @param r lower bound of current range * @param R upper bound of current range * @param t lower bound of target range * @param T upper bound of target range * @returns ∈ [ymin, ymax] */ export declare function remap(x: bigint, r: bigint, R: bigint, t: bigint, T: bigint): bigint; export { remap as map }; /** * Linearly interpolate a bigint between two bigints. * @param x start bigint * @param y stop bigint * @param t interpolant ∈ [0, 1] * @returns ∈ [x, y] */ export declare function lerp(x: bigint, y: bigint, t: number): bigint; /** * Check if bigint is a power-of-2. * @param x a bigint * @returns 2ⁱ = x? | i = +ve integer */ export declare function isPow2(x: bigint): boolean; /** * Check if bigint is a power-of-10. * @param x a bigint * @returns 10ⁱ = x? | i = +ve integer */ export declare function isPow10(x: bigint): boolean; /** * Find largest power-of-2 less than or equal to given bigint. * @param x a bigint * @returns 2ⁱ | 2ⁱ ≤ x and 2ⁱ > x/2 */ export declare function prevPow2(x: bigint): bigint; /** * Find largest power-of-10 less than or equal to given bigint. * @param x a bigint * @returns 10ⁱ | 10ⁱ ≤ x and 10ⁱ > x/10 */ export declare function prevPow10(x: bigint): bigint; /** * Find smallest power-of-2 greater than or equal to given bigint. * @param x a bigint * @returns 2ⁱ | 2ⁱ ≥ x and 2ⁱ < 2x */ export declare function nextPow2(x: bigint): bigint; /** * Find smallest power-of-10 greater than or equal to given bigint. * @param x a bigint * @returns 10ⁱ | 10ⁱ ≥ x and 10ⁱ < 10x */ export declare function nextPow10(x: bigint): bigint; /** * Find the base-2 logarithm of a bigint. * @param x a bigint * @returns log₂(x) */ export declare function log2(x: bigint): bigint; /** * Find the base-10 logarithm of a bigint. * @param x a bigint * @returns log₁₀(x) */ export declare function log10(x: bigint): bigint; /** * Find the square root of a bigint. * @param x a bigint * @returns √x */ export declare function sqrt(x: bigint): bigint | null; /** * Find the cube root of a bigint. * @param x a bigint * @returns ³√x */ export declare function cbrt(x: bigint): bigint | null; /** * Find the nth root of a bigint. * @param x a bigint * @param n nth root (1n) * @returns ⁿ√x */ export declare function root(x: bigint, n?: bigint): bigint | null; /** * List all divisors of a bigint, except itself. * @param x a bigint * @returns proper divisors (factors) */ export declare function properDivisors(x: bigint): bigint[]; export { properDivisors as aliquotParts }; /** * Sum all proper divisors of a bigint. * @param x a bigint * @returns Σdᵢ | dᵢ is a divisor of x and ≠x */ export declare function aliquotSum(x: bigint): bigint; /** * Find the least prime number which divides a bigint. * @param x a bigint * @returns least prime factor */ export declare function minPrimeFactor(x: bigint): bigint; export { minPrimeFactor as leastPrimeFactor }; /** * Find the greatest prime number which divides a bigint. * @param x a bigint * @returns greatest prime factor */ export declare function maxPrimeFactor(x: bigint): bigint; export { maxPrimeFactor as greatestPrimeFactor }; /** * Find the prime factors of a bigint. * @param x a bigint * @returns [f₀, f₁, ...] | fᵢ divides x and is prime */ export declare function primeFactors(x: bigint): bigint[]; /** * Find the prime factors and respective exponents of a bigint. * @param x a bigint * @returns [[f₀, e₀], [f₁, e₁], ...] | fᵢ is a prime factor of x and eᵢ is its exponent */ export declare function primeExponentials(x: bigint): [bigint, bigint][]; /** * Check if bigint is prime. * @param x a bigint * @returns is divisible by 1n and itself only? */ export declare function isPrime(x: bigint): boolean; /** * Find the greatest common divisor of bigints. * @param xs a list of bigints * @returns gcd(x₁, x₂, ...) */ export declare function gcd(...xs: bigint[]): bigint; export { gcd as hcf }; /** * Find the least common multiple of bigints. * @param xs a list of bigints * @returns lcm(x₁, x₂, ...) */ export declare function lcm(...xs: bigint[]): bigint; /** * Find the factorial of a bigint. * @param n a bigint * @param k denominator factorial [0] * @returns P(n, k); k=0: n!, k>0: n!/k! */ export declare function factorial(n: bigint, k?: bigint): bigint; /** * Find the number of ways to choose k elements from a set of n elements. * @param n elements in source set * @param k elements in choose set * @returns C(n, k) */ export declare function binomial(n: bigint, k: bigint): bigint; /** * Find the number of ways to put n objects in m bins (n=sum(kᵢ)). * @param ks objects per bin (kᵢ) * @returns n!/(k₁!k₂!...) | n=sum(kᵢ) */ export declare function multinomial(...ks: bigint[]): bigint; /** * Find the length of hypotenuse. * @param xs lengths of perpendicular sides (x, y, z, ...) * @returns √(x² + y² + z²) */ export declare function hypot(...xs: bigint[]): bigint; /** * Find the sum of bigints (Σ). * @param xs bigints * @returns Σxᵢ */ export declare function sum(...xs: bigint[]): bigint; /** * Find the product of bigints (∏). * @param xs bigints * @returns ∏xᵢ */ export declare function product(...xs: bigint[]): bigint; /** * Find the value separating the higher and lower halves of bigints. * @param xs a list of bigints * @returns xₘ | sort(xs) = [..., xₘ, ...] */ export declare function median(...xs: bigint[]): bigint; /** * Find the values that appear most often. * @param xs a list of bigints * @returns [xₘ₁, xₘ₂, ...] | count(xₘᵢ) ≥ count(xᵢ) ∀ xᵢ ∈ xs */ export declare function modes(...xs: bigint[]): bigint[]; /** * Find the smallest bigint. * @param xs bigints * @returns min(xs) */ export declare function min(...xs: bigint[]): bigint; /** * Find the largest bigint. * @param xs bigints * @returns max(xs) */ export declare function max(...xs: bigint[]): bigint; /** * Find the minimum and maximum bigint. * @param xs bigints * @returns [min, max] */ export declare function range(...xs: bigint[]): [bigint, bigint]; /** * Find the mean of squared deviation of bigints from its mean. * @param xs a list of bigints * @returns σ² = E[(xs - µ)²] | µ = mean(xs) */ export declare function variance(...xs: bigint[]): bigint; /** * Find the arithmetic mean of bigints (µ). * @param xs bigints * @returns µ = (Σxᵢ)/n | n = size(xs) */ export declare function arithmeticMean(...xs: bigint[]): bigint; export { arithmeticMean as mean }; /** * Find the geometric mean of bigints. * @param xs bigints * @returns ⁿ√(∏xᵢ) | n = size(xs) */ export declare function geometricMean(...xs: bigint[]): bigint | null; /** * Find the harmonic mean of bigints. * @param xs bigints * @returns n/Σ(1/xᵢ) | n = size(xs) */ export declare function harmonicMean(...xs: bigint[]): bigint; /** * Find the quadriatic mean of bigints. * @param xs bigints * @returns √(Σxᵢ²)/n | n = size(xs) */ export declare function quadriaticMean(...xs: bigint[]): bigint; export { quadriaticMean as rootMeanSquare }; /** * Find the cubic mean of bigints. * @param xs bigints * @returns ³√(Σxᵢ³)/n | n = size(xs) */ export declare function cubicMean(...xs: bigint[]): bigint | null;