indutny / bn.js

BigNum in pure javascript
MIT License
1.19k stars 150 forks source link

Inequal BN in Jest #245

Closed jafri closed 3 years ago

jafri commented 4 years ago

When deep comparing these two big numbers I got inequality error from Jest

  1. new BN(0.0001 * Math.pow(10, 18))
  2. new BN('00000000000000000000000000000000000000000000000000005af3107a4000', 16)

These are the same numbers, but here are the inner-representations

  1. BN { negative: 0, words: [ 8011776, 1490116 ], length: 2, red: null }
  2. BN { negative: 0, words: [ 8011776, 1490116, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], length: 2, red: null }

From my perspective, the internal representation of both should be the same as they represent the same number

fanatid commented 4 years ago

Probably there 2 ways for solving issue: 1) Compare numbers with .eq method 2) Use internal _strip for second number

jafri commented 4 years ago

@fanatid _strip does not remove the zeros

fanatid commented 3 years ago

Yes, I was wrong :disappointed: ._strip do not remove zeros, it's only changing .length property. .eq method should be used.