-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigInteger.h
83 lines (63 loc) · 2.27 KB
/
BigInteger.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Created by Павел Пономарев on 07.03.2018.
//
#ifndef BIGINTEGER_H
#define BIGINTEGER_H
#include <iostream>
#include <string>
#include <vector>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <cmath>
template<typename T, size_t Base = std::numeric_limits<T>::max()>
class BigInteger;
template<typename T, size_t Base>
std::ostream & operator <<(std::ostream &, const BigInteger<T, Base> &);
template<typename T, size_t Base>
std::istream & operator >>(std::istream &, BigInteger<T, Base> &);
template<typename T, size_t Base>
class BigInteger {
friend std::ostream & operator << <>(std::ostream &, const BigInteger<T, Base> &);
friend std::istream & operator >> <>(std::istream &, BigInteger<T, Base> &);
template<typename T1, size_t Base1> friend class BigInteger;
public:
explicit BigInteger(long long number = 0);
explicit BigInteger(std::string argument);
template<typename digitT>
explicit BigInteger(std::vector<digitT> bigDigits);
template<typename NewT, size_t NewBase>
explicit operator BigInteger<NewT, NewBase>() const;
BigInteger(const BigInteger &);
BigInteger(BigInteger &&);
BigInteger& operator =(const BigInteger &);
BigInteger & operator +=(const BigInteger &);
BigInteger operator +(const BigInteger &) const;
BigInteger & operator *=(const BigInteger &);
BigInteger operator *(const BigInteger &) const;
BigInteger & operator -=(const BigInteger &);
BigInteger operator -(const BigInteger &) const;
BigInteger operator -() const;
bool operator<(const BigInteger &) const;
bool operator>(const BigInteger &) const;
bool operator<=(const BigInteger &) const;
bool operator>=(const BigInteger &) const;
bool operator==(const BigInteger &) const;
bool operator!=(const BigInteger &) const;
T operator[](size_t i) const;
size_t size() const;
BigInteger abs() const;
bool isNegative() const;
void setSign(bool negative = true);
bool isZero() const;
private:
void trimZeros();
void trim();
void setDigit(size_t pos, T digit);
constexpr static int digitsInType();
constexpr static int bitsUsedForOneDigit();
std::vector<T> number;
size_t sizeOfNumber;
bool negativeSign;
};
#endif // BIGINTEGER_H