use*_*214 12 c++ implicit-conversion
这是令人惊讶,我看到,即使值可以转换,一个int浮动转换始终给予警告.为什么是这样?
int i = 0;
float f = 0; // warning here
// I thought this was an implicit conversion,
// meaning it is convertible with no warnings.
f = i; // another warning here
Run Code Online (Sandbox Code Playgroud)
警告是:
warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
Run Code Online (Sandbox Code Playgroud)
我在这里回答了类似的问题:
原因是当int将 an 转换为 a 时需要进行舍入,float因为在这种情况下float不能包含 an 的所有精度int。
在你的例子中, afloat只有大约 24 位精度。因此,虽然 anint具有 32 位精度,但此转换会损失一些精度,因此会出现警告。
| 归档时间: |
|
| 查看次数: |
18376 次 |
| 最近记录: |