warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
2014-04-04 09:27
441 查看
在32位平台上,通常int是4字节长度,最多表示到21亿多,而int型是“绝对精确”的,换句话说,就是int行最多可以保证10位十进制有效数字的精确度。
而float只能保证6位有效数字的精确度,因此int到float的转换是可能丢失精度的,比如整数“1234567899”转换成float后,大约是:1.23457936乘10的9次方,也就是从第7位有效数字开始已经不准确了。
double可以保证15位10进制有效数字的精度,所以从int到double不会有这个警告。
在32位平台上,通常int和float都是4字节的,那既然字节数一样,凭什么int只能表示到21亿,而float可以表示到10的38次方?答案就是float跟int相比,牺牲了精确度,换来了更大的表示范围。
而float只能保证6位有效数字的精确度,因此int到float的转换是可能丢失精度的,比如整数“1234567899”转换成float后,大约是:1.23457936乘10的9次方,也就是从第7位有效数字开始已经不准确了。
double可以保证15位10进制有效数字的精度,所以从int到double不会有这个警告。
在32位平台上,通常int和float都是4字节的,那既然字节数一样,凭什么int只能表示到21亿,而float可以表示到10的38次方?答案就是float跟int相比,牺牲了精确度,换来了更大的表示范围。
相关文章推荐
- warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
- vs2005 warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
- How to eliminate the compile error "conversion from 'double ' to 'float ', possible loss of data"
- vs2005 warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
- How to get rid of `deprecated conversion from string constant to 'char*'` warnings in GCC?
- gcc编译错误(invalid conversion from 'int' to enum)
- Implicit conversion of 'int' to 'id' is disallowed with ARC
- vs2005 warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
- vs2005 warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
- error C2664: 'cvSetMouseCallback' : cannot convert parameter 2 from 'void (__cdecl *)(int,int,int,int)' to 'CvMouseCallback' 的解决
- Implicit conversion loses integer precision: 'unsigned long' to 'CC_LONG' (aka 'unsigned int').
- [C/C++]warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
- Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB
- spring Failed to convert property value of type 'java.lang.String' to required type 'int' for proper
- invalid conversion from 'const char*' to 'UCHAR*'解决方法
- Cast from pointer to smaller type 'int' loses
- warning:deprecated conversion from string constant to 'char *'
- cast from 'void *' to 'int' loses precision
- implicit conversion loses integer precision :'long' to 'int'
- error:error C2664: 'calc' : cannot convert parameter 2 from 'int' to 'int []' Conversion fro