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

后端 未结 10 723
离开以前
离开以前 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:20

    this float1 == 0.0f is never really a safe comparison.

    if you have something like

    float x = 0.0f;
    for (int i = 0; i < 10; i++) x += 0.1f;
    x -= 1.0f;
    assert (x == 0.0f);
    

    it will fail even though it is seemingly supposed to be 0.

提交回复
热议问题