-
Notifications
You must be signed in to change notification settings - Fork 0
/
int128.h
67 lines (39 loc) · 1.73 KB
/
int128.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#include <cstdint>
#include <string_view>
#include <ostream>
struct Int128 {
public:
Int128() noexcept;
Int128(int64_t) noexcept;
Int128(std::string_view) noexcept;
explicit operator int64_t() const noexcept;
explicit operator double() const noexcept;
std::string str() const;
friend Int128 operator-(const Int128 &a) noexcept;
friend Int128 operator+(const Int128 &lhs, const Int128 &rhs) noexcept;
friend Int128 operator-(const Int128 &lhs, const Int128 &rhs) noexcept;
friend Int128 operator*(const Int128 &lhs, const Int128 &rhs) noexcept;
friend Int128 operator/(const Int128 &lhs, const Int128 &rhs) noexcept;
Int128 &operator+=(const Int128 &rhs) noexcept;
Int128 &operator-=(const Int128 &rhs) noexcept;
Int128 &operator*=(Int128 rhs) noexcept;
Int128 &operator/=(Int128 rhs) noexcept;
Int128 operator<<(int) const noexcept;
Int128 operator>>(int) const noexcept;
friend bool operator<(const Int128 &lhs, const Int128 &rhs) noexcept;
friend bool operator>(const Int128 &lhs, const Int128 &rhs) noexcept;
friend bool operator<=(const Int128 &lhs, const Int128 &rhs) noexcept;
friend bool operator>=(const Int128 &lhs, const Int128 &rhs) noexcept;
friend bool operator==(const Int128 &lhs, const Int128 &rhs) noexcept;
friend bool operator!=(const Int128 &lhs, const Int128 &rhs) noexcept;
friend std::ostream &operator<<(std::ostream &, const Int128 &);
void print() const;
private:
friend int cmp(const Int128 &lhs, const Int128 &rhs);
friend int cmpAbs(const Int128 &lhs, const Int128 &rhs);
uint64_t high, low;
explicit Int128(uint64_t, uint64_t) noexcept;
Int128 &negate() noexcept;
bool isNegative() const noexcept;
};