bigint-mod-arith/lib/index.browser.bundle.mod.js

2 lines
1.2 KiB
JavaScript

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