Does float have a negative zero? (-0f)

后端 未结 10 738
离开以前
离开以前 2020-11-28 09:36

IEEE floating point numbers have a bit assigned to indicate the sign, which means you can technically have different binary representations of zero (+0 and -0). Is there an

10条回答
  •  生来不讨喜
    2020-11-28 10:28

    Yes, floats have negative zero just like other IEEE floating point types such as double (on systems with IEEE floating point). There is an example here in Octave of how to create them; the same operations work in C. The == operator treats +0 and -0 the same, though, and so negative zeros do not break that type of comparison.

提交回复
热议问题