Skip to content

Repository files navigation

A collection for common number functions (queries, comparisons, rounding, divisors, etc).

A number is a mathematical object used to count, measure, and label. In JavaScript, Number type is double-precision 64-bit binary format IEEE 754 value. This package includes common number functions related to querying about numbers, comparing numbers, rounding numbers, performing rounded division, performing modulo operations, controlling range of numbers, performing arithmetic operations, obtaining divisors of a number (and related operations), getting the number of possible arrangements of a set of objects, performing geometry-related calculations, performing basic statistical analysis, and finding various statistical means.

▌ 📦 JSR, 📦 NPM, 📰 Docs.


import*asxnumberfrom"jsr:@nodef/extra-number";xnumber.isPrime(53);// → truexnumber.properDivisors(6);// → [1, 2, 3]xnumber.round(9.1357,0.05);// → 9.15xnumber.significantDigits(0.0034);// → 2// TOFIX:// xnumber.fromRoman('DCXLIX');// → 649// xnumber.toScientific(695700000);// → '6.957×10⁸' (radius of Sun in m)


Index

NameDescription
isCheck if value is a number.
isNormalCheck if number is normal (not zero, subnormal, infinite, or NaN).
classifyClassify a number into its floating point category.
isPerfectExamine if sum of divisors equals the number itself.
isAbundantExamine if sum of divisors exceeds the number itself.
abundanceObtain the sum of divisors exceeding the number itself.
abundancyIndexObtain the ratio of sum of divisors to the number itself.
significantDigitsCount the number of significant digits in a number.
compareCompare two numbers.
floorRound down a number to specific precision.
ceilRound up a number to specific precision.
roundRound a number to specific precision.
floorDivPerform floor-divison of two numbers.
ceilDivPerform ceiling-divison of two numbers.
roundDivPerform rounded-divison of two numbers.
remFind the remainder of x/y with sign of x (truncated division).
modFind the remainder of x/y with sign of y (floored division).
modpFind the remainder of x/y with +ve sign (euclidean division).
constrainConstrain a number within a minimum and a maximum value.
normalizeNormalize a number from its current range into a value between 0 and 1.
remapRe-map a number from one range to another.
lerpLinearly interpolate a number between two numbers.
isPowCheck if a number is a power-of-n.
prevPowFind largest power-of-n less than or equal to given number.
nextPowFind smallest power-of-n greater than or equal to given number.
rootFind the nth root of a number (ⁿ√).
logFind the logarithm of a number with a given base.
properDivisorsList all divisors of a number, except itself.
aliquotSumSum all proper divisors of a number.
minPrimeFactorFind the least prime number which divides a number.
maxPrimeFactorFind the greatest prime number which divides a number.
primeFactorsFind the prime factors of a number.
primeExponentialsFind the prime factors and respective exponents of a number.
isPrimeCheck if number is prime.
gcdFind the greatest common divisor of numbers.
lcmFind the least common multiple of numbers.
factorialFind the factorial of a number.
binomialFind the number of ways to choose k elements from a set of n elements.
multinomialFind the number of ways to put n objects in m bins (n=sum(kᵢ)).
degreesConvert radians to degrees.
radiansConvert degrees to radians.
sumFind the sum of numbers (Σ).
productFind the product of numbers (∏).
medianFind the value separating the higher and lower halves of numbers.
modesFind the values that appear most often.
rangeFind the smallest and largest values.
varianceFind the mean of squared deviation of numbers from its mean.
arithmeticMeanFind the average of numbers.
geometricMeanFind the geometric mean of numbers.
harmonicMeanFind the harmonic mean of numbers.
quadriaticMeanFind the quadriatic mean of numbers.
cubicMeanFind the cubic mean of numbers.


References




ORG