double int char 数据类型
生活随笔
收集整理的這篇文章主要介紹了
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
double就是IEEE754的64位浮點數
1位符號位
11位指數位
52位尾數位
即 精確到52位2進制位。
也就是說,精確到log(2^52)/log(10) = 15.6535597 位10進制位。
然后,float和double的精度是由尾數的位數來決定的。浮點數在內存中是按科學計數法來存儲的,其整數部分始終是一個隱含著的“1”,
由于它是不變的,故不能對精度造成影響。
所以,有效數字是15-16位,沒有精確到小數點后幾位之說。【大概是?T_T】
?
然后附偷來的詳細一點的:
轉載于:https://www.cnblogs.com/icode-girl/p/5371383.html
總結
以上是生活随笔為你收集整理的double int char 数据类型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求嘀嗒歌词!
- 下一篇: 2016.04.09 使用Powerde