-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpdecpp.hpp
248 lines (203 loc) · 6.55 KB
/
mpdecpp.hpp
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#ifndef MPDECPP_HPP
#define MPDECPP_HPP
#include <memory>
#include <string>
#include <iostream>
#include <mpdecimal.h>
namespace mpdecpp
{
void set_context(std::shared_ptr<mpd_context_t> new_context);
std::shared_ptr<mpd_context_t> get_context() noexcept;
std::shared_ptr<mpd_context_t> get_context_ctor() noexcept;
std::shared_ptr<mpd_context_t> DefaultContext();
std::shared_ptr<mpd_context_t> BasicContext();
std::shared_ptr<mpd_context_t> MaxContext();
std::shared_ptr<mpd_context_t> IEEEContext(int);
//a local context manager
class mpd_localcontext {
private:
std::shared_ptr<mpd_context_t> saved_context;
public:
mpd_localcontext(std::shared_ptr<mpd_context_t>);
~mpd_localcontext();
mpd_localcontext(const mpd_localcontext&) = delete; //no copies
mpd_localcontext(const mpd_localcontext&&) = delete; //no moves
};
class mpd_c {
public:
mutable mpd_t *number;
//constructors
mpd_c(int32_t, std::shared_ptr<mpd_context_t>) noexcept;
mpd_c(int64_t, std::shared_ptr<mpd_context_t>) noexcept;
mpd_c(uint32_t, std::shared_ptr<mpd_context_t>) noexcept;
mpd_c(uint64_t, std::shared_ptr<mpd_context_t>) noexcept;
mpd_c(std::string, std::shared_ptr<mpd_context_t>) noexcept;
mpd_c(const char*, std::shared_ptr<mpd_context_t>) noexcept;
mpd_c(int32_t value) noexcept;
mpd_c(int64_t value) noexcept;
mpd_c(uint32_t value) noexcept;
mpd_c(uint64_t value) noexcept;
mpd_c(std::string value) noexcept;
mpd_c(const char* value) noexcept;
mpd_c(std::shared_ptr<mpd_context_t>) noexcept;
mpd_c() noexcept;
mpd_c(const mpd_c&) noexcept;
mpd_c(mpd_c&&) noexcept;
mpd_c& operator=(mpd_c other) noexcept;
friend void swap(mpd_c&, mpd_c&) noexcept;
//destructor
~mpd_c();
//addition overloads
// mpd_c& operator+=(const mpd_ssize_t &rhs); //is i64...
const mpd_c operator+() const;
mpd_c& operator++();
const mpd_c operator++(int) const;
mpd_c& operator+=(const mpd_c &rhs);
mpd_c& operator+=(const int32_t &rhs);
mpd_c& operator+=(const int64_t &rhs);
mpd_c& operator+=(const uint32_t &rhs);
mpd_c& operator+=(const uint64_t &rhs);
const mpd_c operator+(const mpd_c &other) const;
const mpd_c operator+(const int32_t &other) const;
const mpd_c operator+(const int64_t &other) const;
const mpd_c operator+(const uint32_t &other) const;
const mpd_c operator+(const uint64_t &other) const;
//subtraction overloads
const mpd_c operator-() const;
mpd_c& operator--();
const mpd_c operator--(int) const;
mpd_c& operator-=(const mpd_c &rhs);
mpd_c& operator-=(const int32_t &rhs);
mpd_c& operator-=(const int64_t &rhs);
mpd_c& operator-=(const uint32_t &rhs);
mpd_c& operator-=(const uint64_t &rhs);
const mpd_c operator-(const mpd_c &other) const;
const mpd_c operator-(const int32_t &other) const;
const mpd_c operator-(const int64_t &other) const;
const mpd_c operator-(const uint32_t &other) const;
const mpd_c operator-(const uint64_t &other) const;
//multiplication overloads
mpd_c& operator*=(const mpd_c &rhs);
mpd_c& operator*=(const int32_t &rhs);
mpd_c& operator*=(const int64_t &rhs);
mpd_c& operator*=(const uint32_t &rhs);
mpd_c& operator*=(const uint64_t &rhs);
const mpd_c operator*(const mpd_c &other) const;
const mpd_c operator*(const int32_t &other) const;
const mpd_c operator*(const int64_t &other) const;
const mpd_c operator*(const uint32_t &other) const;
const mpd_c operator*(const uint64_t &other) const;
//division overloads
mpd_c& operator/=(const mpd_c &rhs);
mpd_c& operator/=(const int32_t &rhs);
mpd_c& operator/=(const int64_t &rhs);
mpd_c& operator/=(const uint32_t &rhs);
mpd_c& operator/=(const uint64_t &rhs);
const mpd_c operator/(const mpd_c &other) const;
const mpd_c operator/(const int32_t &other) const;
const mpd_c operator/(const int64_t &other) const;
const mpd_c operator/(const uint32_t &other) const;
const mpd_c operator/(const uint64_t &other) const;
//modulo overloads
mpd_c& operator%=(const mpd_c &rhs);
const mpd_c operator%(const mpd_c &other) const;
//comparison overloads
bool operator==(mpd_c const&) const;
bool operator!=(mpd_c const&) const;
bool operator>(mpd_c const&) const;
bool operator<(mpd_c const&) const;
bool operator>=(mpd_c const&) const;
bool operator<=(mpd_c const&) const;
//digitwise overloads - use with care!
const mpd_c operator~();
mpd_c& operator&=(const mpd_c &);
mpd_c& operator|=(const mpd_c &);
mpd_c& operator^=(const mpd_c &);
mpd_c& operator<<=(const mpd_c &);
mpd_c& operator>>=(const mpd_c &);
const mpd_c operator&(const mpd_c &) const;
const mpd_c operator|(const mpd_c &) const;
const mpd_c operator^(const mpd_c &) const;
const mpd_c operator<<(const mpd_c &) const;
const mpd_c operator>>(const mpd_c &) const;
//logical overloads
const mpd_c operator!() const;
friend std::ostream &operator<<(std::ostream &output, const mpd_c &D);
friend std::istream &operator>>(std::istream &input, mpd_c &D);
//cmath
//cos
//sin
//tan
//acos
//asin
//atan
//atan2
//cosh
//sinh
//tanh
//acosh
//asinh
//atanh
friend mpd_c exp(const mpd_c);
//frexp
//ldexp
friend mpd_c log(const mpd_c);
friend mpd_c log10(const mpd_c);
//modf
//exp2
//expm1
//ilogb
//log1p
//log2
//logb
//scalbn
//scalbln
friend mpd_c pow(const mpd_c, const mpd_c);
friend mpd_c sqrt(const mpd_c);
//cbrt
//hypot
//erf
//erfc
//tgamma
//lgamma
friend mpd_c ceil(const mpd_c);
friend mpd_c floor(const mpd_c);
//fmod
//trunc
//round
//lround
//llround
//rint
//llrint
//nearbyint
//remainder
//remquo
//copysign
//nan
//nextafter
//nexttoward
//fdim
//fmax
//fmin
friend mpd_c fabs(const mpd_c);
friend mpd_c abs(const mpd_c);
friend mpd_c fma(const mpd_c, const mpd_c, const mpd_c);
//Macros / Functions
};
//stream manipulation
enum ExponentFormat
{
MPD_EXP_FMT_SCI = 0,
MPD_EXP_FMT_ENG
};
enum ExponentCapitalisation
{
MPD_EXP_CAP_LOWER = 0,
MPD_EXP_CAP_UPPER
};
std::ostream& sci(std::ostream&);
std::ostream& SCI(std::ostream&);
std::ostream& eng(std::ostream&);
std::ostream& ENG(std::ostream&);
}
#endif