Added comment with reasoning for number or array BN instantiation.

This commit is contained in:
Braydon Fuller 2015-07-01 15:30:21 -04:00
parent 2a71863992
commit 4a681f967e
1 changed files with 6 additions and 0 deletions

View File

@ -94,6 +94,12 @@ BufferReader.prototype.readUInt64LEBN = function() {
var second = this.buf.readUInt32LE(this.pos);
var first = this.buf.readUInt32LE(this.pos + 4);
var combined = (first * 0x100000000) + second;
// Instantiating an instance of BN with a number is faster than with an
// array or string. However, the maximum safe number for a double precision
// floating point is 2 ^ 52 - 1 (0x1fffffffffffff), thus we can safely use
// non-floating point numbers less than this amount (52 bits). And in the case
// that the number is larger, we can instatiate an instance of BN by passing
// an array from the buffer (slower) and specifying the endianness.
var bn;
if (combined <= 0x1fffffffffffff) {
bn = new BN(combined);