gpt4 book ai didi

c++我可以用double初始化一个float类型的变量吗?

转载 作者:行者123 更新时间:2023-11-30 01:41:49 33 4
gpt4 key购买 nike

还没有真正能够找到很多关于这个的信息。虽然当我用 double 初始化类型为 float 的变量时编译器似乎没有提示,例如

double a = 1.0;
float b = a;

它工作正常,但我仍然很好奇这样做是否可以,和/或是否安全?

(我在运行 windows 的 32 位系统上)

最佳答案

4.8 Floating point conversions

1 A prvalue of floating point type can be converted to a prvalue of another floating point type. If thesource value can be exactly represented in the destination type, the result of the conversion is that exactrepresentation. If the source value is between two adjacent destination values, the result of the conversionis an implementation-defined choice of either of those values. Otherwise, the behavior is undefined.

关于c++我可以用double初始化一个float类型的变量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40792246/

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