Is floating point multiplication by zero guaranteed to produce zero?

前端 未结 2 1203
天命终不由人
天命终不由人 2021-01-01 17:10

I understand floating point has rounding errors, but I\'m wondering if there are certain situations where the error does not apply, such as multiplication by zero .

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 17:40

    False:

    0f * NAN == NAN
    0f * INFINITY == NAN
    

    and ...

    0f * -1f == -0f (negative 0f), with 0f == -0f :-)
    

    (on Intel, VC++, and probably on any platform that uses IEEE 754-1985 floating points)

    Example on ideone (that uses GCC on some Intel compatible platform probably)

提交回复
热议问题