UNPKG

hm-aftermath-ts-sdk

Version:
46 lines (45 loc) 1.45 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.IFixedUtils = void 0; const casting_1 = require("./casting"); class IFixedUtils { } exports.IFixedUtils = IFixedUtils; _a = IFixedUtils; IFixedUtils.ONE = BigInt(1000000000000000000); IFixedUtils.GREATEST_BIT = BigInt(1) << BigInt(255); IFixedUtils.NOT_GREATEST_BIT = (BigInt(1) << BigInt(255)) - BigInt(1); IFixedUtils.numberFromIFixed = (value) => { const absVal = _a.abs(value); const integerPart = Number(absVal / _a.ONE); const decimalPart = Number(absVal % _a.ONE) / Number(_a.ONE); return _a.sign(value) * (integerPart + decimalPart); }; IFixedUtils.iFixedFromNumber = (value) => { const newValue = BigInt(Math.floor(Math.abs(value) * Number(_a.ONE))); if (value < 0) return _a.neg(newValue); return newValue; }; IFixedUtils.abs = (value) => { if (value >= _a.GREATEST_BIT) return _a.neg(value); return value; }; IFixedUtils.sign = (value) => { if (value >= _a.GREATEST_BIT) return -1; if (value === BigInt(0)) return 0; return 1; }; IFixedUtils.neg = (value) => { return (((value ^ _a.NOT_GREATEST_BIT) + BigInt(1)) ^ _a.GREATEST_BIT); }; IFixedUtils.iFixedFromBytes = (bytes) => { return casting_1.Casting.bigIntFromBytes(bytes); }; IFixedUtils.iFixedFromStringBytes = (bytes) => { return _a.iFixedFromBytes(casting_1.Casting.bytesFromStringBytes(bytes)); };