C语言:float表示范围

您所在的位置:网站首页 c语言float数据范围 C语言:float表示范围

C语言:float表示范围

2023-06-01 16:52| 来源: 网络整理| 查看: 265

#include #include //整数限制 #include //浮点数限制 void main() { printf("the FLOAT_MIN number is : %f\n",FLT_MIN); //float的最小值 printf("the FLOAT_MAX number is : %f\n",FLT_MAX); //float的最大值 printf("the FLOAT_MAX number is : %e\n",FLT_MAX); //float的最大值 getchar(); }

#include #include //整数限制 #include //浮点数限制 void main() { printf("the FLOAT_MIN number is : %f\n",FLT_MIN); //float的最小值 printf("the FLOAT_MAX number is : %f\n",FLT_MAX); //float的最大值 printf("the FLOAT_MAX number is : %e\n",FLT_MAX); //float的最大值 printf("the INT_MAX number is : %d\n",INT_MAX); printf("the INT_MIN number is : %d\n",INT_MIN); printf("the CHAR_MAX number is : %d\n",CHAR_MAX); printf("the CHAR_MIN number is : %d\n",CHAR_MIN); printf("the SHORT_MAX number is : %d\n",SHRT_MAX); printf("the SHORT_MIN number is : %d\n",SHRT_MIN); printf("the LONG_MAX number is : %d\n",LONG_MAX); printf("the LONG_MIN number is : %d\n",LONG_MIN); printf("the DOUBLE_MAX number is : %d\n",DBL_MAX); printf("the DOUBLE_MIN number is : %d\n",DBL_MIN); getchar(); }

 float:

  1bit(符号位) 8bits(指数位) 23bits(尾数位)double:  1bit(符号位) 11bits(指数位) 52bits(尾数位)

于是,float的指数范围为-127~+128,而double的指数范围为-1023~+1024,并且指数位是按补码的形式来划分的。  其中负指数决定了浮点数所能表达的绝对值最小的非零数;而正指数决定了浮点数所能表达的绝对值最大的数,也即决定了浮点数的取值范围。  float的范围为-2^128 ~ +2^128,也即-3.40E+38 ~ +3.40E+38;double的范围为-2^1024 ~ +2^1024,也即-1.79E+308 ~ +1.79E+308。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3