关于数值极限
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include <limits> #include <iostream>
int main() { std::cout << "type\t\t\tlowest()\t\tmin()\t\t\tmax()\n\n";
std::cout << "short\t\t\t" << std::numeric_limits<short>::lowest() << "\t\t\t" << std::numeric_limits<short>::min() << "\t\t\t" << std::numeric_limits<short>::max() << "\n"; std::cout << "int\t\t\t" << std::numeric_limits<int>::lowest() << "\t\t" << std::numeric_limits<int>::min() << "\t\t" << std::numeric_limits<int>::max() << "\n"; std::cout << "long\t\t\t" << std::numeric_limits<long>::lowest() << "\t\t" << std::numeric_limits<long>::min() << "\t\t" << std::numeric_limits<long>::max() << "\n"; std::cout << "long long\t\t" << std::numeric_limits<long long>::lowest() << "\t" << std::numeric_limits<long long>::min() << "\t" << std::numeric_limits<long long>::max() << "\n"; std::cout << "unsigned short\t\t" << std::numeric_limits<unsigned short>::lowest() << "\t\t\t" << std::numeric_limits<unsigned short>::min() << "\t\t\t" << std::numeric_limits<unsigned short>::max() << "\n"; std::cout << "unsigned int\t\t" << std::numeric_limits<unsigned int>::lowest() << "\t\t\t" << std::numeric_limits<unsigned int>::min() << "\t\t\t" << std::numeric_limits<unsigned int>::max() << "\n"; std::cout << "unsigned long\t\t" << std::numeric_limits<unsigned long>::lowest() << "\t\t\t" << std::numeric_limits<unsigned long>::min() << "\t\t\t" << std::numeric_limits<unsigned long>::max() << "\n"; std::cout << "unsigned long long\t" << std::numeric_limits<unsigned long long>::lowest() << "\t\t\t" << std::numeric_limits<unsigned long long>::min() << "\t\t\t" << std::numeric_limits<unsigned long long>::max() << "\n";
system("pause"); }
|
64 位
在64位系统上Visual Studio 输出结果:
换为2的幂级数表示为(64位系统下):
type |
lowest() |
min() |
max() |
short |
-32768 |
-32768 |
32767 |
int |
-2147483648 |
-2147483648 |
2147483647 |
long |
-2147483648 |
-2147483648 |
2147483647 |
long long |
-9223372036854775808 |
-9223372036854775808 |
9223372036854775807 |
unsigned short |
0 |
0 |
65535 |
unsigned int |
0 |
0 |
4294967295 |
unsigned long |
0 |
0 |
4294967295 |
unsigned long long |
0 |
0 |
18446744073709551615 |
32 位
在32位系统上Visual Studio 输出结果:
type |
lowest() |
min() |
max() |
short |
-32768 |
-32768 |
32767 |
int |
-2147483648 |
-2147483648 |
2147483647 |
long |
-2147483648 |
-2147483648 |
2147483647 |
long long |
-9223372036854775808 |
-9223372036854775808 |
9223372036854775807 |
unsigned short |
0 |
0 |
65535 |
unsigned int |
0 |
0 |
4294967295 |
unsigned long |
0 |
0 |
4294967295 |
unsigned long long |
0 |
0 |
18446744073709551615 |