bigint-mod-arith/dist/bundles/bigint-mod-arith.esm.js

2 lines
1.2 KiB
JavaScript
Raw Normal View History

function n(n){return n>=0?n:-n}function t(n){if(1n===(n=BigInt(n)))return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){let r=BigInt(n),i=BigInt(t);if(r<=0n||i<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,u=1n,o=1n,f=0n;for(;0n!==r;){const n=i/r,t=i%r,c=e-o*n,g=u-f*n;i=r,r=t,e=o,u=f,o=c,f=g}return{g:i,x:e,y:u}}function i(t,r){let i=BigInt(n(t)),e=BigInt(n(r));if(0n===i)return e;if(0n===e)return i;let u=0n;for(;0n===(1n&(i|e));)i>>=1n,e>>=1n,u++;for(;0n===(1n&i);)i>>=1n;do{for(;0n===(1n&e);)e>>=1n;if(i>e){const n=i;i=e,e=n}e-=i}while(0n!==e);return i<<u}function e(t,r){const e=BigInt(t),u=BigInt(r);return 0n===e&&0n===u?BigInt(0):n(e*u)/i(e,u)}function u(n,t){return n>=t?n:t}function o(n,t){return n>=t?t:n}function f(n,t){const r=BigInt(t);if(t<=0)return NaN;const i=BigInt(n)%r;return i<0n?i+r:i}function c(n,t){try{const i=r(f(n,t),t);return 1n!==i.g?NaN:f(i.x,t)}catch(n){return NaN}}function g(t,r,i){const e=BigInt(i);if(e<=0n)return NaN;if(1n===e)return BigInt(0);let u=f(t,e);if((r=BigInt(r))<0n)return c(g(u,n(r),e),e);let o=1n;for(;r>0;)r%2n===1n&&(o=o*u%e),r/=2n,u=u**2n%e;return o}export{n as abs,t as bitLength,r as eGcd,i as gcd,e as lcm,u as max,o as min,c as modInv,g as modPow,f as toZn};