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

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

posted @ 2010-08-31 19:33  嗷嗷  阅读(632)  评论(0编辑  收藏  举报