indutny / bn.js

BigNum in pure javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inequal BN in Jest

jafri opened this issue · comments

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

Probably there 2 ways for solving issue:

  1. Compare numbers with .eq method
  2. Use internal _strip for second number

@fanatid _strip does not remove the zeros

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