型ごとの上限・下限
一応型ごとの大きさは規格では決まってない(最小限のビット数はあるけどこれを書いても意味がない) けど x86_64 だったら普通同じになるはず。
Type | Bits | Min | Max |
---|---|---|---|
signed char |
8 | -128 | 127 |
unsigned char |
8 | 0 | 255 |
signed short |
16 | -32768 | 32767 |
unsigned short |
16 | 0 | 65535 |
signed int |
32 | -2147483648 | 2147483647 |
unsigned int |
32 | 0 | 4294967295 |
signed long int |
64 | -9223372036854775808 | 9223372036854775807 |
unsigned long int |
64 | 0 | 18446744073709551615 |
signed long long int |
64 | -9223372036854775808 | 9223372036854775807 |
unsigned long long int |
64 | 0 | 18446744073709551615 |
コード
#include <iostream>
#include <limits>
using namespace std;
#define LIMIT(type) cout << "`" #type "` | " \
<< sizeof(type) * numeric_limits<unsigned char>::digits << " | " \
<< +numeric_limits<type>::min() << " | " \
<< +numeric_limits<type>::max() << endl;
int main() {
cout << "Type | Bits | Min | Max" << endl;
cout << "-----|------|-----|----" << endl;
LIMIT(signed char);
LIMIT(unsigned char);
LIMIT(signed short);
LIMIT(unsigned short);
LIMIT(signed int);
LIMIT(unsigned int);
LIMIT(signed long int);
LIMIT(unsigned long int);
LIMIT(signed long long int);
LIMIT(unsigned long long int);
}
浮動小数点数
10進での桁数
type | num |
---|---|
float |
6 |
double |
15 |
long double |
18 |