blob: 822f51feb53fe8a48ba1a2040219a6c08a64e300 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
"use strict";
/**
* Number related helper functions for metrics.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.reduceSignificantDigits = void 0;
/**
* Reduce significant figures of `value` by `significantDigits`.
* @param value - Value to reduce precision of.
* @param significantDigits - Number of significant digits to reduce precision by.
*
* Examples:
* value = 123.5, significantDigits = 0, result = 120 (no significant digit reduced)
* value = 123.5, significantDigits = 1, result = 120 (1 significant digit reduced)
* value = 123.5, significantDigits = 2, result = 100 (2 significant digit reduced)
*/
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;
}
exports.reduceSignificantDigits = reduceSignificantDigits;
//# sourceMappingURL=numerics.js.map
|