Created
August 23, 2012 19:38
-
-
Save justmoon/3440704 to your computer and use it in GitHub Desktop.
SJCL BN divInt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** 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