Added comment with reasoning for number or array BN instantiation.
This commit is contained in:
parent
2a71863992
commit
4a681f967e
@ -94,6 +94,12 @@ BufferReader.prototype.readUInt64LEBN = function() {
|
|||||||
var second = this.buf.readUInt32LE(this.pos);
|
var second = this.buf.readUInt32LE(this.pos);
|
||||||
var first = this.buf.readUInt32LE(this.pos + 4);
|
var first = this.buf.readUInt32LE(this.pos + 4);
|
||||||
var combined = (first * 0x100000000) + second;
|
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;
|
var bn;
|
||||||
if (combined <= 0x1fffffffffffff) {
|
if (combined <= 0x1fffffffffffff) {
|
||||||
bn = new BN(combined);
|
bn = new BN(combined);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user