bigint-mod-arith/dist/index.node.cjs

3 lines
5.1 KiB
JavaScript

"use strict";function n(n){return n>=0?n:-n}function t(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,e=1n,o=1n,i=0n;for(;0n!==n;){const u=t/n,f=t%n,g=r-o*u,p=e-i*u;t=n,n=f,r=o,e=i,o=g,i=p}return{g:t,x:r,y:e}}function r(t,r){let e="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof r?BigInt(n(r)):n(r);if(0n===e)return o;if(0n===o)return e;let i=0n;for(;0n===(1n&(e|o));)e>>=1n,o>>=1n,i++;for(;0n===(1n&e);)e>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(e>o){const n=e;e=o,o=n}o-=e}while(0n!==o);return e<<i}function e(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const r=n%t;return r<0n?r+t:r}function o(n,r){const o=t(e(n,r),r);if(1n!==o.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${r.toString()}`);return e(o.x,r)}exports.abs=n,exports.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},exports.eGcd=t,exports.gcd=r,exports.lcm=function(t,e){return"number"==typeof t&&(t=BigInt(t)),"number"==typeof e&&(e=BigInt(e)),0n===t&&0n===e?BigInt(0):n(t/r(t,e)*e)},exports.max=function(n,t){return n>=t?n:t},exports.min=function(n,t){return n>=t?t:n},exports.modInv=o,exports.modPow=function t(r,i,u){if("number"==typeof r&&(r=BigInt(r)),"number"==typeof i&&(i=BigInt(i)),"number"==typeof u&&(u=BigInt(u)),u<=0n)throw new RangeError("n must be > 0");if(1n===u)return 0n;if(r=e(r,u),i<0n)return o(t(r,n(i),u),u);let f=1n;for(;i>0;)i%2n===1n&&(f=f*r%u),i/=2n,r=r**2n%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