MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / _Ldiv

Function _Ldiv

vm/ByteCodeTranslator/src/javascript/parparvm_runtime.js:3782–3814  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

3780 return al === bl ? 0 : (al < bl ? -1 : 1);
3781}
3782function _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}
3815function _Lrem(a, b) { a = _Lc(a); b = _Lc(b); return _Lsub(a, _Lmul(_Ldiv(a, b), b)); }
3816function _Land(a, b) { a = _Lc(a); b = _Lc(b); return _LL(a.l & b.l, a.h & b.h); }
3817function _Lor(a, b) { a = _Lc(a); b = _Lc(b); return _LL(a.l | b.l, a.h | b.h); }

Callers 2

_LremFunction · 0.85
_LtoStrFunction · 0.85

Calls 15

_LcFunction · 0.85
_LisZeroFunction · 0.85
_LeqFunction · 0.85
_LLFunction · 0.85
_LshlFunction · 0.85
_LshrFunction · 0.85
_LisNegFunction · 0.85
_LsubFunction · 0.85
_LmulFunction · 0.85
_LaddFunction · 0.85
_LnegFunction · 0.85
_LcmpFunction · 0.85

Tested by

no test coverage detected