1 | A collection of common mathematical functions.<br>
|
2 | ๐ฆ [Node.js](https://www.npmjs.com/package/extra-math),
|
3 | ๐ [Web](https://www.npmjs.com/package/extra-math.web),
|
4 | ๐ [Files](https://unpkg.com/extra-math/),
|
5 | ๐ฐ [JSDoc](https://nodef.github.io/extra-math/),
|
6 | ๐ [Wiki](https://github.com/nodef/extra-math/wiki/).
|
7 |
|
8 | Mathematics is the classification and study of all possible patterns [(1)]. This
|
9 | package includes common number functions related to querying *about* numbers,
|
10 | *comparing* numbers, *rounding* numbers, performing *rounded division*,
|
11 | performing *modulo* operations, *controlling range* of numbers, performing
|
12 | *arithmetic* operations, obtaining *divisors* of a number (and related
|
13 | operations), getting the number of possible *arrangements* of a set of objects,
|
14 | performing *geometry*-related calculations, performing basic *statistical*
|
15 | analysis, and finding various *statistical means*.
|
16 |
|
17 | **Natural numbers**: There are 3 different ways of performing the *modulo*
|
18 | operation: [rem], [mod], and [modp]. [gcd]/`HCF` and [lcm] of a list of numbers
|
19 | can be obtained. To calculate the number of ways of *ordering items*, use
|
20 | [factorial]/`P(n, k)`, [binomial]/`C(n, k)`, or [multinomial]/`n!/kโ!kโ!...`.
|
21 |
|
22 | **Real numbers**: *Range* of a number can be controlled with [constrain],
|
23 | [normalize], or [remap]. Use [lerp] for *linear interpolation* (or extrapolation);
|
24 | [root] for calculating the *n-th root* of a number; and [log] to find the
|
25 | *logarithm* of a number with a given base.
|
26 |
|
27 | **Geometry**: Perform conversion from [degrees] to [radians] and vice versa.
|
28 | Find the [magnitude] of a vector or [distance] between two points.
|
29 |
|
30 | **Statistics**: For a list of numbers, we can calculate the [sum], [product],
|
31 | [arithmeticMean]. [median] gives the value lying in the middle when the numbers are
|
32 | sorted, and [modes] gives the values which are repeated most often. The
|
33 | difference between the largest and the smallest values is the [range].
|
34 | [variance] is a measure of variability of numbers.
|
35 |
|
36 | This package is available in both *Node.js* and *Web* formats. The web format is
|
37 | exposed as `extra_math` standalone variable and can be loaded from [jsDelivr CDN].
|
38 |
|
39 | [(1)]: https://en.wikipedia.org/wiki/Walter_Warwick_Sawyer
|
40 | [jsDelivr CDN]: https://cdn.jsdelivr.net/npm/extra-math.web/index.js
|
41 |
|
42 | > Stability: [Experimental](https://www.youtube.com/watch?v=L1j93RnIxEo).
|
43 |
|
44 | <br>
|
45 |
|
46 |
|
47 | ```javascript
|
48 | const math = require('extra-math');
|
49 | // import * as math from "extra-math";
|
50 | // import * as math from "https://unpkg.com/extra-math/index.mjs"; (deno)
|
51 |
|
52 | math.sum(1, 2, 3, 4);
|
53 | // โ 10
|
54 |
|
55 | math.median(1, 7, 8);
|
56 | // โ 7
|
57 |
|
58 | math.variance(1, 2, 3, 4);
|
59 | // โ 1.25
|
60 |
|
61 | math.lcm(2, 3, 4);
|
62 | // โ 12
|
63 | ```
|
64 |
|
65 | <br>
|
66 | <br>
|
67 |
|
68 |
|
69 | ## Index
|
70 |
|
71 | | Property | Description |
|
72 | | ---- | ---- |
|
73 | | [floor] | Round down a number to specific precision. |
|
74 | | [ceil] | Round up a number to specific precision. |
|
75 | | [round] | Round a number to specific precision. |
|
76 | | | |
|
77 | | [floorDiv] | Perform floor-divison of two numbers. |
|
78 | | [ceilDiv] | Perform ceiling-divison of two numbers. |
|
79 | | [roundDiv] | Perform rounded-divison of two numbers. |
|
80 | | | |
|
81 | | [rem] | Find the remainder of x/y with sign of x (truncated division). |
|
82 | | [mod] | Find the remainder of x/y with sign of y (floored division). |
|
83 | | [modp] | Find the remainder of x/y with +ve sign (euclidean division). |
|
84 | | | |
|
85 | | [constrain] | Constrain a number within a minimum and a maximum value. |
|
86 | | [normalize] | Normalize a number from its current range into a value between 0 and 1. |
|
87 | | [remap] | Re-map a number from one range to another. |
|
88 | | [lerp] | Linearly interpolate a number between two numbers. |
|
89 | | | |
|
90 | | [isPow] | Check if a number is a power-of-n. |
|
91 | | [prevPow] | Find largest power-of-n less than or equal to given number. |
|
92 | | [nextPow] | Find smallest power-of-n greater than or equal to given number. |
|
93 | | | |
|
94 | | [root] | Find the nth root of a number (โฟโ). |
|
95 | | [log] | Find the logarithm of a number with a given base. |
|
96 | | | |
|
97 | | [properDivisors] | List all divisors of a number, except itself. |
|
98 | | [aliquotSum] | Sum all proper divisors of a number. |
|
99 | | [minPrimeFactor] | Find the least prime number which divides a number. |
|
100 | | [maxPrimeFactor] | Find the greatest prime number which divides a number. |
|
101 | | [primeFactors] | Find the prime factors of a number. |
|
102 | | [primeExponentials] | Find the prime factors and respective exponents of a number. |
|
103 | | [isPrime] | Check if number is prime. |
|
104 | | [gcd] | Find the greatest common divisor of numbers. |
|
105 | | [lcm] | Find the least common multiple of numbers. |
|
106 | | | |
|
107 | | [factorial] | Find the factorial of a number. |
|
108 | | [binomial] | Find the number of ways to choose k elements from a set of n elements. |
|
109 | | [multinomial] | Find the number of ways to put n objects in m bins (n=sum(kแตข)). |
|
110 | | | |
|
111 | | [degrees] | Convert radians to degrees. |
|
112 | | [radians] | Convert degrees to radians. |
|
113 | | [magnitude] | Calculate the magnitude (length) of a vector. |
|
114 | | [distance] | Calculate the distance between two points. |
|
115 | | | |
|
116 | | [sum] | Find the sum of numbers (ฮฃ). |
|
117 | | [product] | Find the product of numbers (โ). |
|
118 | | [median] | Find the value separating the higher and lower halves of numbers. |
|
119 | | [modes] | Find the values that appear most often. |
|
120 | | [range] | Find the smallest and largest values. |
|
121 | | [variance] | Find the mean of squared deviation of numbers from its mean. |
|
122 | | | |
|
123 | | [arithmeticMean] | Find the average of numbers. |
|
124 | | [geometricMean] | Find the geometric mean of numbers. |
|
125 | | [harmonicMean] | Find the harmonic mean of numbers. |
|
126 | | [quadriaticMean] | Find the quadriatic mean of numbers. |
|
127 | | [cubicMean] | Find the cubic mean of numbers. |
|
128 |
|
129 | <br>
|
130 | <br>
|
131 |
|
132 |
|
133 | ## References
|
134 |
|
135 | - [Yang, Z. H., & Tian, J. F. (2018). An accurate approximation formula for gamma function. Journal of inequalities and applications, 2018(1), 56.](https://doi.org/10.1186/s13660-018-1646-6)
|
136 | - [MathLib by @alawatthe](https://github.com/alawatthe/MathLib)
|
137 | - [Processing Reference](https://processing.org/reference)
|
138 | - [Common mathematical functions by cppreference](https://en.cppreference.com/w/cpp/numeric/math)
|
139 | - [Modulo operation](https://en.wikipedia.org/wiki/Modulo_operation)
|
140 | - [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)
|
141 | - [Least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple)
|
142 | - [Permutation](https://en.wikipedia.org/wiki/Permutation)
|
143 | - [Binomial coefficient](https://en.wikipedia.org/wiki/Binomial_coefficient)
|
144 | - [Multinomial distribution](https://en.wikipedia.org/wiki/Multinomial_distribution)
|
145 | - [Conventional commits](https://www.conventionalcommits.org/en/v1.0.0-beta.2/)
|
146 |
|
147 | <br>
|
148 | <br>
|
149 |
|
150 |
|
151 | [![](https://img.youtube.com/vi/dW8Cy6WrO94/maxresdefault.jpg)](https://www.youtube.com/watch?v=dW8Cy6WrO94)<br>
|
152 | [![ORG](https://img.shields.io/badge/org-nodef-green?logo=Org)](https://nodef.github.io)
|
153 | [![DOI](https://zenodo.org/badge/141781770.svg)](https://zenodo.org/badge/latestdoi/141781770)
|
154 | [![Coverage Status](https://coveralls.io/repos/github/nodef/extra-math/badge.svg?branch=master)](https://coveralls.io/github/nodef/extra-math?branch=master)
|
155 | [![Test Coverage](https://api.codeclimate.com/v1/badges/13d7102b0273f2a77c66/test_coverage)](https://codeclimate.com/github/nodef/extra-math/test_coverage)
|
156 | [![Maintainability](https://api.codeclimate.com/v1/badges/13d7102b0273f2a77c66/maintainability)](https://codeclimate.com/github/nodef/extra-math/maintainability)
|
157 |
|
158 |
|
159 | [floor]: https://github.com/nodef/extra-math/wiki/floor
|
160 | [ceil]: https://github.com/nodef/extra-math/wiki/ceil
|
161 | [round]: https://github.com/nodef/extra-math/wiki/round
|
162 | [floorDiv]: https://github.com/nodef/extra-math/wiki/floorDiv
|
163 | [ceilDiv]: https://github.com/nodef/extra-math/wiki/ceilDiv
|
164 | [roundDiv]: https://github.com/nodef/extra-math/wiki/roundDiv
|
165 | [rem]: https://github.com/nodef/extra-math/wiki/rem
|
166 | [mod]: https://github.com/nodef/extra-math/wiki/mod
|
167 | [modp]: https://github.com/nodef/extra-math/wiki/modp
|
168 | [constrain]: https://github.com/nodef/extra-math/wiki/constrain
|
169 | [normalize]: https://github.com/nodef/extra-math/wiki/normalize
|
170 | [remap]: https://github.com/nodef/extra-math/wiki/remap
|
171 | [lerp]: https://github.com/nodef/extra-math/wiki/lerp
|
172 | [isPow]: https://github.com/nodef/extra-math/wiki/isPow
|
173 | [prevPow]: https://github.com/nodef/extra-math/wiki/prevPow
|
174 | [nextPow]: https://github.com/nodef/extra-math/wiki/nextPow
|
175 | [root]: https://github.com/nodef/extra-math/wiki/root
|
176 | [log]: https://github.com/nodef/extra-math/wiki/log
|
177 | [properDivisors]: https://github.com/nodef/extra-math/wiki/properDivisors
|
178 | [aliquotSum]: https://github.com/nodef/extra-math/wiki/aliquotSum
|
179 | [minPrimeFactor]: https://github.com/nodef/extra-math/wiki/minPrimeFactor
|
180 | [maxPrimeFactor]: https://github.com/nodef/extra-math/wiki/maxPrimeFactor
|
181 | [primeFactors]: https://github.com/nodef/extra-math/wiki/primeFactors
|
182 | [primeExponentials]: https://github.com/nodef/extra-math/wiki/primeExponentials
|
183 | [isPrime]: https://github.com/nodef/extra-math/wiki/isPrime
|
184 | [gcd]: https://github.com/nodef/extra-math/wiki/gcd
|
185 | [lcm]: https://github.com/nodef/extra-math/wiki/lcm
|
186 | [factorial]: https://github.com/nodef/extra-math/wiki/factorial
|
187 | [binomial]: https://github.com/nodef/extra-math/wiki/binomial
|
188 | [multinomial]: https://github.com/nodef/extra-math/wiki/multinomial
|
189 | [degrees]: https://github.com/nodef/extra-math/wiki/degrees
|
190 | [radians]: https://github.com/nodef/extra-math/wiki/radians
|
191 | [magnitude]: https://github.com/nodef/extra-math/wiki/magnitude
|
192 | [distance]: https://github.com/nodef/extra-math/wiki/distance
|
193 | [sum]: https://github.com/nodef/extra-math/wiki/sum
|
194 | [product]: https://github.com/nodef/extra-math/wiki/product
|
195 | [median]: https://github.com/nodef/extra-math/wiki/median
|
196 | [modes]: https://github.com/nodef/extra-math/wiki/modes
|
197 | [range]: https://github.com/nodef/extra-math/wiki/range
|
198 | [variance]: https://github.com/nodef/extra-math/wiki/variance
|
199 | [arithmeticMean]: https://github.com/nodef/extra-math/wiki/arithmeticMean
|
200 | [geometricMean]: https://github.com/nodef/extra-math/wiki/geometricMean
|
201 | [harmonicMean]: https://github.com/nodef/extra-math/wiki/harmonicMean
|
202 | [quadriaticMean]: https://github.com/nodef/extra-math/wiki/quadriaticMean
|
203 | [cubicMean]: https://github.com/nodef/extra-math/wiki/cubicMean
|