this repo has no description
1"use strict";
2/**
3 * Number related helper functions for metrics.
4 */
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.reduceSignificantDigits = void 0;
7/**
8 * Reduce significant figures of `value` by `significantDigits`.
9 * @param value - Value to reduce precision of.
10 * @param significantDigits - Number of significant digits to reduce precision by.
11 *
12 * Examples:
13 * value = 123.5, significantDigits = 0, result = 120 (no significant digit reduced)
14 * value = 123.5, significantDigits = 1, result = 120 (1 significant digit reduced)
15 * value = 123.5, significantDigits = 2, result = 100 (2 significant digit reduced)
16 */
17function reduceSignificantDigits(value, significantDigits) {
18 const roundFactor = Math.pow(10.0, significantDigits);
19 const roundingFunction = value > 0.0 ? Math.floor : Math.ceil;
20 return roundingFunction(value / roundFactor) * roundFactor;
21}
22exports.reduceSignificantDigits = reduceSignificantDigits;
23//# sourceMappingURL=numerics.js.map