rg-stats
Version:
A library for calculating various rhythm game stats.
31 lines • 878 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoundToNDP = exports.LogToBase = void 0;
/**
* Logarithm a number to any base.
* @param number - The number to logarithm.
* @param base - The base to log to.
*
* Uses this identity:
* loga(n) = logb(n) / logb(a)
* we use logb = ln, just because it's right there.
*/
function LogToBase(number, base) {
return Math.log(number) / Math.log(base);
}
exports.LogToBase = LogToBase;
/**
* Round a number to N decimal places.
*
* @example `RoundToNDP(1.594, 1) -> 1.6`
* @example `RoundToNDP(1.591, 2) -> 1.69`
*
* @param number - The number to round.
* @param dp - The amount of decimal places to round to.
*/
function RoundToNDP(number, dp) {
const mul = 10 ** dp;
return Math.round(number * mul) / mul;
}
exports.RoundToNDP = RoundToNDP;
//# sourceMappingURL=math.js.map