warning C4244: '=' : conversion from 'unsigned int' to 'float', possible loss of data
float 不应该能够处理来自 int 的任何值吗?
unsigned int: 0 to 4,294,967,295
float 3.4E +/- 38 (7 digits)
维基:
The advantage of floating-point representation over fixed-point (and
integer) representation is that it can support a much wider range of values.
任何见解都会有所帮助,谢谢。
http://msdn.microsoft.com/en-us/library/s3f49ktz%28VS.80%29.aspx
最佳答案
'unsigned int' 和 'float' 都使用 32 位来存储值。由于 float 的范围较大,因此必然会牺牲一些精度。这意味着有一些 unsigned int 值不能用 float 准确表示。 MSDN提供了更多详细信息。
关于c++ - 从 unsigned int 到 float 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3401722/