-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongnum.hpp
78 lines (55 loc) · 2.28 KB
/
longnum.hpp
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
68
69
70
71
72
73
74
75
76
77
78
#ifndef LONGNUM_HPP
#define LONGNUM_HPP
#include <iostream>
#include <vector>
#include <string>
#include <cinttypes>
#include <climits>
#include <optional>
class LongNum {
bool is_negative = false;
unsigned exp = 0;
std::vector<uint32_t> limbs;
LongNum(bool _is_negative, unsigned _exp, std::vector<uint32_t>& _limbs);
void remove_leading_zeros();
public:
LongNum() = default;
LongNum(const LongNum& other) = default;
explicit LongNum(unsigned long long x);
LongNum(long long x);
~LongNum() = default;
LongNum& operator=(const LongNum& other) = default;
friend bool operator==(const LongNum& lhs, const LongNum& rhs);
friend std::strong_ordering operator<=>(const LongNum& lhs, const LongNum& rhs);
LongNum operator+() const;
LongNum operator-() const;
LongNum& operator<<=(unsigned shift);
friend LongNum operator<<(const LongNum& number, unsigned shift);
LongNum& operator>>=(unsigned shift);
friend LongNum operator>>(const LongNum& number, unsigned shift);
LongNum& operator+=(const LongNum& rhs);
friend LongNum operator+(LongNum lhs, const LongNum& rhs);
LongNum& operator-=(const LongNum& rhs);
friend LongNum operator-(LongNum lhs, const LongNum& rhs);
LongNum& operator*=(const LongNum& rhs);
friend LongNum operator*(const LongNum& lhs, const LongNum& rhs);
LongNum& operator/=(const LongNum& rhs);
friend LongNum operator/(LongNum lhs, const LongNum& rhs);
void set_precision(unsigned precision);
LongNum with_precision(unsigned precision) const;
LongNum truncate() const;
LongNum frac() const;
void shrink_to_fit();
LongNum pow(unsigned power) const;
LongNum sqrt() const;
std::string to_binary_string() const;
static LongNum from_binary_string(std::string str);
std::string to_string(unsigned decimal_precision = UINT_MAX) const;
static LongNum from_string(std::string str, const std::optional<unsigned>& precision = std::nullopt);
};
LongNum operator""_longnum(unsigned long long number);
LongNum operator""_longnum(long double number);
LongNum operator""_longnum(const char* number, std::size_t len);
std::istream& operator>>(std::istream& stream, LongNum& number);
std::ostream& operator<<(std::ostream& stream, const LongNum& number);
#endif