Skip to content

Instantly share code, notes, and snippets.

@justmoon
Created August 23, 2012 19:38
Show Gist options
  • Select an option

  • Save justmoon/3440704 to your computer and use it in GitHub Desktop.

Select an option

Save justmoon/3440704 to your computer and use it in GitHub Desktop.
SJCL BN divInt
/** this /= (int) that */
sjcl.bn.prototype.divIntM = function (that) {
var i, limbs = this.limbs, ll = limbs.length, carry = 0, quotient;
if (this.sign() === -1) {
throw (new sjcl.exception.invalid("divIntM: dividend must be > 0"));
}
if ("number" !== typeof that ||
that > this.radixMask ||
that <= 0) {
throw (new sjcl.exception.invalid("divIntM: divisor must be number (0 < n < radixMask)"));
}
for (i = ll-1; i >= 0; i--) {
quotient = this.radixMask * carry + limbs[i];
carry = quotient % that;
limbs[i] = quotient / that >>> 0;
}
return this.trim();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment