How to use big-integer - 10 common examples

To help you get started, we’ve selected a few big-integer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

iden3 / websnark / test / int.js View on Github
``````it("It should profile int", async () => {

const pA = pbInt.alloc();
const pB = pbInt.alloc();
const pC = pbInt.alloc(64);

let start, end, time;

const A = bigInt.one.shiftLeft(256).minus(1);
const B = bigInt.one.shiftLeft(256).minus(1);

pbInt.set(pA, A);
pbInt.set(pB, B);

start = new Date().getTime();
pbInt.test_int_mul(pA, pB, pC, 50000000);
end = new Date().getTime();
time = end - start;

const c1 = pbInt.get(pC, 1, 64);
assert(c1.equals(A.times(B)));

console.log("Mul Time (ms): " + time);

// start = new Date().getTime();
// pbInt.test_int_mulOld(pA, pB, pC, 50000000);``````
iden3 / websnark / test / f1.js View on Github
``````it("It should do various test in zq Snarks modules", async () =&gt; {
const q = bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583");
const f1 = await buildF1(q);
const v= [
q.minus(1),
q.minus(2),
q.minus(1).shiftRight(1),
q.minus(1).shiftRight(1).minus(1),
q.minus(1).shiftRight(1).minus(2),
bigInt(2),
bigInt.one,
bigInt.zero
];

const pA = f1.allocInt();
const pB = f1.allocInt();
const pC = f1.allocInt();
let c;

for (let i=0; i``````
weijiekoh / zkmm / mastermind / src / test_mastermind.ts View on Github
``````const genSalt = (): bigInt.BigInteger => {
const buf = crypto.randomBytes(54)
const salt = bigInt.fromArray(Array.from(buf), 256, false).minus(340)

// 4 * (4^3) + 4 * (4^2) + 4 * (4^1) + 4 * (4^0) = 340
// Only return values greater than the largest possible solution
if (salt.lt(340)) {
return genSalt()
}

return salt
}``````
masx200 / webpack-react-vue-spa-awesome-config / src / 圆周率计算-可设置圆周率位数-可选择线程个数-多线程大数框架webworker输出useragent大数框架 / mypidashujisuan-bigint.js View on Github
``````testname +
"线程数为" +
" " +
"圆周率计算" +
piwei +
"位 " +
"计算圆周率中......" +
"  \n"
);
//   debugger;
//   console.log(outputtext1);
console.log(testname);
console.time(testname);
strt = new Date().getTime();
p = new bigInt(0);
//   myworker = [];
finishflag = [];
//   if (typeof worker1 == "undefined") {
//   }
//   for (var i = 0, len = threadgeshu; i &lt; len; i++) {
//     myworker[i] = worker1;
//   }
//       myworker[key]=undefined
//   }``````
masx200 / webpack-react-vue-spa-awesome-config / src / 圆周率计算-可设置圆周率位数-可选择线程个数-多线程大数框架webworker输出useragent大数框架 / mypidashujisuan-bigint.js View on Github
``````arr[index].onmessage = function(event) {
console.log(
"主线程从副线程" + (index + 1) + "接收" + "event.data\n",
event.data
);
// console.log(
//   "第一个参数",
//   event.data[0],
//   "\n第二个参数",
//   event.data[1]
// );
var p1 = new bigInt(event.data[0]);
x = Math.max(x, parseInt(event.data[1]));
finishflag[index] = 1;
//   currentValue.terminate()
rs(event.data);
};
arr[index].onerror = e => {``````
masx200 / webpack-react-vue-spa-awesome-config / src / 圆周率计算-可设置圆周率位数-可选择线程个数-多线程大数框架webworker输出useragent大数框架 / mypidashujisuan-bigint.js View on Github
``````arr[index].onmessage = function(event) {
console.log(
"主线程从副线程" + (index + 1) + "接收" + "event.data\n",
event.data
);
// console.log(
//   "第一个参数",
//   event.data[0],
//   "\n第二个参数",
//   event.data[1]
// );
var p1 = new bigInt(event.data[0]);
x = Math.max(x, parseInt(event.data[1]));
finishflag[index] = 1;
//   currentValue.terminate()
rs(event.data);
};
arr[index].onerror = e => {``````
DaoCasino / BankRollerApp / src / model / games.js View on Github
``````confirmNumber_dice(input){
/* Equivalent of solidity hash function:
function confirm(bytes32 _s) public returns(uint256){
return uint256 (sha3(_s));
}
*/
let    hash    = '0x'+Eth.ABI.soliditySHA3(['bytes32'],[ input ]).toString('hex')
let    confirm = bigInt(hash,16).divmod(65536).remainder.value
return confirm
}
confirmNumber_blackjack(input){``````
jeffijoe / snicket / src / subscriptions / all-subscription.ts View on Github
``````async function getStartPositionForEnd() {
try {
// Edge case where start position is 0 (beginning of time) and the stream is empty.
return BigInteger.zero
}
} catch (error) {
logger.error(
'Unable to get stream information. Dropping subscription and disposing.',
error
)
await dropAndDispose()
return BigInteger(-1)
}
}``````
thetrime / proscript2 / src / arithmetic.js View on Github
``````function toRationals(args) // Takes an array of Objects and returns an array of Rationals
{
var r = new Array(args.length);
for (var i = 0; i &lt; args.length; i++)
{
var v = evaluate_expression(args[i]);
if (v instanceof RationalTerm)
r[i] = v.value;
else if (v instanceof BigIntegerTerm)
r[i] = new Rational(v.value, BigInteger.one);
else if (v instanceof IntegerTerm)
r[i] = new Rational(new BigInteger(v.value), BigInteger.one);
else
throw new Error("Illegal BigInteger conversion from " + v.getClass());
}
return r;
}``````
jeffijoe / snicket / src / postgres / pg-stream-store.ts View on Github
``````if (messages.length === count + 1) {
// We intentionally included another message to see if we are at the end.
// We are not.
isEnd = false
messages.splice(messages.length - 1, 1)
}

const lastMessage = messages[messages.length - 1]
const nextPosition = forward
? BigInteger(lastMessage.position)
.plus(BigInteger.one)
.toString()
: // nextVersion will be 0 at the end, but that always includes the first message in
// the stream. There's no way around this that does not skip the first message.
BigInteger.max(
BigInteger(lastMessage.position).minus(BigInteger.one),
BigInteger(-1)
).toString()

return {
isEnd,
nextPosition,
messages: await maybeFilterExpiredMessages(messages)
}
}``````

big-integer

An arbitrary length integer library for Javascript