-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigInt.h
More file actions
91 lines (80 loc) · 1.86 KB
/
BigInt.h
File metadata and controls
91 lines (80 loc) · 1.86 KB
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
84
85
86
87
88
89
90
91
#pragma once
#include <iostream>
#include <string> //getline
#include <vector>
#include <cmath>
using namespace std;
class BigInt {
private:
int type; //0:Integer 1:Decimal 2:operator
bool sign; //0:+ 1:-
string name;
string digits;
int dotPlace;
public:
static vector<BigInt> All; //存所有變數
BigInt() { name = ""; };
BigInt(string n) { name = n; };
BigInt(bool, string, string);//type, name, digits
void setType(int _type) { type = _type; }
void setSign(bool _sign) { sign = _sign; }
void setDigits(string _digits) { digits = _digits; }
void setDotPlace(int _dotPlace) { dotPlace = _dotPlace; }
void setName(string _name)
{
//清除空格
int i = 0;
while (_name[i] == ' ')
i++;
_name.erase(0, i);
i = _name.length() - 1;
while (_name[i] == ' ')
i--;
_name.erase(i + 1, _name.length() - 1);
name = _name;
}
int getType() { return type; }
bool getSign() { return sign; }
string getDigits() { return digits; }
int getDotPlace() { return dotPlace; }
string getName() { return name; }
void checkType()
{
dotPlace = digits.find('.');
if (type == 0)
{
if (dotPlace != string::npos)
{
digits.erase(dotPlace);
dotPlace = -1;
}
}
else
{
if (dotPlace == string::npos)
{
dotPlace = digits.length();
digits += '.';
}
if (digits.length() - dotPlace - 1 < 100)//小數部分不足100位
{
//補到100位數
for (int i = digits.length() - dotPlace - 1; i < 100; i++)
digits += '0';
}
else
{
digits.erase(dotPlace + 101);
}
}
}
friend BigInt process(string);
BigInt operator+(BigInt) const;
BigInt operator-(BigInt) const;
BigInt operator*(BigInt) const;
BigInt operator/(BigInt) const;
BigInt operator^(BigInt) const;
void operator=(const BigInt&);
int compare(string) const; //回傳: -1:< 0:== 1:>
friend ostream& operator<<(ostream&, const BigInt&);
};