| 3780 | return al === bl ? 0 : (al < bl ? -1 : 1); |
| 3781 | } |
| 3782 | function _Ldiv(a, b) { |
| 3783 | a = _Lc(a); b = _Lc(b); |
| 3784 | if (_LisZero(b)) { throw new Error("/ by zero"); } |
| 3785 | if (_LisZero(a)) return _L0; |
| 3786 | if (_Leq(a, _LMIN)) { |
| 3787 | if (_Leq(b, _L1) || _Leq(b, _LL(-1, -1))) return _LMIN; |
| 3788 | if (_Leq(b, _LMIN)) return _L1; |
| 3789 | const approx = _Lshl(_Ldiv(_Lshr(a, 1), b), 1); |
| 3790 | if (_LisZero(approx)) return _LisNeg(b) ? _L1 : _LL(-1, -1); |
| 3791 | const rem = _Lsub(a, _Lmul(b, approx)); |
| 3792 | return _Ladd(approx, _Ldiv(rem, b)); |
| 3793 | } |
| 3794 | if (_Leq(b, _LMIN)) return _L0; |
| 3795 | if (_LisNeg(a)) return _LisNeg(b) ? _Ldiv(_Lneg(a), _Lneg(b)) : _Lneg(_Ldiv(_Lneg(a), b)); |
| 3796 | if (_LisNeg(b)) return _Lneg(_Ldiv(a, _Lneg(b))); |
| 3797 | let res = _L0, rem = a; |
| 3798 | while (_Lcmp(rem, b) >= 0) { |
| 3799 | let approx = Math.max(1, Math.floor(_LtoNumber(rem) / _LtoNumber(b))); |
| 3800 | const log2 = Math.ceil(Math.log(approx) / Math.LN2); |
| 3801 | const delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48); |
| 3802 | let approxRes = _LfromNumber(approx); |
| 3803 | let approxRem = _Lmul(approxRes, b); |
| 3804 | while (_LisNeg(approxRem) || _Lcmp(approxRem, rem) > 0) { |
| 3805 | approx -= delta; |
| 3806 | approxRes = _LfromNumber(approx); |
| 3807 | approxRem = _Lmul(approxRes, b); |
| 3808 | } |
| 3809 | if (_LisZero(approxRes)) approxRes = _L1; |
| 3810 | res = _Ladd(res, approxRes); |
| 3811 | rem = _Lsub(rem, approxRem); |
| 3812 | } |
| 3813 | return res; |
| 3814 | } |
| 3815 | function _Lrem(a, b) { a = _Lc(a); b = _Lc(b); return _Lsub(a, _Lmul(_Ldiv(a, b), b)); } |
| 3816 | function _Land(a, b) { a = _Lc(a); b = _Lc(b); return _LL(a.l & b.l, a.h & b.h); } |
| 3817 | function _Lor(a, b) { a = _Lc(a); b = _Lc(b); return _LL(a.l | b.l, a.h | b.h); } |