|
| 1 | +**Mathematics** is the classification and study of all possible patterns [(1)]. 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*. |
| 2 | + |
| 3 | +**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₂!...`. |
| 4 | + |
| 5 | +**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. |
| 6 | + |
| 7 | +**Geometry**: Perform conversion from [degrees] to [radians] and vice versa. Find the [magnitude] of a vector or [distance] between two points. |
| 8 | + |
| 9 | +**Statistics**: For a list of numbers, we can calculate the [sum], [product], [arithmeticMean]. [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. |
| 10 | + |
| 11 | +[(1)]: https://en.wikipedia.org/wiki/Walter_Warwick_Sawyer |
| 12 | + |
| 13 | +▌ |
| 14 | +📦 [JSR](https://jsr.io/@nodef/extra-math), |
| 15 | +📰 [Docs](https://jsr.io/@nodef/extra-math/doc), |
| 16 | + |
| 17 | +<br> |
| 18 | + |
| 19 | + |
| 20 | +```javascript |
| 21 | +import * as xmath from "jsr:@nodef/extra-math"; |
| 22 | + |
| 23 | +xmath.sum(1, 2, 3, 4); |
| 24 | +// → 10 |
| 25 | + |
| 26 | +xmath.median(1, 7, 8); |
| 27 | +// → 7 |
| 28 | + |
| 29 | +xmath.variance(1, 2, 3, 4); |
| 30 | +// → 1.25 |
| 31 | + |
| 32 | +xmath.lcm(2, 3, 4); |
| 33 | +// → 12 |
| 34 | +``` |
| 35 | + |
| 36 | +<br> |
| 37 | +<br> |
| 38 | + |
| 39 | + |
| 40 | +## Index |
| 41 | + |
| 42 | +| Name | Description | |
| 43 | +| ---- | ---- | |
| 44 | +| [floor] | Round down a number to specific precision. | |
| 45 | +| [ceil] | Round up a number to specific precision. | |
| 46 | +| [round] | Round a number to specific precision. | |
| 47 | +| | | |
| 48 | +| [floorDiv] | Perform floor-divison of two numbers. | |
| 49 | +| [ceilDiv] | Perform ceiling-divison of two numbers. | |
| 50 | +| [roundDiv] | Perform rounded-divison of two numbers. | |
| 51 | +| | | |
| 52 | +| [rem] | Find the remainder of x/y with sign of x (truncated division). | |
| 53 | +| [mod] | Find the remainder of x/y with sign of y (floored division). | |
| 54 | +| [modp] | Find the remainder of x/y with +ve sign (euclidean division). | |
| 55 | +| | | |
| 56 | +| [constrain] | Constrain a number within a minimum and a maximum value. | |
| 57 | +| [normalize] | Normalize a number from its current range into a value between 0 and 1. | |
| 58 | +| [remap] | Re-map a number from one range to another. | |
| 59 | +| [lerp] | Linearly interpolate a number between two numbers. | |
| 60 | +| | | |
| 61 | +| [isPow] | Check if a number is a power-of-n. | |
| 62 | +| [prevPow] | Find largest power-of-n less than or equal to given number. | |
| 63 | +| [nextPow] | Find smallest power-of-n greater than or equal to given number. | |
| 64 | +| | | |
| 65 | +| [root] | Find the nth root of a number (ⁿ√). | |
| 66 | +| [log] | Find the logarithm of a number with a given base. | |
| 67 | +| | | |
| 68 | +| [properDivisors] | List all divisors of a number, except itself. | |
| 69 | +| [aliquotSum] | Sum all proper divisors of a number. | |
| 70 | +| [minPrimeFactor] | Find the least prime number which divides a number. | |
| 71 | +| [maxPrimeFactor] | Find the greatest prime number which divides a number. | |
| 72 | +| [primeFactors] | Find the prime factors of a number. | |
| 73 | +| [primeExponentials] | Find the prime factors and respective exponents of a number. | |
| 74 | +| [isPrime] | Check if number is prime. | |
| 75 | +| [gcd] | Find the greatest common divisor of numbers. | |
| 76 | +| [lcm] | Find the least common multiple of numbers. | |
| 77 | +| | | |
| 78 | +| [factorial] | Find the factorial of a number. | |
| 79 | +| [binomial] | Find the number of ways to choose k elements from a set of n elements. | |
| 80 | +| [multinomial] | Find the number of ways to put n objects in m bins (n=sum(kᵢ)). | |
| 81 | +| | | |
| 82 | +| [degrees] | Convert radians to degrees. | |
| 83 | +| [radians] | Convert degrees to radians. | |
| 84 | +| [magnitude] | Calculate the magnitude (length) of a vector. | |
| 85 | +| [distance] | Calculate the distance between two points. | |
| 86 | +| | | |
| 87 | +| [sum] | Find the sum of numbers (Σ). | |
| 88 | +| [product] | Find the product of numbers (∏). | |
| 89 | +| [median] | Find the value separating the higher and lower halves of numbers. | |
| 90 | +| [modes] | Find the values that appear most often. | |
| 91 | +| [range] | Find the smallest and largest values. | |
| 92 | +| [variance] | Find the mean of squared deviation of numbers from its mean. | |
| 93 | +| | | |
| 94 | +| [arithmeticMean] | Find the average of numbers. | |
| 95 | +| [geometricMean] | Find the geometric mean of numbers. | |
| 96 | +| [harmonicMean] | Find the harmonic mean of numbers. | |
| 97 | +| [quadriaticMean] | Find the quadriatic mean of numbers. | |
| 98 | +| [cubicMean] | Find the cubic mean of numbers. | |
| 99 | + |
| 100 | +<br> |
| 101 | +<br> |
| 102 | + |
| 103 | + |
| 104 | +## References |
| 105 | + |
| 106 | +- [An accurate approximation formula for gamma function; Yang, et al. (2018)](https://doi.org/10.1186/s13660-018-1646-6) |
| 107 | +- [MathLib by @alawatthe](https://github.com/alawatthe/MathLib) |
| 108 | +- [Processing Reference](https://processing.org/reference) |
| 109 | +- [Common mathematical functions by cppreference](https://en.cppreference.com/w/cpp/numeric/math) |
| 110 | +- [Modulo operation](https://en.wikipedia.org/wiki/Modulo_operation) |
| 111 | +- [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) |
| 112 | +- [Least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple) |
| 113 | +- [Permutation](https://en.wikipedia.org/wiki/Permutation) |
| 114 | +- [Binomial coefficient](https://en.wikipedia.org/wiki/Binomial_coefficient) |
| 115 | +- [Multinomial distribution](https://en.wikipedia.org/wiki/Multinomial_distribution) |
| 116 | +- [Conventional commits](https://www.conventionalcommits.org/en/v1.0.0-beta.2/) |
| 117 | + |
| 118 | +<br> |
| 119 | +<br> |
| 120 | + |
| 121 | + |
| 122 | +[](https://wolfram77.github.io)<br> |
| 123 | +[](https://nodef.github.io) |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +[floor]: https://jsr.io/@nodef/extra-sql/doc/~/floor |
| 128 | +[ceil]: https://jsr.io/@nodef/extra-sql/doc/~/ceil |
| 129 | +[round]: https://jsr.io/@nodef/extra-sql/doc/~/round |
| 130 | +[floorDiv]: https://jsr.io/@nodef/extra-sql/doc/~/floorDiv |
| 131 | +[ceilDiv]: https://jsr.io/@nodef/extra-sql/doc/~/ceilDiv |
| 132 | +[roundDiv]: https://jsr.io/@nodef/extra-sql/doc/~/roundDiv |
| 133 | +[rem]: https://jsr.io/@nodef/extra-sql/doc/~/rem |
| 134 | +[mod]: https://jsr.io/@nodef/extra-sql/doc/~/mod |
| 135 | +[modp]: https://jsr.io/@nodef/extra-sql/doc/~/modp |
| 136 | +[constrain]: https://jsr.io/@nodef/extra-sql/doc/~/constrain |
| 137 | +[normalize]: https://jsr.io/@nodef/extra-sql/doc/~/normalize |
| 138 | +[remap]: https://jsr.io/@nodef/extra-sql/doc/~/remap |
| 139 | +[lerp]: https://jsr.io/@nodef/extra-sql/doc/~/lerp |
| 140 | +[isPow]: https://jsr.io/@nodef/extra-sql/doc/~/isPow |
| 141 | +[prevPow]: https://jsr.io/@nodef/extra-sql/doc/~/prevPow |
| 142 | +[nextPow]: https://jsr.io/@nodef/extra-sql/doc/~/nextPow |
| 143 | +[root]: https://jsr.io/@nodef/extra-sql/doc/~/root |
| 144 | +[log]: https://jsr.io/@nodef/extra-sql/doc/~/log |
| 145 | +[properDivisors]: https://jsr.io/@nodef/extra-sql/doc/~/properDivisors |
| 146 | +[aliquotSum]: https://jsr.io/@nodef/extra-sql/doc/~/aliquotSum |
| 147 | +[minPrimeFactor]: https://jsr.io/@nodef/extra-sql/doc/~/minPrimeFactor |
| 148 | +[maxPrimeFactor]: https://jsr.io/@nodef/extra-sql/doc/~/maxPrimeFactor |
| 149 | +[primeFactors]: https://jsr.io/@nodef/extra-sql/doc/~/primeFactors |
| 150 | +[primeExponentials]: https://jsr.io/@nodef/extra-sql/doc/~/primeExponentials |
| 151 | +[isPrime]: https://jsr.io/@nodef/extra-sql/doc/~/isPrime |
| 152 | +[gcd]: https://jsr.io/@nodef/extra-sql/doc/~/gcd |
| 153 | +[lcm]: https://jsr.io/@nodef/extra-sql/doc/~/lcm |
| 154 | +[factorial]: https://jsr.io/@nodef/extra-sql/doc/~/factorial |
| 155 | +[binomial]: https://jsr.io/@nodef/extra-sql/doc/~/binomial |
| 156 | +[multinomial]: https://jsr.io/@nodef/extra-sql/doc/~/multinomial |
| 157 | +[degrees]: https://jsr.io/@nodef/extra-sql/doc/~/degrees |
| 158 | +[radians]: https://jsr.io/@nodef/extra-sql/doc/~/radians |
| 159 | +[magnitude]: https://jsr.io/@nodef/extra-sql/doc/~/magnitude |
| 160 | +[distance]: https://jsr.io/@nodef/extra-sql/doc/~/distance |
| 161 | +[sum]: https://jsr.io/@nodef/extra-sql/doc/~/sum |
| 162 | +[product]: https://jsr.io/@nodef/extra-sql/doc/~/product |
| 163 | +[median]: https://jsr.io/@nodef/extra-sql/doc/~/median |
| 164 | +[modes]: https://jsr.io/@nodef/extra-sql/doc/~/modes |
| 165 | +[range]: https://jsr.io/@nodef/extra-sql/doc/~/range |
| 166 | +[variance]: https://jsr.io/@nodef/extra-sql/doc/~/variance |
| 167 | +[arithmeticMean]: https://jsr.io/@nodef/extra-sql/doc/~/arithmeticMean |
| 168 | +[geometricMean]: https://jsr.io/@nodef/extra-sql/doc/~/geometricMean |
| 169 | +[harmonicMean]: https://jsr.io/@nodef/extra-sql/doc/~/harmonicMean |
| 170 | +[quadriaticMean]: https://jsr.io/@nodef/extra-sql/doc/~/quadriaticMean |
| 171 | +[cubicMean]: https://jsr.io/@nodef/extra-sql/doc/~/cubicMean |
0 commit comments