double int char 数据类型
生活随笔
收集整理的這篇文章主要介紹了
double int char 数据类型
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
貼心的limits...
測(cè)試代碼:
#include <iostream>
#include <stdio.h>
#include <limits>
#include <math.h>
using namespace std;int main() {//double 有效數(shù)字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;
}
運(yùn)行:
其中:關(guān)于double
double就是IEEE754的64位浮點(diǎn)數(shù)
1位符號(hào)位
11位指數(shù)位
52位尾數(shù)位
即 精確到52位2進(jìn)制位。
也就是說(shuō),精確到log(2^52)/log(10) = 15.6535597 位10進(jìn)制位。
然后,float和double的精度是由尾數(shù)的位數(shù)來(lái)決定的。浮點(diǎn)數(shù)在內(nèi)存中是按科學(xué)計(jì)數(shù)法來(lái)存儲(chǔ)的,其整數(shù)部分始終是一個(gè)隱含著的“1”,
由于它是不變的,故不能對(duì)精度造成影響。
所以,有效數(shù)字是15-16位,沒(méi)有精確到小數(shù)點(diǎn)后幾位之說(shuō)。【大概是?T_T】
?
然后附偷來(lái)的詳細(xì)一點(diǎn)的:
轉(zhuǎn)載于:https://www.cnblogs.com/icode-girl/p/5371383.html
總結(jié)
以上是生活随笔為你收集整理的double int char 数据类型的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 求嘀嗒歌词!
- 下一篇: 2016.04.09 使用Powerde