6 #ifndef SYMENGINE_REAL_MPC_H
7 #define SYMENGINE_REAL_MPC_H
9 #include <symengine/real_mpfr.h>
10 #include <symengine/symengine_exception.h>
12 #ifdef HAVE_SYMENGINE_MPC
28 mpc_srcptr get_mpc_t()
const
32 explicit mpc_class(mpc_t m)
34 mpc_init2(mp, mpc_get_prec(m));
35 mpc_set(mp, m, MPFR_RNDN);
37 explicit mpc_class(mpfr_prec_t prec = 53)
41 mpc_class(
std::string s, mpfr_prec_t prec = 53,
unsigned base = 10)
44 mpc_set_str(mp, s.
c_str(), base, MPFR_RNDN);
46 mpc_class(
const mpc_class &other)
48 mpc_init2(mp, mpc_get_prec(other.get_mpc_t()));
49 mpc_set(mp, other.get_mpc_t(), MPFR_RNDN);
51 mpc_class(mpc_class &&other)
53 mp->re->_mpfr_d =
nullptr;
54 mpc_swap(mp, other.get_mpc_t());
56 mpc_class &operator=(
const mpc_class &other)
58 mpc_set_prec(mp, mpc_get_prec(other.get_mpc_t()));
59 mpc_set(mp, other.get_mpc_t(), MPFR_RNDN);
62 mpc_class &operator=(mpc_class &&other)
64 mpc_swap(mp, other.get_mpc_t());
69 if (mp->re->_mpfr_d !=
nullptr) {
73 mpfr_prec_t get_prec()
const
75 return mpc_get_prec(mp);
79 RCP<const Number> number(mpfr_ptr x);
82 class ComplexMPC :
public ComplexBase
90 ComplexMPC(mpc_class i);
91 inline const mpc_class &as_mpc()
const
95 inline mpfr_prec_t get_prec()
const
97 return mpc_get_prec(i.get_mpc_t());
108 RCP<const Number> real_part()
const override;
110 RCP<const Number> imaginary_part()
const override;
112 RCP<const Basic>
conjugate()
const override;
129 inline bool is_exact()
const override
134 Evaluate &
get_eval()
const override;
139 return mpc_cmp_si_si(i.get_mpc_t(), 0, 0) == 0;
143 bool is_one()
const override
157 RCP<const Number>
add(
const Integer &other)
const;
158 RCP<const Number>
add(
const Rational &other)
const;
159 RCP<const Number>
add(
const Complex &other)
const;
160 RCP<const Number>
add(
const RealDouble &other)
const;
161 RCP<const Number>
add(
const ComplexDouble &other)
const;
162 RCP<const Number>
add(
const RealMPFR &other)
const;
163 RCP<const Number>
add(
const ComplexMPC &other)
const;
166 RCP<const Number>
add(
const Number &other)
const override
168 if (is_a<Rational>(other)) {
169 return add(down_cast<const Rational &>(other));
170 }
else if (is_a<Integer>(other)) {
171 return add(down_cast<const Integer &>(other));
172 }
else if (is_a<Complex>(other)) {
173 return add(down_cast<const Complex &>(other));
174 }
else if (is_a<RealDouble>(other)) {
175 return add(down_cast<const RealDouble &>(other));
176 }
else if (is_a<ComplexDouble>(other)) {
177 return add(down_cast<const ComplexDouble &>(other));
178 }
else if (is_a<RealMPFR>(other)) {
179 return add(down_cast<const RealMPFR &>(other));
180 }
else if (is_a<ComplexMPC>(other)) {
181 return add(down_cast<const ComplexMPC &>(other));
183 return other.add(*
this);
187 RCP<const Number>
sub(
const Integer &other)
const;
188 RCP<const Number>
sub(
const Rational &other)
const;
189 RCP<const Number>
sub(
const Complex &other)
const;
190 RCP<const Number>
sub(
const RealDouble &other)
const;
191 RCP<const Number>
sub(
const ComplexDouble &other)
const;
192 RCP<const Number>
sub(
const RealMPFR &other)
const;
193 RCP<const Number>
sub(
const ComplexMPC &other)
const;
196 RCP<const Number>
sub(
const Number &other)
const override
198 if (is_a<Rational>(other)) {
199 return sub(down_cast<const Rational &>(other));
200 }
else if (is_a<Integer>(other)) {
201 return sub(down_cast<const Integer &>(other));
202 }
else if (is_a<Complex>(other)) {
203 return sub(down_cast<const Complex &>(other));
204 }
else if (is_a<RealDouble>(other)) {
205 return sub(down_cast<const RealDouble &>(other));
206 }
else if (is_a<ComplexDouble>(other)) {
207 return sub(down_cast<const ComplexDouble &>(other));
208 }
else if (is_a<RealMPFR>(other)) {
209 return sub(down_cast<const RealMPFR &>(other));
210 }
else if (is_a<ComplexMPC>(other)) {
211 return sub(down_cast<const ComplexMPC &>(other));
213 return other.rsub(*
this);
217 RCP<const Number> rsub(
const Integer &other)
const;
218 RCP<const Number> rsub(
const Rational &other)
const;
219 RCP<const Number> rsub(
const Complex &other)
const;
220 RCP<const Number> rsub(
const RealDouble &other)
const;
221 RCP<const Number> rsub(
const ComplexDouble &other)
const;
222 RCP<const Number> rsub(
const RealMPFR &other)
const;
225 RCP<const Number> rsub(
const Number &other)
const override
227 if (is_a<Rational>(other)) {
228 return rsub(down_cast<const Rational &>(other));
229 }
else if (is_a<Integer>(other)) {
230 return rsub(down_cast<const Integer &>(other));
231 }
else if (is_a<Complex>(other)) {
232 return rsub(down_cast<const Complex &>(other));
233 }
else if (is_a<RealDouble>(other)) {
234 return rsub(down_cast<const RealDouble &>(other));
235 }
else if (is_a<ComplexDouble>(other)) {
236 return rsub(down_cast<const ComplexDouble &>(other));
237 }
else if (is_a<RealMPFR>(other)) {
238 return rsub(down_cast<const RealMPFR &>(other));
240 throw NotImplementedError(
"Not Implemented");
244 RCP<const Number>
mul(
const Integer &other)
const;
245 RCP<const Number>
mul(
const Rational &other)
const;
246 RCP<const Number>
mul(
const Complex &other)
const;
247 RCP<const Number>
mul(
const RealDouble &other)
const;
248 RCP<const Number>
mul(
const ComplexDouble &other)
const;
249 RCP<const Number>
mul(
const RealMPFR &other)
const;
250 RCP<const Number>
mul(
const ComplexMPC &other)
const;
253 RCP<const Number>
mul(
const Number &other)
const override
255 if (is_a<Rational>(other)) {
256 return mul(down_cast<const Rational &>(other));
257 }
else if (is_a<Integer>(other)) {
258 return mul(down_cast<const Integer &>(other));
259 }
else if (is_a<Complex>(other)) {
260 return mul(down_cast<const Complex &>(other));
261 }
else if (is_a<RealDouble>(other)) {
262 return mul(down_cast<const RealDouble &>(other));
263 }
else if (is_a<ComplexDouble>(other)) {
264 return mul(down_cast<const ComplexDouble &>(other));
265 }
else if (is_a<RealMPFR>(other)) {
266 return mul(down_cast<const RealMPFR &>(other));
267 }
else if (is_a<ComplexMPC>(other)) {
268 return mul(down_cast<const ComplexMPC &>(other));
270 return other.mul(*
this);
274 RCP<const Number>
div(
const Integer &other)
const;
275 RCP<const Number>
div(
const Rational &other)
const;
276 RCP<const Number>
div(
const Complex &other)
const;
277 RCP<const Number>
div(
const RealDouble &other)
const;
278 RCP<const Number>
div(
const ComplexDouble &other)
const;
279 RCP<const Number>
div(
const RealMPFR &other)
const;
280 RCP<const Number>
div(
const ComplexMPC &other)
const;
283 RCP<const Number>
div(
const Number &other)
const override
285 if (is_a<Rational>(other)) {
286 return div(down_cast<const Rational &>(other));
287 }
else if (is_a<Integer>(other)) {
288 return div(down_cast<const Integer &>(other));
289 }
else if (is_a<Complex>(other)) {
290 return div(down_cast<const Complex &>(other));
291 }
else if (is_a<RealDouble>(other)) {
292 return div(down_cast<const RealDouble &>(other));
293 }
else if (is_a<ComplexDouble>(other)) {
294 return div(down_cast<const ComplexDouble &>(other));
295 }
else if (is_a<RealMPFR>(other)) {
296 return div(down_cast<const RealMPFR &>(other));
297 }
else if (is_a<ComplexMPC>(other)) {
298 return div(down_cast<const ComplexMPC &>(other));
300 return other.rdiv(*
this);
304 RCP<const Number> rdiv(
const Integer &other)
const;
305 RCP<const Number> rdiv(
const Rational &other)
const;
306 RCP<const Number> rdiv(
const Complex &other)
const;
307 RCP<const Number> rdiv(
const RealDouble &other)
const;
308 RCP<const Number> rdiv(
const ComplexDouble &other)
const;
309 RCP<const Number> rdiv(
const RealMPFR &other)
const;
312 RCP<const Number> rdiv(
const Number &other)
const override
314 if (is_a<Rational>(other)) {
315 return rdiv(down_cast<const Rational &>(other));
316 }
else if (is_a<Integer>(other)) {
317 return rdiv(down_cast<const Integer &>(other));
318 }
else if (is_a<Complex>(other)) {
319 return rdiv(down_cast<const Complex &>(other));
320 }
else if (is_a<RealDouble>(other)) {
321 return rdiv(down_cast<const RealDouble &>(other));
322 }
else if (is_a<ComplexDouble>(other)) {
323 return rdiv(down_cast<const ComplexDouble &>(other));
324 }
else if (is_a<RealMPFR>(other)) {
325 return rdiv(down_cast<const RealMPFR &>(other));
327 throw NotImplementedError(
"Not Implemented");
331 RCP<const Number>
pow(
const Integer &other)
const;
332 RCP<const Number>
pow(
const Rational &other)
const;
333 RCP<const Number>
pow(
const Complex &other)
const;
334 RCP<const Number>
pow(
const RealDouble &other)
const;
335 RCP<const Number>
pow(
const ComplexDouble &other)
const;
336 RCP<const Number>
pow(
const RealMPFR &other)
const;
337 RCP<const Number>
pow(
const ComplexMPC &other)
const;
340 RCP<const Number>
pow(
const Number &other)
const override
342 if (is_a<Rational>(other)) {
343 return pow(down_cast<const Rational &>(other));
344 }
else if (is_a<Integer>(other)) {
345 return pow(down_cast<const Integer &>(other));
346 }
else if (is_a<Complex>(other)) {
347 return pow(down_cast<const Complex &>(other));
348 }
else if (is_a<RealDouble>(other)) {
349 return pow(down_cast<const RealDouble &>(other));
350 }
else if (is_a<ComplexDouble>(other)) {
351 return pow(down_cast<const ComplexDouble &>(other));
352 }
else if (is_a<RealMPFR>(other)) {
353 return pow(down_cast<const RealMPFR &>(other));
354 }
else if (is_a<ComplexMPC>(other)) {
355 return pow(down_cast<const ComplexMPC &>(other));
357 return other.rpow(*
this);
361 RCP<const Number> rpow(
const Integer &other)
const;
362 RCP<const Number> rpow(
const Rational &other)
const;
363 RCP<const Number> rpow(
const Complex &other)
const;
364 RCP<const Number> rpow(
const RealDouble &other)
const;
365 RCP<const Number> rpow(
const ComplexDouble &other)
const;
366 RCP<const Number> rpow(
const RealMPFR &other)
const;
369 RCP<const Number> rpow(
const Number &other)
const override
371 if (is_a<Rational>(other)) {
372 return rpow(down_cast<const Rational &>(other));
373 }
else if (is_a<Integer>(other)) {
374 return rpow(down_cast<const Integer &>(other));
375 }
else if (is_a<Complex>(other)) {
376 return rpow(down_cast<const Complex &>(other));
377 }
else if (is_a<RealDouble>(other)) {
378 return rpow(down_cast<const RealDouble &>(other));
379 }
else if (is_a<ComplexDouble>(other)) {
380 return rpow(down_cast<const ComplexDouble &>(other));
381 }
else if (is_a<RealMPFR>(other)) {
382 return rpow(down_cast<const RealMPFR &>(other));
384 throw NotImplementedError(
"Not Implemented");
389 inline RCP<const ComplexMPC> complex_mpc(mpc_class x)
391 return make_rcp<const ComplexMPC>(
std::move(x));
#define IMPLEMENT_TYPEID(SYMENGINE_ID)
Inline members and functions.
virtual bool __eq__(const Basic &o) const =0
Test equality.
virtual hash_t __hash__() const =0
virtual int compare(const Basic &o) const =0
ComplexBase Class for deriving all complex classes.
virtual Evaluate & get_eval() const
Get Evaluate singleton to evaluate numerically.
virtual RCP< const Number > mul(const Number &other) const =0
Multiplication.
virtual bool is_one() const =0
virtual bool is_complex() const =0
virtual bool is_exact() const
return true if the number is an exact representation
virtual RCP< const Number > add(const Number &other) const =0
Addition.
virtual RCP< const Number > pow(const Number &other) const =0
Power.
virtual bool is_negative() const =0
virtual RCP< const Basic > conjugate() const
virtual bool is_positive() const =0
virtual RCP< const Number > div(const Number &other) const
Division.
virtual RCP< const Number > sub(const Number &other) const
Subtraction.
virtual bool is_zero() const =0
virtual bool is_minus_one() const =0
Main namespace for SymEngine package.