UNPKG

@melonproject/token-math

Version:

A small helper library to do precision safe calculations

16 lines (15 loc) 684 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const isZero_1 = __importDefault(require("./isZero")); const modulo_1 = __importDefault(require("./modulo")); const toBI_1 = __importDefault(require("./toBI")); // console.log(typeof BigInt === undefined); const getGreatestCommonDivisor = (a, b) => { const bBI = toBI_1.default(b); const aBI = toBI_1.default(a); return isZero_1.default(bBI) ? aBI : getGreatestCommonDivisor(bBI, modulo_1.default(aBI, bBI)); }; exports.default = getGreatestCommonDivisor;