extra-math 1.3.30
Install from the command line:
Learn more about npm packages
$ npm install @nodef/extra-math@1.3.30
Install via package.json:
"@nodef/extra-math": "1.3.30"
About this version
A collection of common mathematical functions.
π¦ Node.js,
π Web,
π Files,
π° JSDoc,
π Wiki.
Mathematics is the classification and study of all possible patterns (1). This package includes common mathematical functions related to natural numbers, real numbers, geometry, and statistics.
Natural numbers: There are 3 different ways of performing the modulo
operation: rem, mod, and modp. gcd/HCF
and lcm of a list of numbers
can be obtained. To calculate the number of ways of ordering items, use
factorial/P(n, k)
, binomial/C(n, k)
, or multinomial/n!/kβ!kβ!...
.
Real numbers: Range of a number can be controlled with constrain, normalize, or remap. Use lerp for linear interpolation (or extrapolation); root for calculating the n-th root of a number; and log to find the logarithm of a number with a given base. Results of special mathematical functions (approximations) for a given number can be obtained with erf and erfc.
Geometry: Perform conversion from degrees to radians and vice versa. Find the magnitude of a vector or distance between two points.
Statistics: For a list of numbers, we can calculate the sum, product, mean. median gives the value lying in the middle when the numbers are sorted, and modes gives the values which are repeated most often. The difference between the largest and the smallest values is the range. variance is a measure of variability of numbers.
This package is available in both Node.js and Web formats. The web format is
exposed as extra_math
standalone variable and can be loaded from jsDelivr CDN.
Stability: Experimental.
const math = require('extra-math');
// import * as math from "extra-math";
// import * as math from "https://unpkg.com/extra-math/index.mjs"; (deno)
math.sum(1, 2, 3, 4);
// β 10
math.median(1, 7, 8);
// β 7
math.variance(1, 2, 3, 4);
// β 1.25
math.lcm(2, 3, 4);
// β 12
Property | Description |
---|---|
rem | Find the remainder of x/y with sign of x (truncated division). |
mod | Find the remainder of x/y with sign of y (floored division). |
modp | Find the remainder of x/y with +ve sign (euclidean division). |
gcd | Find the greatest common divisor of numbers. |
lcm | Find the least common multiple of numbers. |
factorial | Find the factorial of a number. |
binomial | Find the number of ways to choose k elements from a set of n elements. |
multinomial | Find the number of ways to put n objects in m bins (n=sum(kα΅’)). |
constrain | Constrain a number within a minimum and a maximum value. |
normalize | Normalize a number from its current range into a value between 0 and 1. |
remap | Re-map a number from one range to another. |
lerp | Linearly interpolate a number between two numbers. |
root | Find the nth root of a number (βΏβ). |
log | Find the logarithm of a number with a given base. |
erf | Find error function value of number (approximation). |
erfc | Find the complementary error function value of number (approximation). |
degrees | Convert radians to degrees. |
radians | Convert degrees to radians. |
magnitude | Calculate the magnitude (length) of a vector. |
distance | Calculate the distance between two points. |
sum | Find the sum of numbers (Ξ£). |
product | Find the product of numbers (β). |
mean | Find the average of numbers. |
median | Find the value separating the higher and lower halves of numbers. |
modes | Find the values that appear most often. |
range | Find the difference between the largest and smallest values. |
variance | Find the mean of squared deviation of numbers from its mean. |
- Yang, Z. H., & Tian, J. F. (2018). An accurate approximation formula for gamma function. Journal of inequalities and applications, 2018(1), 56.
- MathLib by @alawatthe
- Processing Reference
- Common mathematical functions by cppreference
- Modulo operation
- Euclidean algorithm
- Least common multiple
- Permutation
- Binomial coefficient
- Multinomial distribution
- Conventional commits