Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a signed zero Integer in Java?

I've learned that floating point number s have a signed zero in java. But I'm afraid Integer has not:

new Integer("0").equals(new Integer("-0")) // true

vs.

new Double("0").equals(new Double("-0")) // false

How could I store a sign with my zero Integer value?

like image 929
Sebastian Avatar asked May 07 '26 14:05

Sebastian


1 Answers

You cannot store a sign with Java integer primitive type.

Negative zero is an artifact of IEEE-754 representation, which stores a sign in a separate bit. Integers, on the other hand, are stored in two's complement representation, which has a unique representation for zero.

like image 61
Sergey Kalinichenko Avatar answered May 09 '26 03:05

Sergey Kalinichenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!