do not handle negative zero for twos compliment.
This commit is contained in:
parent
90fb650d12
commit
608fb8777e
@ -1278,31 +1278,6 @@ utils.nonce = function nonce() {
|
|||||||
// IN THE SOFTWARE.
|
// IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
|
||||||
* Test whether a script number is negative zero.
|
|
||||||
* @param {Buffer} bytes
|
|
||||||
* @param {String} order - `le` or `be`.
|
|
||||||
* @returns {Boolean}
|
|
||||||
*/
|
|
||||||
|
|
||||||
utils.isNegZero = function isNegZero(bytes, order) {
|
|
||||||
var s = 0;
|
|
||||||
var b, res;
|
|
||||||
|
|
||||||
if (order === 'le')
|
|
||||||
s = bytes.length - 1;
|
|
||||||
|
|
||||||
if (bytes[s] & 0x80) {
|
|
||||||
b = bytes[s];
|
|
||||||
bytes[s] &= ~0x80;
|
|
||||||
res = new bn(bytes, order).cmpn(0) === 0;
|
|
||||||
bytes[s] = b;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read uint8.
|
* Read uint8.
|
||||||
* @param {Buffer} arr
|
* @param {Buffer} arr
|
||||||
@ -1487,14 +1462,8 @@ utils.read64 = function read64(arr, off) {
|
|||||||
|
|
||||||
num = arr.slice(off, off + 8);
|
num = arr.slice(off, off + 8);
|
||||||
|
|
||||||
// If we are signed, do (~num + 1) to get
|
if (num[num.length - 1] & 0x80)
|
||||||
// the positive counterpart and set bn's
|
|
||||||
// negative flag.
|
|
||||||
if (num[num.length - 1] & 0x80) {
|
|
||||||
if (utils.isNegZero(num, 'le'))
|
|
||||||
return new bn(0);
|
|
||||||
return new bn(num, 'le').notn(64).addn(1).neg();
|
return new bn(num, 'le').notn(64).addn(1).neg();
|
||||||
}
|
|
||||||
|
|
||||||
return new bn(num, 'le');
|
return new bn(num, 'le');
|
||||||
};
|
};
|
||||||
@ -1513,14 +1482,8 @@ utils.read64BE = function read64BE(arr, off) {
|
|||||||
|
|
||||||
num = arr.slice(off, off + 8);
|
num = arr.slice(off, off + 8);
|
||||||
|
|
||||||
// If we are signed, do (~num + 1) to get
|
if (num[0] & 0x80)
|
||||||
// the positive counterpart and set bn's
|
|
||||||
// negative flag.
|
|
||||||
if (num[0] & 0x80) {
|
|
||||||
if (utils.isNegZero(num, 'be'))
|
|
||||||
return new bn(0);
|
|
||||||
return new bn(num, 'be').notn(64).addn(1).neg();
|
return new bn(num, 'be').notn(64).addn(1).neg();
|
||||||
}
|
|
||||||
|
|
||||||
return new bn(num, 'be');
|
return new bn(num, 'be');
|
||||||
};
|
};
|
||||||
@ -1980,14 +1943,8 @@ utils.write64 = function write64(dst, num, off) {
|
|||||||
|
|
||||||
off = off >>> 0;
|
off = off >>> 0;
|
||||||
|
|
||||||
// Convert the number to the
|
if (num.isNeg())
|
||||||
// negative byte representation.
|
num = num.neg().notn(64).addn(1);
|
||||||
if (num.isNeg()) {
|
|
||||||
if (num.cmpn(0) === 0)
|
|
||||||
num = new bn(0);
|
|
||||||
else
|
|
||||||
num = num.neg().notn(64).addn(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (num.bitLength() > 64)
|
if (num.bitLength() > 64)
|
||||||
num = num.uand(utils.U64);
|
num = num.uand(utils.U64);
|
||||||
@ -2016,14 +1973,8 @@ utils.write64BE = function write64BE(dst, num, off) {
|
|||||||
|
|
||||||
off = off >>> 0;
|
off = off >>> 0;
|
||||||
|
|
||||||
// Convert the number to the
|
if (num.isNeg())
|
||||||
// negative byte representation.
|
num = num.neg().notn(64).addn(1);
|
||||||
if (num.isNeg()) {
|
|
||||||
if (num.cmpn(0) === 0)
|
|
||||||
num = new bn(0);
|
|
||||||
else
|
|
||||||
num = num.neg().notn(64).addn(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (num.bitLength() > 64)
|
if (num.bitLength() > 64)
|
||||||
num = num.uand(utils.U64);
|
num = num.uand(utils.U64);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user