-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber.cpp
More file actions
153 lines (136 loc) · 3.7 KB
/
number.cpp
File metadata and controls
153 lines (136 loc) · 3.7 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "number.hpp"
namespace number{
base operator+(base n1 , base n2){
base tampon("tampon", n1.value + n2.value);
return tampon;
}
base operator*(base n1 , base n2){
base tampon("tampon", n1.value * n2.value);
return tampon;
}
base operator/(base n1 , base n2){
base tampon("tampon", n1.value / n2.value);
return tampon;
}
base operator-(base n1 , base n2){
base tampon("tampon", n1.value - n2.value);
return tampon;
}
std::string base::get_name(void){
return name;
}
void base::read_only(){
isConst = true;
}
bool base::is_const(){
return isConst;
}
base& base::operator= (const base & l1){
if (this != &l1){
this->value = l1.value;
}
return *this;
}
bool operator==(base n1, base n2){
return n1.value == n2.value;
}
base null("null");
bool base::is_null(){
return this->value == 0;
}
bool base::cmp(const char * ref){
return name.compare(ref);
}
bool base::cmp(std::string ref){
return name.compare(ref.c_str());
}
base::base(std::string nom ,mpf_class v)
{
value = v;
name = nom;
isConst = false;
}
base::base(const char * n,mpf_class v){
value = v;
name.clear();
name.append(n);
isConst = false;
}
base::base(std::string nom)
{
name = nom;
value = 0;
isConst = false;
}
mpf_class base::get(){
return value;
}
void base::set(mpf_class v){
value = v;
}
bool testdigite(const char * num){
bool isNum = true;
size_t l = strlen(num), i = 0;
while( i < l){
if(! isdigit(num[i])){
isNum = false;
break;
}
i++;
}
return isNum;
}
int NumbersGestion::new_number(std::string id, std::string value){
return new_number(id.c_str(),value.c_str());
};
int NumbersGestion::new_number(const char * id, const char * value){
if(!number::testdigite(value)){
return -1;
};
mpf_class n(value);
std::string name(id);
number::base b(name, n);
num.push_back(b);
return 1;
};
base NumbersGestion::get(const char * n){
std::vector <base>::iterator il;
for(il = num.begin(); il != num.end(); il++){
if( (*il).cmp(n) == EQUAL){
return *il;
};
};
return null;
};
base NumbersGestion::set(const char * n, mpf_class v){
std::vector <base>::iterator il;
for(il = num.begin(); il != num.end(); il++){
if( (*il).cmp(n) == EQUAL){
(*il).set(v);
return (*il);
}
}
return null;
}
base NumbersGestion::set(const char * n, const char * val){
mpf_class v(val);
return this->set(n,v);
}
int NumbersGestion::del(const char * n){
std::vector <base>::iterator il;
for(il = num.begin(); il != num.end(); il++){
if( (*il).cmp(n) == EQUAL){
num.erase(il);
return 0;
}
}
return 0;
}
NumbersGestion:: NumbersGestion(/* args */)
{
}
std::string base::c_str(){
mp_exp_t e = 10;
return value.get_str(e);
}
}