UNPKG

@technobuddha/library

Version:
24 lines (23 loc) 1.13 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.floor = void 0; var floor_1 = __importDefault(require("lodash/floor")); /** * A tweaked variant of {@code Math.floor} which tolerates if the passed number * is infinitesimally smaller than the closest integer. It often happens with * the results of floating point calculations because of the finite precision * of the intermediate results. For example {@code Math.floor(Math.log(1000) / * Math.LN10) == 2}, not 3 as one would expect. * @param input A number. * @param precision The prevision to round down to. * @return The largest integer less than or equal to {@code num}. */ function floor(input, _a) { var _b = _a === void 0 ? {} : _a, _c = _b.tolerance, tolerance = _c === void 0 ? 0 : _c, _d = _b.precision, precision = _d === void 0 ? 0 : _d; return floor_1.default(input + (Math.sign(input) * tolerance) + Number.EPSILON, precision); } exports.floor = floor; exports.default = floor;