complex_mpc.cpp
1 
6 #include <symengine/complex_mpc.h>
7 #include <symengine/eval_mpc.h>
8 #include <symengine/symengine_exception.h>
9 
10 #ifdef HAVE_SYMENGINE_MPC
11 namespace SymEngine
12 {
13 
14 ComplexMPC::ComplexMPC(mpc_class i)
15  : i{std::move(i)} {SYMENGINE_ASSIGN_TYPEID()}
16 
17  hash_t ComplexMPC::__hash__() const
18 {
19  hash_t seed = SYMENGINE_COMPLEX_MPC;
20  hash_combine_impl(seed, mpc_realref(i.get_mpc_t()));
21  hash_combine_impl(seed, mpc_imagref(i.get_mpc_t()));
22  return seed;
23 }
24 
25 bool ComplexMPC::__eq__(const Basic &o) const
26 {
27  if (is_a<ComplexMPC>(o)) {
28  const ComplexMPC &s = down_cast<const ComplexMPC &>(o);
29  if (get_prec() == s.get_prec()) {
30  return mpc_cmp(this->i.get_mpc_t(), s.i.get_mpc_t()) == 0;
31  }
32  }
33  return false;
34 }
35 
36 int ComplexMPC::compare(const Basic &o) const
37 {
38  SYMENGINE_ASSERT(is_a<ComplexMPC>(o))
39  const ComplexMPC &s = down_cast<const ComplexMPC &>(o);
40  if (get_prec() == s.get_prec()) {
41  int cmp = mpc_cmp(this->i.get_mpc_t(), s.i.get_mpc_t());
42  int x = MPC_INEX_RE(cmp), y = MPC_INEX_IM(cmp);
43  if (x == 0) {
44  if (y != 0)
45  return y > 0 ? 1 : -1;
46  return 0;
47  }
48  return x > 0 ? 1 : -1;
49  } else {
50  return get_prec() > s.get_prec() ? 1 : -1;
51  }
52 }
53 
54 RCP<const Number> ComplexMPC::real_part() const
55 {
56  mpfr_class t(get_prec());
57  mpc_real(t.get_mpfr_t(), i.get_mpc_t(), MPFR_RNDN);
58  return real_mpfr(std::move(t));
59 }
60 
61 RCP<const Number> ComplexMPC::imaginary_part() const
62 {
63  mpfr_class t(get_prec());
64  mpc_imag(t.get_mpfr_t(), i.get_mpc_t(), MPFR_RNDN);
65  return real_mpfr(std::move(t));
66 }
67 
68 RCP<const Basic> ComplexMPC::conjugate() const
69 {
70  mpc_class t(get_prec());
71  mpc_conj(t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
72  return rcp(new ComplexMPC(std::move(t)));
73 }
74 
78 RCP<const Number> ComplexMPC::add(const Integer &other) const
79 {
80  mpc_class t(get_prec());
81  mpc_set_z(t.get_mpc_t(), get_mpz_t(other.as_integer_class()), MPFR_RNDN);
82  mpc_add(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
83  return rcp(new ComplexMPC(std::move(t)));
84 }
85 
89 RCP<const Number> ComplexMPC::add(const Rational &other) const
90 {
91  mpc_class t(get_prec());
92  mpc_set_q(t.get_mpc_t(), get_mpq_t(other.as_rational_class()), MPFR_RNDN);
93  mpc_add(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
94  return rcp(new ComplexMPC(std::move(t)));
95 }
96 
100 RCP<const Number> ComplexMPC::add(const Complex &other) const
101 {
102  mpc_class t(get_prec());
103  mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
104  get_mpq_t(other.imaginary_), MPFR_RNDN);
105  mpc_add(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
106  return rcp(new ComplexMPC(std::move(t)));
107 }
108 
112 RCP<const Number> ComplexMPC::add(const RealDouble &other) const
113 {
114  mpc_class t(get_prec());
115  mpc_set_d(t.get_mpc_t(), other.i, MPFR_RNDN);
116  mpc_add(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
117  return rcp(new ComplexMPC(std::move(t)));
118 }
119 
123 RCP<const Number> ComplexMPC::add(const ComplexDouble &other) const
124 {
125  mpc_class t(get_prec());
126  mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
127  mpc_add(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
128  return rcp(new ComplexMPC(std::move(t)));
129 }
130 
134 RCP<const Number> ComplexMPC::add(const RealMPFR &other) const
135 {
136  mpc_class t(std::max(get_prec(), other.get_prec()));
137  mpc_add_fr(t.get_mpc_t(), i.get_mpc_t(), other.i.get_mpfr_t(), MPFR_RNDN);
138  return rcp(new ComplexMPC(std::move(t)));
139 }
140 
144 RCP<const Number> ComplexMPC::add(const ComplexMPC &other) const
145 {
146  mpc_class t(std::max(get_prec(), other.get_prec()));
147  mpc_add(t.get_mpc_t(), i.get_mpc_t(), other.i.get_mpc_t(), MPFR_RNDN);
148  return rcp(new ComplexMPC(std::move(t)));
149 }
150 
154 RCP<const Number> ComplexMPC::sub(const Integer &other) const
155 {
156  mpc_class t(get_prec());
157  mpc_set_z(t.get_mpc_t(), get_mpz_t(other.as_integer_class()), MPFR_RNDN);
158  mpc_sub(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
159  return rcp(new ComplexMPC(std::move(t)));
160 }
161 
165 RCP<const Number> ComplexMPC::sub(const Rational &other) const
166 {
167  mpc_class t(get_prec());
168  mpc_set_q(t.get_mpc_t(), get_mpq_t(other.as_rational_class()), MPFR_RNDN);
169  mpc_sub(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
170  return rcp(new ComplexMPC(std::move(t)));
171 }
172 
176 RCP<const Number> ComplexMPC::sub(const Complex &other) const
177 {
178  mpc_class t(get_prec());
179  mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
180  get_mpq_t(other.imaginary_), MPFR_RNDN);
181  mpc_sub(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
182  return rcp(new ComplexMPC(std::move(t)));
183 }
184 
188 RCP<const Number> ComplexMPC::sub(const RealDouble &other) const
189 {
190  mpc_class t(get_prec());
191  mpc_set_d(t.get_mpc_t(), other.i, MPFR_RNDN);
192  mpc_sub(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
193  return rcp(new ComplexMPC(std::move(t)));
194 }
195 
199 RCP<const Number> ComplexMPC::sub(const ComplexDouble &other) const
200 {
201  mpc_class t(get_prec());
202  mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
203  mpc_sub(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
204  return rcp(new ComplexMPC(std::move(t)));
205 }
206 
210 RCP<const Number> ComplexMPC::sub(const RealMPFR &other) const
211 {
212  mpc_class t(std::max(get_prec(), other.get_prec()));
213  mpc_sub_fr(t.get_mpc_t(), i.get_mpc_t(), other.i.get_mpfr_t(), MPFR_RNDN);
214  return rcp(new ComplexMPC(std::move(t)));
215 }
216 
220 RCP<const Number> ComplexMPC::sub(const ComplexMPC &other) const
221 {
222  mpc_class t(std::max(get_prec(), other.get_prec()));
223  mpc_sub(t.get_mpc_t(), i.get_mpc_t(), other.i.get_mpc_t(), MPFR_RNDN);
224  return rcp(new ComplexMPC(std::move(t)));
225 }
226 
230 RCP<const Number> ComplexMPC::rsub(const Integer &other) const
231 {
232  mpc_class t(get_prec());
233  mpc_set_z(t.get_mpc_t(), get_mpz_t(other.as_integer_class()), MPFR_RNDN);
234  mpc_sub(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
235  return rcp(new ComplexMPC(std::move(t)));
236 }
237 
241 RCP<const Number> ComplexMPC::rsub(const Rational &other) const
242 {
243  mpc_class t(get_prec());
244  mpc_set_q(t.get_mpc_t(), get_mpq_t(other.as_rational_class()), MPFR_RNDN);
245  mpc_sub(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
246  return rcp(new ComplexMPC(std::move(t)));
247 }
248 
252 RCP<const Number> ComplexMPC::rsub(const Complex &other) const
253 {
254  mpc_class t(get_prec());
255  mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
256  get_mpq_t(other.imaginary_), MPFR_RNDN);
257  mpc_sub(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
258  return rcp(new ComplexMPC(std::move(t)));
259 }
260 
264 RCP<const Number> ComplexMPC::rsub(const RealDouble &other) const
265 {
266  mpc_class t(get_prec());
267  mpc_set_d(t.get_mpc_t(), other.i, MPFR_RNDN);
268  mpc_sub(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
269  return rcp(new ComplexMPC(std::move(t)));
270 }
271 
275 RCP<const Number> ComplexMPC::rsub(const ComplexDouble &other) const
276 {
277  mpc_class t(get_prec());
278  mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
279  mpc_sub(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
280  return rcp(new ComplexMPC(std::move(t)));
281 }
282 
286 RCP<const Number> ComplexMPC::rsub(const RealMPFR &other) const
287 {
288  mpc_class t(std::max(get_prec(), other.get_prec()));
289  mpc_fr_sub(t.get_mpc_t(), other.i.get_mpfr_t(), i.get_mpc_t(), MPFR_RNDN);
290  return rcp(new ComplexMPC(std::move(t)));
291 }
292 
296 RCP<const Number> ComplexMPC::mul(const Integer &other) const
297 {
298  mpc_class t(get_prec());
299  mpc_set_z(t.get_mpc_t(), get_mpz_t(other.as_integer_class()), MPFR_RNDN);
300  mpc_mul(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
301  return rcp(new ComplexMPC(std::move(t)));
302 }
303 
307 RCP<const Number> ComplexMPC::mul(const Rational &other) const
308 {
309  mpc_class t(get_prec());
310  mpc_set_q(t.get_mpc_t(), get_mpq_t(other.as_rational_class()), MPFR_RNDN);
311  mpc_mul(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
312  return rcp(new ComplexMPC(std::move(t)));
313 }
314 
318 RCP<const Number> ComplexMPC::mul(const Complex &other) const
319 {
320  mpc_class t(get_prec());
321  mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
322  get_mpq_t(other.imaginary_), MPFR_RNDN);
323  mpc_mul(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
324  return rcp(new ComplexMPC(std::move(t)));
325 }
326 
330 RCP<const Number> ComplexMPC::mul(const RealDouble &other) const
331 {
332  mpc_class t(get_prec());
333  mpc_set_d(t.get_mpc_t(), other.i, MPFR_RNDN);
334  mpc_mul(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
335  return rcp(new ComplexMPC(std::move(t)));
336 }
337 
341 RCP<const Number> ComplexMPC::mul(const ComplexDouble &other) const
342 {
343  mpc_class t(get_prec());
344  mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
345  mpc_mul(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
346  return rcp(new ComplexMPC(std::move(t)));
347 }
348 
352 RCP<const Number> ComplexMPC::mul(const RealMPFR &other) const
353 {
354  mpc_class t(std::max(get_prec(), other.get_prec()));
355  mpc_mul_fr(t.get_mpc_t(), i.get_mpc_t(), other.i.get_mpfr_t(), MPFR_RNDN);
356  return rcp(new ComplexMPC(std::move(t)));
357 }
358 
362 RCP<const Number> ComplexMPC::mul(const ComplexMPC &other) const
363 {
364  mpc_class t(std::max(get_prec(), other.get_prec()));
365  mpc_mul(t.get_mpc_t(), i.get_mpc_t(), other.i.get_mpc_t(), MPFR_RNDN);
366  return rcp(new ComplexMPC(std::move(t)));
367 }
368 
372 RCP<const Number> ComplexMPC::div(const Integer &other) const
373 {
374  mpc_class t(get_prec());
375  mpc_set_z(t.get_mpc_t(), get_mpz_t(other.as_integer_class()), MPFR_RNDN);
376  mpc_div(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
377  return rcp(new ComplexMPC(std::move(t)));
378 }
379 
383 RCP<const Number> ComplexMPC::div(const Rational &other) const
384 {
385  mpc_class t(get_prec());
386  mpc_set_q(t.get_mpc_t(), get_mpq_t(other.as_rational_class()), MPFR_RNDN);
387  mpc_div(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
388  return rcp(new ComplexMPC(std::move(t)));
389 }
390 
394 RCP<const Number> ComplexMPC::div(const Complex &other) const
395 {
396  mpc_class t(get_prec());
397  mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
398  get_mpq_t(other.imaginary_), MPFR_RNDN);
399  mpc_div(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
400  return rcp(new ComplexMPC(std::move(t)));
401 }
402 
406 RCP<const Number> ComplexMPC::div(const RealDouble &other) const
407 {
408  mpc_class t(get_prec());
409  mpc_set_d(t.get_mpc_t(), other.i, MPFR_RNDN);
410  mpc_div(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
411  return rcp(new ComplexMPC(std::move(t)));
412 }
413 
417 RCP<const Number> ComplexMPC::div(const ComplexDouble &other) const
418 {
419  mpc_class t(get_prec());
420  mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
421  mpc_div(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
422  return rcp(new ComplexMPC(std::move(t)));
423 }
424 
428 RCP<const Number> ComplexMPC::div(const RealMPFR &other) const
429 {
430  mpc_class t(std::max(get_prec(), other.get_prec()));
431  mpc_div_fr(t.get_mpc_t(), i.get_mpc_t(), other.i.get_mpfr_t(), MPFR_RNDN);
432  return rcp(new ComplexMPC(std::move(t)));
433 }
434 
438 RCP<const Number> ComplexMPC::div(const ComplexMPC &other) const
439 {
440  mpc_class t(std::max(get_prec(), other.get_prec()));
441  mpc_div(t.get_mpc_t(), i.get_mpc_t(), other.i.get_mpc_t(), MPFR_RNDN);
442  return rcp(new ComplexMPC(std::move(t)));
443 }
444 
448 RCP<const Number> ComplexMPC::rdiv(const Integer &other) const
449 {
450  mpc_class t(get_prec());
451  mpc_set_z(t.get_mpc_t(), get_mpz_t(other.as_integer_class()), MPFR_RNDN);
452  mpc_div(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
453  return rcp(new ComplexMPC(std::move(t)));
454 }
455 
459 RCP<const Number> ComplexMPC::rdiv(const Rational &other) const
460 {
461  mpc_class t(get_prec());
462  mpc_set_q(t.get_mpc_t(), get_mpq_t(other.as_rational_class()), MPFR_RNDN);
463  mpc_div(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
464  return rcp(new ComplexMPC(std::move(t)));
465 }
466 
470 RCP<const Number> ComplexMPC::rdiv(const Complex &other) const
471 {
472  mpc_class t(get_prec());
473  mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
474  get_mpq_t(other.imaginary_), MPFR_RNDN);
475  mpc_div(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
476  return rcp(new ComplexMPC(std::move(t)));
477 }
478 
482 RCP<const Number> ComplexMPC::rdiv(const RealDouble &other) const
483 {
484  mpc_class t(get_prec());
485  mpc_set_d(t.get_mpc_t(), other.i, MPFR_RNDN);
486  mpc_div(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
487  return rcp(new ComplexMPC(std::move(t)));
488 }
489 
493 RCP<const Number> ComplexMPC::rdiv(const ComplexDouble &other) const
494 {
495  mpc_class t(get_prec());
496  mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
497  mpc_div(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
498  return rcp(new ComplexMPC(std::move(t)));
499 }
500 
504 RCP<const Number> ComplexMPC::rdiv(const RealMPFR &other) const
505 {
506  mpc_class t(std::max(get_prec(), other.get_prec()));
507  mpc_fr_div(t.get_mpc_t(), other.i.get_mpfr_t(), i.get_mpc_t(), MPFR_RNDN);
508  return rcp(new ComplexMPC(std::move(t)));
509 }
510 
514 RCP<const Number> ComplexMPC::pow(const Integer &other) const
515 {
516  mpc_class t(get_prec());
517  mpc_set_z(t.get_mpc_t(), get_mpz_t(other.as_integer_class()), MPFR_RNDN);
518  mpc_pow(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
519  return rcp(new ComplexMPC(std::move(t)));
520 }
521 
525 RCP<const Number> ComplexMPC::pow(const Rational &other) const
526 {
527  mpc_class t(get_prec());
528  mpc_set_q(t.get_mpc_t(), get_mpq_t(other.as_rational_class()), MPFR_RNDN);
529  mpc_pow(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
530  return rcp(new ComplexMPC(std::move(t)));
531 }
532 
536 RCP<const Number> ComplexMPC::pow(const Complex &other) const
537 {
538  mpc_class t(get_prec());
539  mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
540  get_mpq_t(other.imaginary_), MPFR_RNDN);
541  mpc_pow(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
542  return rcp(new ComplexMPC(std::move(t)));
543 }
544 
548 RCP<const Number> ComplexMPC::pow(const RealDouble &other) const
549 {
550  mpc_class t(get_prec());
551  mpc_set_d(t.get_mpc_t(), other.i, MPFR_RNDN);
552  mpc_pow(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
553  return rcp(new ComplexMPC(std::move(t)));
554 }
555 
559 RCP<const Number> ComplexMPC::pow(const ComplexDouble &other) const
560 {
561  mpc_class t(get_prec());
562  mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
563  mpc_pow(t.get_mpc_t(), i.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
564  return rcp(new ComplexMPC(std::move(t)));
565 }
566 
570 RCP<const Number> ComplexMPC::pow(const RealMPFR &other) const
571 {
572  mpc_class t(std::max(get_prec(), other.get_prec()));
573  mpc_pow_fr(t.get_mpc_t(), i.get_mpc_t(), other.i.get_mpfr_t(), MPFR_RNDN);
574  return rcp(new ComplexMPC(std::move(t)));
575 }
576 
580 RCP<const Number> ComplexMPC::pow(const ComplexMPC &other) const
581 {
582  mpc_class t(std::max(get_prec(), other.get_prec()));
583  mpc_pow(t.get_mpc_t(), i.get_mpc_t(), other.i.get_mpc_t(), MPFR_RNDN);
584  return rcp(new ComplexMPC(std::move(t)));
585 }
586 
590 RCP<const Number> ComplexMPC::rpow(const Integer &other) const
591 {
592  mpc_class t(get_prec());
593  mpc_set_z(t.get_mpc_t(), get_mpz_t(other.as_integer_class()), MPFR_RNDN);
594  mpc_pow(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
595  return rcp(new ComplexMPC(std::move(t)));
596 }
597 
601 RCP<const Number> ComplexMPC::rpow(const Rational &other) const
602 {
603  mpc_class t(get_prec());
604  mpc_set_q(t.get_mpc_t(), get_mpq_t(other.as_rational_class()), MPFR_RNDN);
605  mpc_pow(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
606  return rcp(new ComplexMPC(std::move(t)));
607 }
608 
612 RCP<const Number> ComplexMPC::rpow(const Complex &other) const
613 {
614  mpc_class t(get_prec());
615  mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
616  get_mpq_t(other.imaginary_), MPFR_RNDN);
617  mpc_pow(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
618  return rcp(new ComplexMPC(std::move(t)));
619 }
620 
624 RCP<const Number> ComplexMPC::rpow(const RealDouble &other) const
625 {
626  mpc_class t(get_prec());
627  mpc_set_d(t.get_mpc_t(), other.i, MPFR_RNDN);
628  mpc_pow(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
629  return rcp(new ComplexMPC(std::move(t)));
630 }
631 
635 RCP<const Number> ComplexMPC::rpow(const ComplexDouble &other) const
636 {
637  mpc_class t(get_prec());
638  mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
639  mpc_pow(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
640  return rcp(new ComplexMPC(std::move(t)));
641 }
642 
646 RCP<const Number> ComplexMPC::rpow(const RealMPFR &other) const
647 {
648  mpc_class t(std::max(get_prec(), other.get_prec()));
649  mpc_set_fr(t.get_mpc_t(), other.i.get_mpfr_t(), MPFR_RNDN);
650  mpc_pow(t.get_mpc_t(), t.get_mpc_t(), i.get_mpc_t(), MPFR_RNDN);
651  return rcp(new ComplexMPC(std::move(t)));
652 }
653 
655 class EvaluateMPC : public Evaluate
656 {
657  virtual RCP<const Basic> sin(const Basic &x) const override
658  {
659  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
660  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
661  mpc_sin(t.get_mpc_t(),
662  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
663  MPFR_RNDN);
664  return complex_mpc(std::move(t));
665  }
666  virtual RCP<const Basic> cos(const Basic &x) const override
667  {
668  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
669  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
670  mpc_cos(t.get_mpc_t(),
671  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
672  MPFR_RNDN);
673  return complex_mpc(std::move(t));
674  }
675  virtual RCP<const Basic> tan(const Basic &x) const override
676  {
677  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
678  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
679  mpc_tan(t.get_mpc_t(),
680  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
681  MPFR_RNDN);
682  return complex_mpc(std::move(t));
683  }
684  virtual RCP<const Basic> cot(const Basic &x) const override
685  {
686  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
687  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
688  mpc_tan(t.get_mpc_t(),
689  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
690  MPFR_RNDN);
691  mpc_ui_div(t.get_mpc_t(), 1, t.get_mpc_t(), MPFR_RNDN);
692  return complex_mpc(std::move(t));
693  }
694  virtual RCP<const Basic> sec(const Basic &x) const override
695  {
696  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
697  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
698  mpc_cos(t.get_mpc_t(),
699  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
700  MPFR_RNDN);
701  mpc_ui_div(t.get_mpc_t(), 1, t.get_mpc_t(), MPFR_RNDN);
702  return complex_mpc(std::move(t));
703  }
704  virtual RCP<const Basic> csc(const Basic &x) const override
705  {
706  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
707  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
708  mpc_sin(t.get_mpc_t(),
709  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
710  MPFR_RNDN);
711  mpc_ui_div(t.get_mpc_t(), 1, t.get_mpc_t(), MPFR_RNDN);
712  return complex_mpc(std::move(t));
713  }
714  virtual RCP<const Basic> asin(const Basic &x) const override
715  {
716  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
717  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
718  mpc_asin(t.get_mpc_t(),
719  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
720  MPFR_RNDN);
721  return complex_mpc(std::move(t));
722  }
723  virtual RCP<const Basic> acos(const Basic &x) const override
724  {
725  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
726  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
727  mpc_acos(t.get_mpc_t(),
728  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
729  MPFR_RNDN);
730  return complex_mpc(std::move(t));
731  }
732  virtual RCP<const Basic> atan(const Basic &x) const override
733  {
734  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
735  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
736  mpc_atan(t.get_mpc_t(),
737  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
738  MPFR_RNDN);
739  return complex_mpc(std::move(t));
740  }
741  virtual RCP<const Basic> acot(const Basic &x) const override
742  {
743  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
744  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
745  mpc_ui_div(t.get_mpc_t(), 1,
746  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
747  MPFR_RNDN);
748  mpc_atan(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
749  return complex_mpc(std::move(t));
750  }
751  virtual RCP<const Basic> asec(const Basic &x) const override
752  {
753  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
754  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
755  mpc_ui_div(t.get_mpc_t(), 1,
756  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
757  MPFR_RNDN);
758  mpc_acos(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
759  return complex_mpc(std::move(t));
760  }
761  virtual RCP<const Basic> acsc(const Basic &x) const override
762  {
763  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
764  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
765  mpc_ui_div(t.get_mpc_t(), 1,
766  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
767  MPFR_RNDN);
768  mpc_asin(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
769  return complex_mpc(std::move(t));
770  }
771  virtual RCP<const Basic> sinh(const Basic &x) const override
772  {
773  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
774  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
775  mpc_sinh(t.get_mpc_t(),
776  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
777  MPFR_RNDN);
778  return complex_mpc(std::move(t));
779  }
780  virtual RCP<const Basic> csch(const Basic &x) const override
781  {
782  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
783  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
784  mpc_sinh(t.get_mpc_t(),
785  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
786  MPFR_RNDN);
787  mpc_ui_div(t.get_mpc_t(), 1, t.get_mpc_t(), MPFR_RNDN);
788  return complex_mpc(std::move(t));
789  }
790  virtual RCP<const Basic> cosh(const Basic &x) const override
791  {
792  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
793  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
794  mpc_cosh(t.get_mpc_t(),
795  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
796  MPFR_RNDN);
797  return complex_mpc(std::move(t));
798  }
799  virtual RCP<const Basic> sech(const Basic &x) const override
800  {
801  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
802  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
803  mpc_cosh(t.get_mpc_t(),
804  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
805  MPFR_RNDN);
806  mpc_ui_div(t.get_mpc_t(), 1, t.get_mpc_t(), MPFR_RNDN);
807  return complex_mpc(std::move(t));
808  }
809  virtual RCP<const Basic> tanh(const Basic &x) const override
810  {
811  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
812  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
813  mpc_tanh(t.get_mpc_t(),
814  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
815  MPFR_RNDN);
816  return complex_mpc(std::move(t));
817  }
818  virtual RCP<const Basic> coth(const Basic &x) const override
819  {
820  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
821  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
822  mpc_tanh(t.get_mpc_t(),
823  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
824  MPFR_RNDN);
825  mpc_ui_div(t.get_mpc_t(), 1, t.get_mpc_t(), MPFR_RNDN);
826  return complex_mpc(std::move(t));
827  }
828  virtual RCP<const Basic> asinh(const Basic &x) const override
829  {
830  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
831  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
832  mpc_asinh(t.get_mpc_t(),
833  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
834  MPFR_RNDN);
835  return complex_mpc(std::move(t));
836  }
837  virtual RCP<const Basic> acsch(const Basic &x) const override
838  {
839  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
840  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
841  mpc_ui_div(t.get_mpc_t(), 1,
842  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
843  MPFR_RNDN);
844  mpc_asinh(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
845  return complex_mpc(std::move(t));
846  }
847  virtual RCP<const Basic> acosh(const Basic &x) const override
848  {
849  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
850  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
851  mpc_acosh(t.get_mpc_t(),
852  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
853  MPFR_RNDN);
854  return complex_mpc(std::move(t));
855  }
856  virtual RCP<const Basic> atanh(const Basic &x) const override
857  {
858  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
859  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
860  mpc_atanh(t.get_mpc_t(),
861  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
862  MPFR_RNDN);
863  return complex_mpc(std::move(t));
864  }
865  virtual RCP<const Basic> acoth(const Basic &x) const override
866  {
867  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
868  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
869  mpc_ui_div(t.get_mpc_t(), 1,
870  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
871  MPFR_RNDN);
872  mpc_atanh(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
873  return complex_mpc(std::move(t));
874  }
875  virtual RCP<const Basic> asech(const Basic &x) const override
876  {
877  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
878  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
879  mpc_ui_div(t.get_mpc_t(), 1,
880  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
881  MPFR_RNDN);
882  mpc_acosh(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
883  return complex_mpc(std::move(t));
884  }
885  virtual RCP<const Basic> log(const Basic &x) const override
886  {
887  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
888  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
889  mpc_log(t.get_mpc_t(),
890  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
891  MPFR_RNDN);
892  return complex_mpc(std::move(t));
893  }
894  virtual RCP<const Basic> abs(const Basic &x) const override
895  {
896  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
897  mpfr_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
898  mpc_abs(t.get_mpfr_t(),
899  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
900  MPFR_RNDN);
901  return real_mpfr(std::move(t));
902  }
903  virtual RCP<const Basic> gamma(Basic const &aConst) const override
904  {
905  throw NotImplementedError("Not Implemented.");
906  }
907  virtual RCP<const Basic> exp(const Basic &x) const override
908  {
909  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
910  mpc_class t(down_cast<const ComplexMPC &>(x).as_mpc().get_prec());
911  mpc_exp(t.get_mpc_t(),
912  down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t(),
913  MPFR_RNDN);
914  return complex_mpc(std::move(t));
915  }
916  virtual RCP<const Basic> floor(const Basic &x) const override
917  {
918  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
919  integer_class re, im;
920  mpfr_get_z(
921  get_mpz_t(re),
922  mpc_realref(down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t()),
923  MPFR_RNDD);
924  mpfr_get_z(
925  get_mpz_t(im),
926  mpc_imagref(down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t()),
927  MPFR_RNDD);
928  mp_demote(re);
929  mp_demote(im);
930  return Complex::from_two_nums(*integer(std::move(re)),
931  *integer(std::move(im)));
932  }
933  virtual RCP<const Basic> ceiling(const Basic &x) const override
934  {
935  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
936  integer_class re, im;
937  mpfr_get_z(
938  get_mpz_t(re),
939  mpc_realref(down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t()),
940  MPFR_RNDU);
941  mpfr_get_z(
942  get_mpz_t(im),
943  mpc_imagref(down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t()),
944  MPFR_RNDU);
945  mp_demote(re);
946  mp_demote(im);
947  return Complex::from_two_nums(*integer(std::move(re)),
948  *integer(std::move(im)));
949  }
950  virtual RCP<const Basic> truncate(const Basic &x) const override
951  {
952  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
953  integer_class re, im;
954  mpfr_get_z(
955  get_mpz_t(re),
956  mpc_realref(down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t()),
957  MPFR_RNDZ);
958  mpfr_get_z(
959  get_mpz_t(im),
960  mpc_imagref(down_cast<const ComplexMPC &>(x).as_mpc().get_mpc_t()),
961  MPFR_RNDZ);
962  mp_demote(re);
963  mp_demote(im);
964  return Complex::from_two_nums(*integer(std::move(re)),
965  *integer(std::move(im)));
966  }
967  virtual RCP<const Basic> erf(const Basic &x) const override
968  {
969  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
970  throw NotImplementedError("erf is not implemented in mpc");
971  }
972  virtual RCP<const Basic> erfc(const Basic &x) const override
973  {
974  SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
975  throw NotImplementedError("erfc is not implemented in mpc");
976  }
977 };
978 
979 Evaluate &ComplexMPC::get_eval() const
980 {
981  static EvaluateMPC evaluate_mpc;
982  return evaluate_mpc;
983 }
984 
985 } // namespace SymEngine
986 #endif // HAVE_SYMENGINE_MPC
T acos(T... args)
T acosh(T... args)
T asin(T... args)
T asinh(T... args)
T atan(T... args)
T atanh(T... args)
T cos(T... args)
T cosh(T... args)
T erf(T... args)
T erfc(T... args)
T exp(T... args)
T floor(T... args)
T log(T... args)
T max(T... args)
T move(T... args)
Main namespace for SymEngine package.
Definition: add.cpp:19
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
Definition: integer.h:200
RCP< const Basic > sec(const RCP< const Basic > &arg)
Canonicalize Sec:
Definition: functions.cpp:1159
RCP< const Basic > coth(const RCP< const Basic > &arg)
Canonicalize Coth:
Definition: functions.cpp:2290
RCP< const Basic > ceiling(const RCP< const Basic > &arg)
Canonicalize Ceiling:
Definition: functions.cpp:662
RCP< const Basic > abs(const RCP< const Basic > &arg)
Canonicalize Abs:
Definition: functions.cpp:3449
RCP< const Basic > acsc(const RCP< const Basic > &arg)
Canonicalize ACsc:
Definition: functions.cpp:1441
RCP< const Basic > sech(const RCP< const Basic > &arg)
Canonicalize Sech:
Definition: functions.cpp:2208
RCP< const Basic > gamma(const RCP< const Basic > &arg)
Canonicalize Gamma:
Definition: functions.cpp:2971
RCP< const Basic > sub(const RCP< const Basic > &a, const RCP< const Basic > &b)
Substracts b from a.
Definition: add.cpp:495
RCP< const Basic > acoth(const RCP< const Basic > &arg)
Canonicalize ACoth:
Definition: functions.cpp:2491
RCP< const Basic > asec(const RCP< const Basic > &arg)
Canonicalize ASec:
Definition: functions.cpp:1401
RCP< const Basic > acsch(const RCP< const Basic > &arg)
Canonicalize ACsch:
Definition: functions.cpp:2379
RCP< const Basic > cot(const RCP< const Basic > &arg)
Canonicalize Cot:
Definition: functions.cpp:1030
RCP< const Basic > truncate(const RCP< const Basic > &arg)
Canonicalize Truncate:
Definition: functions.cpp:756
RCP< const Basic > csc(const RCP< const Basic > &arg)
Canonicalize Csc:
Definition: functions.cpp:1095
RCP< const Basic > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).
Definition: add.cpp:425
RCP< const Basic > csch(const RCP< const Basic > &arg)
Canonicalize Csch:
Definition: functions.cpp:2126
void hash_combine_impl(hash_t &seed, const T &v, typename std::enable_if< std::is_base_of< Basic, T >::value >::type *=nullptr)
Templatised version to combine hash.
Definition: basic-inl.h:103
RCP< const Basic > asech(const RCP< const Basic > &arg)
Canonicalize ASech:
Definition: functions.cpp:2528
RCP< const Basic > acot(const RCP< const Basic > &arg)
Canonicalize ACot:
Definition: functions.cpp:1523
STL namespace.
T sin(T... args)
T sinh(T... args)
T tan(T... args)
T tanh(T... args)