C语言中的undefined behavior系列(6) floating Conversion

Conversion to orfrom an integer type produces a value outside the range that can be represented(6.3.1.4).

Demotion of onereal floating type to another produces a value outside the range that can berepresented (6.3.1.5).

  如果一个浮点数转换成整数,小数部分会被丢弃。如果浮点数的整数部分越界了,那么undefined behavior

  如果一个整数转换到浮点数,没有越界但是浮点数无法精确表示这个整数,那么取最近的一个值(或高或低),这是实现相关的(implementation-definedmanner).

  如果一个整数转换到浮点数,越界了,那么undefined behavior

  浮点数与浮点数之间的转换也有类似的规则。

原文地址:https://www.cnblogs.com/aoaoblogs/p/1813982.html