最多可以容纳多少个浮点类型? [英] what's the largest number float type can hold?
问题描述
我是编程的新手,最近又提出了这个简单的问题.浮点型有32位,其中8位是整数部分(尾数).所以我的问题是浮点型可以容纳大于255.9999的数字吗?
I'm new to programming and have recently come up with this simple question . float type has 32 bits in which 8 bits are for the whole number part (the mantissa). so my question is can float type hold numbers bigger than 255.9999 ?
如果有人告诉我为什么这段代码的行为异常,我也将不胜感激.是相关问题吗?
and I would also appreciate if someone told me why this code is behaving unexpectedly. Is it a related issue?
int main(){
float a=123456789.1;
printf("%lf",a);
return 0;
}
输出为:
123456792.000000
推荐答案
code>< float.h> -浮点类型的数字限制有您的答案,特别是...
<float.h>
-- Numeric limits of floating point types has your answers, specifically...
- FLT_MAX
- DBL_MAX
- LDBL_MAX
float , double
和 long double
的最大极限值
maximum finite value of float
, double
and long double
respectively
...和...
- FLT_DIG
- DBL_DIG
- LDBL_DIG
保证保留在文本中的小数位数-> float
/ double
/ long double
->文本往返由于舍入或溢出
number of decimal digits that are guaranteed to be preserved in text -> float
/double
/long double
-> text roundtrip without change due to rounding or overflow
最后一部分的意思是,不再保证 float
的值(即更高的有效数字)比 FLT_DIG
更长的值.
That last part is meant to say that a float
value longer (i.e. more significant digits) than FLT_DIG
is no longer guaranteed to be precisely representable.
这篇关于最多可以容纳多少个浮点类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!