peterolson / BigInteger.js

An arbitrary length integer library for Javascript
The Unlicense
1.12k stars 187 forks source link

Incorrect arithmetic #230

Closed LeeYiyuan closed 2 years ago

LeeYiyuan commented 2 years ago

When adding two big integers, it seems that there is some rounding that is taking place unintentionally.

Test code:

// Node v12.22.8, big-integer v1.6.51

const bi = require("big-integer");

console.log(bi("0"));
> Integer { value: 0n }

console.log(bi("98765432112345678")));
> Integer { value: 98765432112345678n }

console.log(bi("0") + bi("98765432112345678"));
> 98765432112345680

Perhaps I am missing something...

LeeYiyuan commented 2 years ago

Figured it out -- use .add instead of operators as mentioned in the README. Sorry for the alarm.