Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 / new BigInteger("-1").compareTo(new BigInteger("-1")) === -Infinity #16

Open
Yaffle opened this issue Apr 28, 2014 · 3 comments
Open

Comments

@Yaffle
Copy link

Yaffle commented Apr 28, 2014

negative zero is a result of "compareTo"

@gmelika
Copy link

gmelika commented Sep 26, 2014

I'm getting a zero

var bd = require('bigdecimal')
undefined
new bd.BigInteger("-1").compareTo(new bd.BigInteger("-1"))
0

@thatguy
Copy link
Contributor

thatguy commented Sep 27, 2014

gmelika, even though it displays as "0", it is apparently actually a -0. You will see this if you divide one by that value as Yaffle has done. Here is a JSFiddle: http://jsfiddle.net/ue0mru55/

It basically shows that

new BigInteger("-1").compareTo(new BigInteger("-1")) => 0

and

1 / new BigInteger("-1").compareTo(new BigInteger("-1")) => -Infinity

Would it be possible and reasonable to wrap the result of compareTo() in Math.abs()?

Yaffle, just for my reference, does it matter if compareTo() returns -0?

@Yaffle
Copy link
Author

Yaffle commented Sep 27, 2014

@thatguy ,

Yaffle, just for my reference, does it matter if compareTo() returns -0?

Possibly, no. Although, if we want to have some standart...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants