peterolson / BigInteger.js

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

Negative mod #139

Closed wa1one closed 6 years ago

wa1one commented 6 years ago

bigInt('-17').mod(bigInt('5'))

Should be 3

wa1one commented 6 years ago

How to change mod function to my own mod function

peterolson commented 6 years ago

It works as expected. BigInteger matches the behavior of plain JavaScript in this case:

-17 % 5 === -2
peterolson commented 6 years ago

If you want to have the positive mod, you can add 5 to the result.