peterolson / BigInteger.js

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

BigInt equality should not distinguish 0 and -0 #102

Closed foones closed 7 years ago

foones commented 7 years ago

For instance:

$ node
> bigInt = require('./BigInteger')
> bigInt.Integer(0) === bigInt.Integer(-0)
false

(It's not clear to me if the fact that BigInt equality relies on the underlying JS number equality may have other unwanted consequences).

peterolson commented 7 years ago

I'm not sure exactly what you mean.

First of all, big Internet doesn't have a method called Integer, so bigInt.Integer will be undefined. I'm not sure how you came up with this example. Did you mean bigInt(0)?

Secondly, you're using the native JavaScript equality operator. If you want to check equality of bigInts, you should use the equals method.

Thirdly, 0 === -0 with native JavaScript numbers, so I'm not sure what issue you are facing.

foones commented 7 years ago

My bad, I did not realize that the interface supported comparing for equality only through the equals method.