double int char 数据类型

时间:2023-03-09 18:04:51
double int char 数据类型

贴心的limits...

测试代码:

#include <iostream>
#include <stdio.h>
#include <limits>
#include <math.h>
using namespace std; int main() {
//double 有效数字16位
double test3 = 1.2345678912345678e17;
printf("%.17lf\n", test3); test3 = 1.23456789123456789123e17;
printf("%.17lf\n", test3); int a = (int)pow(2, 32);
cout << "int 2^32: " << a << "===\n"; int b = (int)pow(2, 64);
cout << "long long to int: " << b << "===\n"; long long c = (long long)pow(2, 64);
cout << "long long 2^64: " << c << "===\n"; cout << "type\t---" << "+++++++++++++++size+++++++++++++++\n";
cout << "bool\t---" << "size:" << sizeof(bool) << "\tmax:" << (numeric_limits<bool>::max()) << "\t\tmin:" << numeric_limits<bool>::min() << endl;
cout << "int\t---" << "size:" << sizeof(int) << "\tmax:" << (numeric_limits<int>::max()) << "\t\tmin:" << numeric_limits<int>::min() << endl;
cout << "long long---" << "size:" << sizeof(long long) << "\tmax:" << (numeric_limits<long long>::max()) << "\t\tmin:" << numeric_limits<long long>::min() << endl;
cout << "double\t---" << "size:" << sizeof(double) << "\tmax:" << (numeric_limits<double>::max()) << "\t\tmin:" << numeric_limits<double>::min() << endl;
cout << "long\t---" << "size:" << sizeof(long) << "\tmax:" << (numeric_limits<long>::max()) << "\t\tmin:" << numeric_limits<long>::min() << endl;
}

运行:

double int char 数据类型

其中:关于double

double就是IEEE754的64位浮点数
1位符号位
11位指数位
52位尾数位

即 精确到52位2进制位。
也就是说,精确到log(2^52)/log(10) = 15.6535597 位10进制位。

然后,float和double的精度是由尾数的位数来决定的。浮点数在内存中是按科学计数法来存储的,其整数部分始终是一个隐含着的“1”,

由于它是不变的,故不能对精度造成影响。

所以,有效数字是15-16位,没有精确到小数点后几位之说。【大概是?T_T】

然后附偷来的详细一点的:

double int char 数据类型