blob: 92b4992e31ae6309b9428d0d045934a6228e7084 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
/**
* Given an integer m > 1, called a modulus, two integers are said to be congruent modulo m,
* if m is a divisor of their difference (i.e., if there is an integer k such that a \u2212 b = km).
*
* Unlike JavaScript's remainder operator (%), this mod function never returns negative values.
*
* @param n An integer
* @param m The modulous
*/
export function mod(n, m) {
return ((n % m) + m) % m;
}
/**
* Reduce sig fig of `value` to `significantDigits`.
* @param value Value to reduce precision of.
* @param significantDigits Significant digits to keep.
*/
export function reduceSignificantDigits(value, significantDigits) {
const roundFactor = Math.pow(10.0, significantDigits);
const roundingFunction = value > 0.0 ? Math.floor : Math.ceil;
return roundingFunction(value / roundFactor) * roundFactor;
}
/**
* Clamps a value between an upper and lower bound.
* @param value The preferred value.
* @param min The minimum allowed value.
* @param max The maximum allowed value.
*/
export function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
//# sourceMappingURL=math-util.js.map
|