UNPKG

@numio/bigmath

Version:

@numio/bigmath is an arbitrary-precision arithmetic library. It can be used for basic operations with decimal numbers (integers and float)

12 lines (11 loc) 440 B
import { bi2s, s2bi } from "../shared/utils.js"; import { modInner } from "./utils.js"; export const mod = (left, right) => { const bil = s2bi(left); const bir = s2bi(right); if (bil[1] > 0) throw new Error(`${left} is not valid. It should be integer to take a modulo`); if (bir[1] > 0) throw new Error(`${right} is not valid. It should be integer to take a modulo`); return bi2s(modInner(bil, bir)); };