gpt4 book ai didi

c++ - C++ 标准为缩小从 double 到 int 的转换提供了哪些保证?

转载 作者:行者123 更新时间:2023-11-30 01:12:13 24 4
gpt4 key购买 nike

C++ 标准为缩小从 double 到 int 类型的转换提供了哪些保证?它与 Q31328190 中解释的 Java 相同吗? :

最佳答案

不,它与 Java 中的不同。如果“截断小数部分”的数学结果不能用目标类型表示,则行为未定义。

来自 4.9 [conv.fpint]/1(“浮点积分转换”):

A prvalue of a floating point type can be converted to a prvalue of an integer type. The conversion truncates; that is, the fractional part is discarded. The behavior is undefined if the truncated value cannot be represented in the destination type.

关于c++ - C++ 标准为缩小从 double 到 int 的转换提供了哪些保证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34597959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com