c++ - 从 unsigned int 到 float 的转换

标签 c++ windows variables types

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/

相关文章:

c++ - 如何在使用 tesseract 时禁用/排除不需要的操作?

c++ - 是否有必要在 Qt 中删除对话框窗口指针?

c++ - 我如何使用多维数组存储多个元素,然后检索元素

c++ - 有没有办法获取在处理信号期间访问的指针?

C# 类变量问题

c++ - 如果我输入字母而不是数字,为什么会出现无限循环?

windows - "npm faq"在 Windows 7 上失败("spawn ENOENT"错误)

string - 调试检查器显示奇怪的字符?

php - 如何在 PHP 中将两个字符串组合在一起?

swift - 在变量中快速创建对象/实例