-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSNumber.h
72 lines (51 loc) · 1.85 KB
/
SNumber.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
#ifndef SNUMBER_H_INCLUDED
#define SNUMBER_H_INCLUDED
#include <string>
struct SNumber
{
public:
SNumber() {}
SNumber(int value, int exp = 0);
SNumber(const std::string& input);
bool Parse(const std::string& input);
std::string ToString() const;
const std::string& GetNumsBeforePoint() const;
const std::string& GetNumsAfterPoint() const;
SNumber operator/(const SNumber& other) const;
SNumber operator*(const SNumber& other) const;
SNumber operator+(const SNumber& other) const;
SNumber operator-(const SNumber& other) const;
SNumber operator^(int power) const;
SNumber& operator+=(const SNumber& other);
SNumber& operator-=(const SNumber& other);
SNumber& operator*=(const SNumber& other);
SNumber& operator/=(const SNumber& other);
SNumber& operator^=(int power);
SNumber operator-() const;
SNumber& operator+();
SNumber& operator--();
SNumber& operator++();
SNumber operator--(int);
SNumber operator++(int);
bool IsZero() const;
bool operator==(const SNumber& other) const;
bool operator!=(const SNumber& other) const;
bool operator<(const SNumber& other) const;
bool operator>(const SNumber& other) const;
bool operator<=(const SNumber& other) const;
bool operator>=(const SNumber& other) const;
private:
std::string numBefPoint = "";
std::string numAftPoint = "";
bool negative = false;
static bool IsNumber(char c);
SNumber MultUChar(unsigned char m) const;
void Trim();
void ApplyExponent10(int exp);
SNumber Sub(const SNumber& other) const;
static void Borrow10(std::string& s, int pos);
bool EqualAbs(const SNumber& other) const;
bool LessAbs(const SNumber& other) const;
};
std::ostream& operator<<(std::ostream& os, const SNumber& num);
#endif // SNUMBER_H_INCLUDED