Is casting of infinity to integer undefined?

前端 未结 3 1774
日久生厌
日久生厌 2021-01-17 07:18

Is the casting of infinity (represented by float) to an integer an undefined behavior?

The standard says:

4.10 Floating-integral conversions<

3条回答
  •  Happy的楠姐
    2021-01-17 07:58

    Casting of infinity to integer is undefined.

    The behavior is undefined if the truncated value cannot be represented in the destination type.

    Says it all. Since truncation removes precision but not magnitude, a truncated infinity is still infinity and integers cannot represent infinity.

提交回复
热议问题