Is there a signed zero Integer in Java?

后端 未结 1 1500
逝去的感伤
逝去的感伤 2021-01-21 09:58

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\"         


        
相关标签:
1条回答
  • 2021-01-21 10:28

    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.

    0 讨论(0)
提交回复
热议问题