• C++中的自带大数据类型:初步探究


    C++基本数据类型分为整型, 字符型, 浮点型

    bit, byte, word

    1. 1bit = 一个二进制位
    2. 1byte=8bit
    3. 1word= 8byte (对于现在的32位以上操作系统)

    浮点数测试

    float 占据 1 word

    double 占据 2 word

    long double 占据3~4 word

    经过精度测试(G++ Version 7.4.0, 编译命令 -std=c++98)

    __int128 a, b;
    void PercisionTest(){
        a = 1; b = 1;
        for(int i = 1; i <= 10; i++) {
            a = 10*a+1; b = 10*b+1;
            printf("10^%d
    ", i*2);
            write(a*b); nl;
            double a1 = a, b1 = b;
            long double a2 = a, b2 = b;
            printf("D:  %.2lf
    ", a1 * b1);
            printf("LD: %.2Lf
    ", a2 * b2);
        }
    }
    

    输出结果:

    10^14
    123456787654321
    D:  123456787654321.00
    LD: 123456787654321.00
    10^16
    12345678987654321
    D:  12345678987654320.00
    LD: 12345678987654321.00
    10^18
    1234567900987654321
    D:  1234567900987654400.00
    LD: 1234567900987654321.00
    10^20
    123456790120987654321
    D:  123456790120987656192.00
    LD: 123456790120987654320.00
    

    得出结论: long double的精度和long long 大约在同一级别.

    (当然long double 可以表示更大的数, 但是精度就会逐渐下降,最后几位会被忽略掉。)

    P.S. 如果要对两个很大的数比较大小而不是要输出精确值的话在1e30以下 long double可以

    有关 __int128

    顾名思义, __int128(in [-2^{127}, 2^{127}))
    实测 g++ -std=c++98 和 g++ -std=c++11 都是可以用的.

    要求操作系统64位以上.

    最好NOIP还是不要用了, NOILinux内核挺老的.

  • 相关阅读:
    PHP和JS判断手机还是电脑访问
    apache 一个站点配置多个域名
    拾遗
    提高工作效率的工具
    PHP urlencode
    JS encodeURI和encodeURIComponent
    Linux实践:ELF文件格式分析
    Linux实践:文件破解
    Linux实践:模块
    Linux内核学习期末总结(网课)
  • 原文地址:https://www.cnblogs.com/Eroad/p/11844320.html
Copyright © 2020-2023  润新知