summaryrefslogtreecommitdiff
path: root/node_modules/@jet-app/app-store/tmp/src/foundation/util/math-util.js
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /node_modules/@jet-app/app-store/tmp/src/foundation/util/math-util.js
init commit
Diffstat (limited to 'node_modules/@jet-app/app-store/tmp/src/foundation/util/math-util.js')
-rw-r--r--node_modules/@jet-app/app-store/tmp/src/foundation/util/math-util.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/node_modules/@jet-app/app-store/tmp/src/foundation/util/math-util.js b/node_modules/@jet-app/app-store/tmp/src/foundation/util/math-util.js
new file mode 100644
index 0000000..92b4992
--- /dev/null
+++ b/node_modules/@jet-app/app-store/tmp/src/foundation/util/math-util.js
@@ -0,0 +1,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 \ No newline at end of file