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。
浮点数与浮点数之间的转换也有类似的规则。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步