climits头文件

来源:互联网 发布:死性不改网络歌手歌词 编辑:程序博客网 时间:2024/06/05 19:24


本代码只是输出各整型数据表示的范围大小,不涉及浮点数。


虽然也用特例测试了一下浮点数的精度,大致为 16位:

float ~ 6、7位

double ~ 15、16位。。查了下网上的说法,推荐看这个链接吧。


#include <iostream>#include <climits>#include <iomanip>using namespace std;template <typename T>int PowOfMax( T t ){    int n=0;    while( t >= 10 ){        n++;        t /= 10;    }    return n;}int main(){    cout << "每个字符包含的位的个数:\t" <<"1 Byte = " <<CHAR_BIT <<"Bits" << endl << endl;// 1字 = 2字节(1 word = 2 byte) , 1字节 = 8位 (1 byte = 8bit) , bps 是 bits per second//一个字的字长为16 , 一个字节的字长是8    cout << "Min Char =\t"<<CHAR_MIN << endl;    cout << "Max Char =\t"<<CHAR_MAX << endl;    cout << "Char 字符整型 科学计数法的极致位数是:\t"<<PowOfMax( CHAR_MAX )<<endl;    cout << "Max Unsigned Char =\t"<<UCHAR_MAX << endl << endl;    cout << "Min Short =\t"<<SHRT_MIN << endl;    cout << "Max Short =\t"<<SHRT_MAX << endl;    cout << "Short 短整型 科学计数法的极致位数是:\t"<<PowOfMax( SHRT_MAX )<<endl;    cout << "Max Unsigned Short =\t"<<USHRT_MAX << endl << endl;    cout << "Min Int =\t"<<INT_MIN << endl;    cout << "Max Int =\t"<<INT_MAX << endl;    cout << "Int 整型 科学计数法的极致位数是:\t"<<PowOfMax( INT_MAX )<<endl;    cout << "Max Unsigned Int =\t"<<UINT_MAX << endl << endl;    cout << "Min Long =\t"<<LONG_MIN << endl;    cout << "Max Long =\t"<<LONG_MAX << endl;    cout << "Long 长整型 科学计数法的极致位数是:\t"<<PowOfMax( LONG_MAX )<<endl;    cout << "Max Unsigned Long =\t"<<ULONG_MAX << endl << endl;    cout << "Min Long Long =\t"<<LONG_LONG_MIN << endl;    cout << "Max Long Long =\t"<<LONG_LONG_MAX << endl;    cout << "LongLong 超长整型 科学计数法的极致位数是:\t"<<PowOfMax( LONG_LONG_MAX )<<endl;    cout << "Max Unsigned Long Long =\t"<<ULONG_LONG_MAX << endl << endl;    float f = 1.12345678912345678912345; //总共25个字符    cout <<"float f =\t"<< setprecision(25) << f << endl;    double d = 1.12345678912345678912345;    cout <<"double d =\t"<< setprecision(25) << d << endl;    long double ld = 1.12345678912345678912345;    cout <<"long double ld =\t"<< setprecision(25) << ld <<endl;    return 0;}

自己代码运行的操作系统环境是学校的32位机器:

(CodeBlocks上执行的)





运行结果是:




0 0
原创粉丝点击