-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathint128.cpp
51 lines (44 loc) · 815 Bytes
/
int128.cpp
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
44
45
46
47
48
49
50
51
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <unordered_set>
#include <vector>
#include <queue>
using namespace std;
#ifdef __GNUC__
#define int128_t __int128
#else
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::int128_t int128_t;
#endif
std::ostream& operator<<(std::ostream& dest, int128_t &x) {
string s;
if (x == 0) {
s = "0";
} else {
if (x < 0) {
cout << "-";
x = -x;
}
while (x > 0) {
s += char('0' + x % 10);
x /= 10;
}
}
reverse(s.begin(), s.end());
dest << s;
return dest;
}
int main(int argc, char* argv[]) {
int128_t x = 1;
x <<= 100;
cout << x << endl; // 1267650600228229401496703205376
x = -1000;
cout << x << endl;
x = 0;
cout << x << endl;
return 0;
}