UNPKG

@melonproject/token-math

Version:

A small helper library to do precision safe calculations

17 lines (16 loc) 691 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsbi_1 = __importDefault(require("jsbi")); const BigInteger_1 = __importDefault(require("./BigInteger")); const greaterThan_1 = __importDefault(require("./greaterThan")); const toBI_1 = __importDefault(require("./toBI")); const absolute = (a) => { const aBI = toBI_1.default(a); return greaterThan_1.default(new BigInteger_1.default(0), aBI) ? new BigInteger_1.default(jsbi_1.default.unaryMinus(aBI.value)) : aBI; }; exports.default = absolute;