贴心的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】

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

double int char 数据类型的更多相关文章

  1. double int char long 等数据类型所占的字节数-----待整理

  2. Linux基本数据类型大小——int,char,long int,long long int

    转自:http://paddy-w.iteye.com/blog/1403217 在Linux操作系统下使用GCC进行编程,目前一般的处理器为32位字宽,下面是/usr/include/limit.h ...

  3. JAVA实体类不要使用基本类型,基本类型包含byte、int、short、long、float、double、char、boolean

    由于JAVA的基本类型会有默认值,例如当某个类中存在private  int age;字段时,创建这个类时,age会有默认值0.当使用age属性时,它总会有值.因此在某些情况下,便无法实现age为nu ...

  4. C 语言实例 - 计算 int, float, double 和 char 字节大小

    C 语言实例 - 计算 int, float, double 和 char 字节大小 C 语言实例 C 语言实例 使用 sizeof 操作符计算int, float, double 和 char四种变 ...

  5. Cstring转char、string、int等数据类型的方法(转载)

    Cstring转char.string.int等数据类型的方法 (-- ::) 转载 标签: 杂谈 分类: VC CString 转char * CString cstr; char *p = (LP ...

  6. python 调用C++ DLL,传递int,char,char*,数组和多维数组

    ctypes 数据类型和 C数据类型 对照表 ctypes type C type Python type c_bool _Bool bool (1) c_char char 1-character ...

  7. Integer 类和 int 基本数据类型的区别

    public static void main(String[] args) { Integer i = 10; Integer j = 10; System.out.println(i == j); ...

  8. C语言下double转char*或者std::string,可以精确转换不含多余的0

    char* GetDoubleStr(double value) { char buf[32]={0};//长度可以自定义 sprintf(buf,"%.8f",value);// ...

  9. 将日期或数据转换为char数据类型 TO_CHAR(x[[,c2],C3])

    TO_CHAR(x[[,c2],C3])[功能]将日期或数据转换为char数据类型[参数]x是一个date或number数据类型.c2为格式参数c3为NLS设置参数如果x为日期nlsparm=NLS_ ...

随机推荐

  1. NYOJ 93 汉诺塔(三)

    汉诺塔(三) 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 在印度,有这么一个古老的传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度 ...

  2. windows git的安装配置(转)

    Win7上Git安装及配置过程 http://www.cnblogs.com/sunny5156/archive/2012/10/23/2735799.html   对于需要使用Putty登录的参见 ...

  3. iOS - Swift NSRect 位置和尺寸

    前言 结构体,这个结构体用来表示事物的坐标点和宽高度. public typealias NSRect = CGRect public struct CGRect { public var origi ...

  4. Android 可拖动列表项的ListView

    需求分析 一个界面内两个ListView 我关注的栏目列表 上面的要长按后可拖动排序 点击减号后列表项消失 下面列表增加一行 同时存储相应字符串到本地作为标记 未关注栏目列表 普通ListView 点 ...

  5. js 高程(三)学习感言(随时更新)

    1.读第二遍了,感觉第一遍白读了. 2.现在还处于初学...

  6. 转!大端模式&小端模式

    大端模式&小端模式   在C语言中除了8位的char型之外,还有16位的short型,32位的long型(要看具体的编译器),对于位数大于8位的处理器,例如16位或者32位的处理器,由于寄存器 ...

  7. commonJS — 函数操作(for Function)

    for Function github: https://github.com/laixiangran/commonJS/blob/master/src/forFunction.js 代码 /** * ...

  8. fetchField 和 fetchColumn

    public function fetchField($index = 0) { // Call PDOStatement::fetchColumn to fetch the field. retur ...

  9. 在腾讯云上创建您的SQL Cluster(1)

    版权声明:本文由李斯达原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/247 来源:腾云阁 https://www.qclo ...

  10. linux笔记:RPM软件包管理-rpm命令管理

    rpm包命名原则: rpm包的依赖性: 包名和包全名: rpm软件包安装.升级和卸载: rpm软件包查询: 从rpm包中提取指定文件: