Skip to content

Commit

Permalink
Maybe a little bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Nov 1, 2015
1 parent 82e0108 commit 4a7dc6a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
17 changes: 13 additions & 4 deletions dist/long.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@
*/
Long.fromBits = fromBits;

/**
* @function
* @param {number} base
* @param {number} exponent
* @returns {number}
* @inner
*/
var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4)

/**
* @param {string} str
* @param {(boolean|number)=} unsigned
Expand Down Expand Up @@ -255,14 +264,14 @@

// Do several (8) digits each time through the loop, so as to
// minimize the calls to the very expensive emulated div.
var radixToPower = fromNumber(Math.pow(radix, 8));
var radixToPower = fromNumber(pow_dbl(radix, 8));

var result = ZERO;
for (var i = 0; i < str.length; i += 8) {
var size = Math.min(8, str.length - i);
var value = parseInt(str.substring(i, i + size), radix);
if (size < 8) {
var power = fromNumber(Math.pow(radix, size));
var power = fromNumber(pow_dbl(radix, size));
result = result.mul(power).add(fromNumber(value));
} else {
result = result.mul(radixToPower);
Expand Down Expand Up @@ -514,7 +523,7 @@

// Do several (6) digits each time through the loop, so as to
// minimize the calls to the very expensive emulated div.
var radixToPower = fromNumber(Math.pow(radix, 6), this.unsigned);
var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned);
rem = this;
var result = '';
while (true) {
Expand Down Expand Up @@ -989,7 +998,7 @@
// We will tweak the approximate result by changing it in the 48-th digit or
// the smallest non-fractional digit, whichever is larger.
var log2 = Math.ceil(Math.log(approx) / Math.LN2),
delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48),
delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48),

// Decrease the approximation until it is smaller than the remainder. Note
// that if it is too large, the product overflows and is negative.
Expand Down
16 changes: 8 additions & 8 deletions dist/long.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/long.min.js.gz
Binary file not shown.
Loading

0 comments on commit 4a7dc6a

Please sign in to comment.