UNPKG

@node-dlc/core

Version:
28 lines 1.15 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.fromPrecision = exports.getPrecision = void 0; const bignumber_js_1 = __importDefault(require("bignumber.js")); // Precision refers to the number of digits after the decimal point. // Refer to https://github.com/discreetlogcontracts/dlcspecs/blob/master/PayoutCurve.md#version-0-payout_function /** * Extract the precision of a number * @param num * @returns The precision of the number */ const getPrecision = (num) => num.decimalPlaces(16).abs().modulo(1).shiftedBy(16).toNumber(); exports.getPrecision = getPrecision; /** * Creates a precise number from a precision * @param precision * @returns The number with the given precision */ const fromPrecision = (precision) => { if (precision.toString().length > 16) throw new Error('Precision is too large'); return new bignumber_js_1.default(precision).shiftedBy(-16); }; exports.fromPrecision = fromPrecision; //# sourceMappingURL=Precision.js.map