-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBigFloat.h
48 lines (44 loc) · 2.1 KB
/
BigFloat.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
#pragma once
#include <vector>
class BigFloat {
private:
std::vector<int> integerPart, fractionalPart;
char sign;
//Must be a power of 2
static const int sizeOfFracPart = 128;
static const int base = 10;
void addToIntPart(const std::vector<int> &digits);
static void extend_vec(std::vector<int>& v, size_t len);
static std::vector<int> naive_mul(const std::vector<int>& x, const std::vector<int>& y);
static std::vector<int> karatsuba_mul(const std::vector<int>& x, const std::vector<int>& y);
static void finalize(std::vector<int>& res);
static std::vector<int> mult(std::vector<int>& x, std::vector<int>& y);
static std::vector<int> sum(const std::vector<int> &x, const std::vector<int> &y);
static std::vector<int> substract(const std::vector<int> &x, const std::vector<int> &y);
void addToFracPart(const std::vector<int> &digits);
void normalise();
static void divideByTwo(std::vector<int> &digits, bool removeZeroes);
void divideByTwo();
public:
BigFloat& inverseSign();
friend BigFloat abs(const BigFloat &x);
explicit BigFloat(const std::vector<int> &intPart, const std::vector<int> &fracPart, char sign_);
explicit BigFloat(int x);
explicit BigFloat(const char* x);
[[nodiscard]] std::string toString(size_t precision) const;
friend BigFloat operator+(const BigFloat &a, const BigFloat &b);
friend BigFloat operator-(const BigFloat &a, const BigFloat &b);
bool operator >= (const BigFloat& other) const;
bool operator < (const BigFloat& other) const;
bool operator == (const BigFloat& other) const;
bool operator <= (const BigFloat& other) const;
bool operator != (const BigFloat& other) const;
bool operator > (const BigFloat& other) const;
BigFloat& operator -();
friend BigFloat operator*(const BigFloat &a, const BigFloat &b);
friend BigFloat operator/(const BigFloat &a, const BigFloat &b);
friend std::ostream& operator << (std::ostream &in, BigFloat &x);
friend void display(const BigFloat&x, size_t precision);
explicit operator double() const;
};
BigFloat operator""_bf(const char *s);