贴心的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. 转 cocos2d-x 优化(纹理渲染优化、资源缓存、内存优化)

    概述 包括以下5种优化:引擎底层优化.纹理优化.渲染优化.资源缓存.内存优化   引擎优化 2.0版本比1.0版本在算法上有所优化,效率更高.2.0版本使用OpenGl ES 2.0图形库,1.0版本 ...

  2. iOS - OC NSTimeZone 时区

    前言 @interface NSTimeZone : NSObject <NSCopying, NSSecureCoding> NSTimeZone 表示时区信息. 1.NSTimeZon ...

  3. [置顶] 将项目从tomcat 迁移到JBoss

    注:针对的是jboss5.0,其它版本没有测试过 ,主要参考了:http://www.diybl.com/course/3_program/java/javajs/20100719/460908.ht ...

  4. HDU 1754

    成段更新 easy #include <stdio.h> #include <string.h> #include <math.h> #include <io ...

  5. Android_Nexus4_屏幕截图

    1. 一般都是 音量-键 + 电源键,同时按一秒以上 2. 3.

  6. Linux 注意

    1. 赋值运算符= 左右之间不能加空格, 其余的都可以加空格, 而这种限制在以下情况, 可以使用空格 let "n = $1" 虽然也是赋值语句, 但是可以使用空格

  7. python中if __name__ == '__main__'

    python 中__name__ = '__main__' 的作用,到底干嘛的? 有句话经典的概括了这段代码的意义: “Make a script both importable and execut ...

  8. STM32学习笔记(一) 如何新建一个STM32工程模板

    学习stm32,第一步就是选择开发工具了,GCC,MDK,IAR每一种都有自己的优劣势,这里我选择使用MDK软件实现STM32模板.当然如果想更快的接触stm32实例,领略嵌入式开发的魅力,STM也提 ...

  9. poj2975(nim游戏取法)

    求处于必胜状态有多少种走法. if( (g[i]^ans) <= g[i]) num++; //这步判断很巧妙 // // main.cpp // poj2975 // // Created b ...

  10. ITERATOR(迭代器)设计模式

    1 意图:提供一种方法顺序访问一个聚合对象中各个元素,而又不暴露该对象的内部表示. 2 别名(Cursor) 3 动机:队列表的访问和遍历从列表对象中分离出来放入一个迭代器对象中.   多态迭代   ...