lib/mongodb/bson/lib/bson/decimal128.js
function(value) {
  var DIVISOR = Long.fromNumber(1000 * 1000 * 1000);
  var _rem = Long.fromNumber(0);
  var i = 0;

  if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
    return { quotient: value, rem: _rem };
  }

  for (i = 0; i <= 3; i++) {
    // Adjust remainder to match value of next dividend
    _rem = _rem.shiftLeft(32);
    // Add the divided to _rem
    _rem = _rem.add(new Long(value.parts[i], 0));
    value.parts[i] = _rem.div(DIVISOR).low_;
    _rem = _rem.modulo(DIVISOR);
  }

  return { quotient: value, rem: _rem };
}
function(value) {
  var DIVISOR = Long.fromNumber(1000 * 1000 * 1000);
  var _rem = Long.fromNumber(0);
  var i = 0;

  if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
    return { quotient: value, rem: _rem };
  }

  for (i = 0; i <= 3; i++) {
    // Adjust remainder to match value of next dividend
    _rem = _rem.shiftLeft(32);
    // Add the divided to _rem
    _rem = _rem.add(new Long(value.parts[i], 0));
    value.parts[i] = _rem.div(DIVISOR).low_;
    _rem = _rem.modulo(DIVISOR);
  }

  return { quotient: value, rem: _rem };
}
function ( value ) { var DIVISOR = Long . fromNumber ( 1000 * 1000 * 1000 ) ; var _rem = Long . fromNumber ( 0 ) ; var i = 0 ; if ( ! value . parts [ 0 ] && ! value . parts [ 1 ] && ! value . parts [ 2 ] && ! value . parts [ 3 ] ) { return { quotient : value , rem : _rem } ; } for ( i = 0 ; i <= 3 ; i ++ ) { // Adjust remainder to match value of next dividend _rem = _rem . shiftLeft ( 32 ) ; // Add the divided to _rem _rem = _rem . add ( new Long ( value . parts [ i ] , 0 ) ) ; value . parts [ i ] = _rem . div ( DIVISOR ) . low_ ; _rem = _rem . modulo ( DIVISOR ) ; } return { quotient : value , rem : _rem } ; }
Divide two uint128 values
Divide two uint128 values