Socket
Socket
Sign inDemoInstall

bn.js

Package Overview
Dependencies
0
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.7.0 to 4.8.0

2

package.json
{
"name": "bn.js",
"version": "4.7.0",
"version": "4.8.0",
"description": "Big number implementation in pure javascript",

@@ -5,0 +5,0 @@ "main": "lib/bn.js",

@@ -22,2 +22,4 @@ # <img src="./logo.png" alt="bn.js" width="160" height="160" />

**Note**: decimals are not supported in this library.
## Notation

@@ -77,2 +79,4 @@

* `a.eq(b)` - `a` equals `b` (`n`)
* `a.toTwos(width)` - convert to two's complement representation, where `width` is bit width
* `a.fromTwos(width)` - convert from two's complement representation, where `width` is the bit width

@@ -79,0 +83,0 @@ ### Arithmetics

@@ -263,2 +263,54 @@ /* global describe, it */

});
describe('.fromTwos', function () {
it('should convert from two\'s complement to negative number', function () {
assert.equal(new BN('00000000', 16).fromTwos(32).toNumber(), 0);
assert.equal(new BN('00000001', 16).fromTwos(32).toNumber(), 1);
assert.equal(new BN('7fffffff', 16).fromTwos(32).toNumber(), 2147483647);
assert.equal(new BN('80000000', 16).fromTwos(32).toNumber(), -2147483648);
assert.equal(new BN('f0000000', 16).fromTwos(32).toNumber(), -268435456);
assert.equal(new BN('f1234567', 16).fromTwos(32).toNumber(), -249346713);
assert.equal(new BN('ffffffff', 16).fromTwos(32).toNumber(), -1);
assert.equal(new BN('fffffffe', 16).fromTwos(32).toNumber(), -2);
assert.equal(new BN('fffffffffffffffffffffffffffffffe', 16)
.fromTwos(128).toNumber(), -2);
assert.equal(new BN('ffffffffffffffffffffffffffffffff' +
'fffffffffffffffffffffffffffffffe', 16).fromTwos(256).toNumber(), -2);
assert.equal(new BN('ffffffffffffffffffffffffffffffff' +
'ffffffffffffffffffffffffffffffff', 16).fromTwos(256).toNumber(), -1);
assert.equal(new BN('7fffffffffffffffffffffffffffffff' +
'ffffffffffffffffffffffffffffffff', 16).fromTwos(256).toString(10),
new BN('5789604461865809771178549250434395392663499' +
'2332820282019728792003956564819967', 10).toString(10));
assert.equal(new BN('80000000000000000000000000000000' +
'00000000000000000000000000000000', 16).fromTwos(256).toString(10),
new BN('-578960446186580977117854925043439539266349' +
'92332820282019728792003956564819968', 10).toString(10));
});
});
describe('.toTwos', function () {
it('should convert from negative number to two\'s complement', function () {
assert.equal(new BN(0).toTwos(32).toString(16), '0');
assert.equal(new BN(1).toTwos(32).toString(16), '1');
assert.equal(new BN(2147483647).toTwos(32).toString(16), '7fffffff');
assert.equal(new BN('-2147483648', 10).toTwos(32).toString(16), '80000000');
assert.equal(new BN('-268435456', 10).toTwos(32).toString(16), 'f0000000');
assert.equal(new BN('-249346713', 10).toTwos(32).toString(16), 'f1234567');
assert.equal(new BN('-1', 10).toTwos(32).toString(16), 'ffffffff');
assert.equal(new BN('-2', 10).toTwos(32).toString(16), 'fffffffe');
assert.equal(new BN('-2', 10).toTwos(128).toString(16),
'fffffffffffffffffffffffffffffffe');
assert.equal(new BN('-2', 10).toTwos(256).toString(16),
'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe');
assert.equal(new BN('-1', 10).toTwos(256).toString(16),
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
assert.equal(new BN('5789604461865809771178549250434395392663' +
'4992332820282019728792003956564819967', 10).toTwos(256).toString(16),
'7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
assert.equal(new BN('-578960446186580977117854925043439539266' +
'34992332820282019728792003956564819968', 10).toTwos(256).toString(16),
'8000000000000000000000000000000000000000000000000000000000000000');
});
});
});

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc