6 #include <symengine/complex_mpc.h>
9 #ifdef HAVE_SYMENGINE_MPFR
14 RealMPFR::RealMPFR(mpfr_class i)
15 : i{
std::
move(i)} {SYMENGINE_ASSIGN_TYPEID()}
17 hash_t RealMPFR::__hash__()
const
19 hash_t seed = SYMENGINE_REAL_MPFR;
32 bool RealMPFR::__eq__(
const Basic &o)
const
34 if (is_a<RealMPFR>(o)) {
35 const RealMPFR &s = down_cast<const RealMPFR &>(o);
36 if (get_prec() == s.get_prec()) {
37 return mpfr_cmp(this->i.get_mpfr_t(), s.i.get_mpfr_t()) == 0;
43 int RealMPFR::compare(
const Basic &o)
const
45 SYMENGINE_ASSERT(is_a<RealMPFR>(o))
46 const RealMPFR &s = down_cast<const RealMPFR &>(o);
47 if (get_prec() == s.get_prec()) {
48 int cmp = mpfr_cmp(this->i.get_mpfr_t(), s.i.get_mpfr_t());
51 return cmp > 0 ? 1 : -1;
53 return get_prec() > s.get_prec() ? 1 : -1;
60 RCP<const Number> RealMPFR::addreal(
const Integer &other)
const
62 mpfr_class t(get_prec());
63 mpfr_add_z(t.get_mpfr_t(), i.get_mpfr_t(),
64 get_mpz_t(other.as_integer_class()), MPFR_RNDN);
65 return make_rcp<const RealMPFR>(
std::move(t));
71 RCP<const Number> RealMPFR::addreal(
const Rational &other)
const
73 mpfr_class t(get_prec());
74 mpfr_add_q(t.get_mpfr_t(), i.get_mpfr_t(),
75 get_mpq_t(other.as_rational_class()), MPFR_RNDN);
76 return make_rcp<const RealMPFR>(
std::move(t));
82 RCP<const Number> RealMPFR::addreal(
const Complex &other)
const
84 #ifdef HAVE_SYMENGINE_MPC
85 mpc_class t(get_prec());
86 mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
87 get_mpq_t(other.imaginary_), MPFR_RNDN);
88 mpc_add_fr(t.get_mpc_t(), t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
91 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
98 RCP<const Number> RealMPFR::addreal(
const RealDouble &other)
const
100 mpfr_class t(get_prec());
101 mpfr_add_d(t.get_mpfr_t(), i.get_mpfr_t(), other.i, MPFR_RNDN);
102 return make_rcp<const RealMPFR>(
std::move(t));
108 RCP<const Number> RealMPFR::addreal(
const ComplexDouble &other)
const
110 #ifdef HAVE_SYMENGINE_MPC
111 mpc_class t(get_prec());
112 mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
113 mpc_add_fr(t.get_mpc_t(), t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
116 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
123 RCP<const Number> RealMPFR::addreal(
const RealMPFR &other)
const
125 mpfr_class t(
std::max(get_prec(), other.get_prec()));
126 mpfr_add(t.get_mpfr_t(), i.get_mpfr_t(), other.i.get_mpfr_t(), MPFR_RNDN);
127 return make_rcp<const RealMPFR>(
std::move(t));
133 RCP<const Number> RealMPFR::subreal(
const Integer &other)
const
135 mpfr_class t(get_prec());
136 mpfr_sub_z(t.get_mpfr_t(), i.get_mpfr_t(),
137 get_mpz_t(other.as_integer_class()), MPFR_RNDN);
138 return make_rcp<const RealMPFR>(
std::move(t));
144 RCP<const Number> RealMPFR::subreal(
const Rational &other)
const
146 mpfr_class t(get_prec());
147 mpfr_sub_q(t.get_mpfr_t(), i.get_mpfr_t(),
148 get_mpq_t(other.as_rational_class()), MPFR_RNDN);
149 return make_rcp<const RealMPFR>(
std::move(t));
155 RCP<const Number> RealMPFR::subreal(
const Complex &other)
const
157 #ifdef HAVE_SYMENGINE_MPC
158 mpc_class t(get_prec());
159 mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
160 get_mpq_t(other.imaginary_), MPFR_RNDN);
161 mpc_sub_fr(t.get_mpc_t(), t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
164 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
171 RCP<const Number> RealMPFR::subreal(
const RealDouble &other)
const
173 mpfr_class t(get_prec());
174 mpfr_sub_d(t.get_mpfr_t(), i.get_mpfr_t(), other.i, MPFR_RNDN);
175 return make_rcp<const RealMPFR>(
std::move(t));
181 RCP<const Number> RealMPFR::subreal(
const ComplexDouble &other)
const
183 #ifdef HAVE_SYMENGINE_MPC
184 mpc_class t(get_prec());
185 mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
186 mpc_sub_fr(t.get_mpc_t(), t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
189 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
196 RCP<const Number> RealMPFR::subreal(
const RealMPFR &other)
const
198 mpfr_class t(
std::max(get_prec(), other.get_prec()));
199 mpfr_sub(t.get_mpfr_t(), i.get_mpfr_t(), other.i.get_mpfr_t(), MPFR_RNDN);
200 return make_rcp<const RealMPFR>(
std::move(t));
206 RCP<const Number> RealMPFR::rsubreal(
const Integer &other)
const
208 mpfr_class t(get_prec());
209 mpfr_z_sub(t.get_mpfr_t(), get_mpz_t(other.as_integer_class()),
210 i.get_mpfr_t(), MPFR_RNDN);
211 return make_rcp<const RealMPFR>(
std::move(t));
217 RCP<const Number> RealMPFR::rsubreal(
const Rational &other)
const
219 mpfr_class t(get_prec());
220 mpfr_sub_q(t.get_mpfr_t(), i.get_mpfr_t(),
221 get_mpq_t(other.as_rational_class()), MPFR_RNDN);
222 mpfr_neg(t.get_mpfr_t(), t.get_mpfr_t(), MPFR_RNDN);
223 return make_rcp<const RealMPFR>(
std::move(t));
229 RCP<const Number> RealMPFR::rsubreal(
const Complex &other)
const
231 #ifdef HAVE_SYMENGINE_MPC
232 mpc_class t(get_prec());
233 mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
234 get_mpq_t(other.imaginary_), MPFR_RNDN);
235 mpc_fr_sub(t.get_mpc_t(), this->i.get_mpfr_t(), t.get_mpc_t(), MPFR_RNDN);
238 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
245 RCP<const Number> RealMPFR::rsubreal(
const RealDouble &other)
const
247 mpfr_class t(get_prec());
248 mpfr_d_sub(t.get_mpfr_t(), other.i, i.get_mpfr_t(), MPFR_RNDN);
249 return make_rcp<const RealMPFR>(
std::move(t));
255 RCP<const Number> RealMPFR::rsubreal(
const ComplexDouble &other)
const
257 #ifdef HAVE_SYMENGINE_MPC
258 mpc_class t(get_prec());
259 mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
260 mpc_fr_sub(t.get_mpc_t(), this->i.get_mpfr_t(), t.get_mpc_t(), MPFR_RNDN);
263 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
270 RCP<const Number> RealMPFR::mulreal(
const Integer &other)
const
272 if (other.is_zero()) {
275 mpfr_class t(get_prec());
276 mpfr_mul_z(t.get_mpfr_t(), i.get_mpfr_t(),
277 get_mpz_t(other.as_integer_class()), MPFR_RNDN);
278 return make_rcp<const RealMPFR>(
std::move(t));
284 RCP<const Number> RealMPFR::mulreal(
const Rational &other)
const
286 mpfr_class t(get_prec());
287 mpfr_mul_q(t.get_mpfr_t(), i.get_mpfr_t(),
288 get_mpq_t(other.as_rational_class()), MPFR_RNDN);
289 return make_rcp<const RealMPFR>(
std::move(t));
295 RCP<const Number> RealMPFR::mulreal(
const Complex &other)
const
297 #ifdef HAVE_SYMENGINE_MPC
298 mpc_class t(get_prec());
299 mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
300 get_mpq_t(other.imaginary_), MPFR_RNDN);
301 mpc_mul_fr(t.get_mpc_t(), t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
304 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
311 RCP<const Number> RealMPFR::mulreal(
const RealDouble &other)
const
313 mpfr_class t(get_prec());
314 mpfr_mul_d(t.get_mpfr_t(), i.get_mpfr_t(), other.i, MPFR_RNDN);
315 return make_rcp<const RealMPFR>(
std::move(t));
321 RCP<const Number> RealMPFR::mulreal(
const ComplexDouble &other)
const
323 #ifdef HAVE_SYMENGINE_MPC
324 mpc_class t(get_prec());
325 mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
326 mpc_mul_fr(t.get_mpc_t(), t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
329 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
336 RCP<const Number> RealMPFR::mulreal(
const RealMPFR &other)
const
338 mpfr_class t(
std::max(get_prec(), other.get_prec()));
339 mpfr_mul(t.get_mpfr_t(), i.get_mpfr_t(), other.i.get_mpfr_t(), MPFR_RNDN);
340 return make_rcp<const RealMPFR>(
std::move(t));
346 RCP<const Number> RealMPFR::divreal(
const Integer &other)
const
348 mpfr_class t(get_prec());
349 mpfr_div_z(t.get_mpfr_t(), i.get_mpfr_t(),
350 get_mpz_t(other.as_integer_class()), MPFR_RNDN);
351 return make_rcp<const RealMPFR>(
std::move(t));
357 RCP<const Number> RealMPFR::divreal(
const Rational &other)
const
359 mpfr_class t(get_prec());
360 mpfr_div_q(t.get_mpfr_t(), i.get_mpfr_t(),
361 get_mpq_t(other.as_rational_class()), MPFR_RNDN);
362 return make_rcp<const RealMPFR>(
std::move(t));
368 RCP<const Number> RealMPFR::divreal(
const Complex &other)
const
370 #ifdef HAVE_SYMENGINE_MPC
371 mpc_class t(get_prec());
372 mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
373 get_mpq_t(other.imaginary_), MPFR_RNDN);
374 mpc_div_fr(t.get_mpc_t(), t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
377 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
384 RCP<const Number> RealMPFR::divreal(
const RealDouble &other)
const
386 mpfr_class t(get_prec());
387 mpfr_div_d(t.get_mpfr_t(), i.get_mpfr_t(), other.i, MPFR_RNDN);
388 return make_rcp<const RealMPFR>(
std::move(t));
394 RCP<const Number> RealMPFR::divreal(
const ComplexDouble &other)
const
396 #ifdef HAVE_SYMENGINE_MPC
397 mpc_class t(get_prec());
398 mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
399 mpc_div_fr(t.get_mpc_t(), t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
402 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
409 RCP<const Number> RealMPFR::divreal(
const RealMPFR &other)
const
411 mpfr_class t(
std::max(get_prec(), other.get_prec()));
412 mpfr_div(t.get_mpfr_t(), i.get_mpfr_t(), other.i.get_mpfr_t(), MPFR_RNDN);
413 return make_rcp<const RealMPFR>(
std::move(t));
419 RCP<const Number> RealMPFR::rdivreal(
const Integer &other)
const
421 mpfr_class t(get_prec());
422 mpfr_div_z(t.get_mpfr_t(), i.get_mpfr_t(),
423 get_mpz_t(other.as_integer_class()), MPFR_RNDN);
424 mpfr_pow_si(t.get_mpfr_t(), t.get_mpfr_t(), -1, MPFR_RNDN);
425 return make_rcp<const RealMPFR>(
std::move(t));
431 RCP<const Number> RealMPFR::rdivreal(
const Rational &other)
const
433 mpfr_class t(get_prec());
434 mpfr_div_q(t.get_mpfr_t(), i.get_mpfr_t(),
435 get_mpq_t(other.as_rational_class()), MPFR_RNDN);
436 mpfr_pow_si(t.get_mpfr_t(), t.get_mpfr_t(), -1, MPFR_RNDN);
437 return make_rcp<const RealMPFR>(
std::move(t));
443 RCP<const Number> RealMPFR::rdivreal(
const Complex &other)
const
445 #ifdef HAVE_SYMENGINE_MPC
446 mpc_class t(get_prec());
447 mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
448 get_mpq_t(other.imaginary_), MPFR_RNDN);
449 mpc_fr_div(t.get_mpc_t(), this->i.get_mpfr_t(), t.get_mpc_t(), MPFR_RNDN);
452 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
459 RCP<const Number> RealMPFR::rdivreal(
const RealDouble &other)
const
461 mpfr_class t(get_prec());
462 mpfr_d_div(t.get_mpfr_t(), other.i, i.get_mpfr_t(), MPFR_RNDN);
463 return make_rcp<const RealMPFR>(
std::move(t));
469 RCP<const Number> RealMPFR::rdivreal(
const ComplexDouble &other)
const
471 #ifdef HAVE_SYMENGINE_MPC
472 mpc_class t(get_prec());
473 mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
474 mpc_fr_div(t.get_mpc_t(), this->i.get_mpfr_t(), t.get_mpc_t(), MPFR_RNDN);
477 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
484 RCP<const Number> RealMPFR::powreal(
const Integer &other)
const
486 mpfr_class t(get_prec());
487 mpfr_pow_z(t.get_mpfr_t(), i.get_mpfr_t(),
488 get_mpz_t(other.as_integer_class()), MPFR_RNDN);
489 return make_rcp<const RealMPFR>(
std::move(t));
495 RCP<const Number> RealMPFR::powreal(
const Rational &other)
const
497 if (mpfr_cmp_si(i.get_mpfr_t(), 0) < 0) {
498 #ifdef HAVE_SYMENGINE_MPC
499 mpc_class t(get_prec()), s(get_prec());
500 mpc_set_q(t.get_mpc_t(), get_mpq_t(other.as_rational_class()),
502 mpc_set_fr(s.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
503 mpc_pow(t.get_mpc_t(), s.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
506 throw SymEngineException(
507 "Result is complex. Recompile with MPC support.");
510 mpfr_class t(get_prec());
511 mpfr_set_q(t.get_mpfr_t(), get_mpq_t(other.as_rational_class()), MPFR_RNDN);
512 mpfr_pow(t.get_mpfr_t(), i.get_mpfr_t(), t.get_mpfr_t(), MPFR_RNDN);
513 return make_rcp<const RealMPFR>(
std::move(t));
519 RCP<const Number> RealMPFR::powreal(
const Complex &other)
const
521 #ifdef HAVE_SYMENGINE_MPC
522 mpc_class t(get_prec());
523 mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
524 get_mpq_t(other.imaginary_), MPFR_RNDN);
525 mpc_pow_fr(t.get_mpc_t(), t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
528 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
535 RCP<const Number> RealMPFR::powreal(
const RealDouble &other)
const
537 if (mpfr_cmp_si(i.get_mpfr_t(), 0) < 0) {
538 #ifdef HAVE_SYMENGINE_MPC
539 mpc_class t(get_prec());
540 mpc_set_fr(t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
541 mpc_pow_d(t.get_mpc_t(), t.get_mpc_t(), other.i, MPFR_RNDN);
544 throw SymEngineException(
545 "Result is complex. Recompile with MPC support.");
548 mpfr_class t(get_prec());
549 mpfr_set_d(t.get_mpfr_t(), other.i, MPFR_RNDN);
550 mpfr_pow(t.get_mpfr_t(), i.get_mpfr_t(), t.get_mpfr_t(), MPFR_RNDN);
551 return make_rcp<const RealMPFR>(
std::move(t));
557 RCP<const Number> RealMPFR::powreal(
const ComplexDouble &other)
const
559 #ifdef HAVE_SYMENGINE_MPC
560 mpc_class t(get_prec()), s(get_prec());
561 mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
562 mpc_set_fr(s.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
563 mpc_pow(t.get_mpc_t(), s.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
566 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
573 RCP<const Number> RealMPFR::powreal(
const RealMPFR &other)
const
575 if (mpfr_cmp_si(i.get_mpfr_t(), 0) < 0) {
576 #ifdef HAVE_SYMENGINE_MPC
577 mpc_class t(get_prec());
578 mpc_set_fr(t.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
579 mpc_pow_fr(t.get_mpc_t(), t.get_mpc_t(), other.i.get_mpfr_t(),
583 throw SymEngineException(
584 "Result is complex. Recompile with MPC support.");
587 mpfr_class t(
std::max(get_prec(), other.get_prec()));
588 mpfr_pow(t.get_mpfr_t(), i.get_mpfr_t(), other.i.get_mpfr_t(), MPFR_RNDN);
589 return make_rcp<const RealMPFR>(
std::move(t));
595 RCP<const Number> RealMPFR::rpowreal(
const Integer &other)
const
597 if (other.is_negative()) {
598 #ifdef HAVE_SYMENGINE_MPC
599 mpc_class t(get_prec()), s(get_prec());
600 mpc_set_z(t.get_mpc_t(), get_mpz_t(other.as_integer_class()),
602 mpc_set_fr(s.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
603 mpc_pow(t.get_mpc_t(), t.get_mpc_t(), s.get_mpc_t(), MPFR_RNDN);
606 throw SymEngineException(
607 "Result is complex. Recompile with MPC support.");
610 mpfr_class t(get_prec());
611 mpfr_set_z(t.get_mpfr_t(), get_mpz_t(other.as_integer_class()), MPFR_RNDN);
612 mpfr_pow(t.get_mpfr_t(), t.get_mpfr_t(), i.get_mpfr_t(), MPFR_RNDN);
613 return make_rcp<const RealMPFR>(
std::move(t));
619 RCP<const Number> RealMPFR::rpowreal(
const Rational &other)
const
621 if (other.is_negative()) {
622 #ifdef HAVE_SYMENGINE_MPC
623 mpc_class t(get_prec()), s(get_prec());
624 mpc_set_q(t.get_mpc_t(), get_mpq_t(other.as_rational_class()),
626 mpc_set_fr(s.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
627 mpc_pow(t.get_mpc_t(), t.get_mpc_t(), s.get_mpc_t(), MPFR_RNDN);
630 throw SymEngineException(
631 "Result is complex. Recompile with MPC support.");
634 mpfr_class t(get_prec());
635 mpfr_set_q(t.get_mpfr_t(), get_mpq_t(other.as_rational_class()), MPFR_RNDN);
636 mpfr_pow(t.get_mpfr_t(), t.get_mpfr_t(), i.get_mpfr_t(), MPFR_RNDN);
637 return make_rcp<const RealMPFR>(
std::move(t));
643 RCP<const Number> RealMPFR::rpowreal(
const Complex &other)
const
645 #ifdef HAVE_SYMENGINE_MPC
646 mpc_class t(get_prec()), s(get_prec());
647 mpc_set_q_q(t.get_mpc_t(), get_mpq_t(other.real_),
648 get_mpq_t(other.imaginary_), MPFR_RNDN);
649 mpc_set_fr(s.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
650 mpc_pow(t.get_mpc_t(), s.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
653 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
660 RCP<const Number> RealMPFR::rpowreal(
const RealDouble &other)
const
662 if (mpfr_cmp_si(i.get_mpfr_t(), 0) < 0) {
663 #ifdef HAVE_SYMENGINE_MPC
664 mpc_class t(get_prec()), s(get_prec());
665 mpc_set_d(t.get_mpc_t(), other.i, MPFR_RNDN);
666 mpc_set_fr(s.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
667 mpc_pow(t.get_mpc_t(), t.get_mpc_t(), s.get_mpc_t(), MPFR_RNDN);
670 throw SymEngineException(
671 "Result is complex. Recompile with MPC support.");
674 mpfr_class t(get_prec());
675 mpfr_set_d(t.get_mpfr_t(), other.i, MPFR_RNDN);
676 mpfr_pow(t.get_mpfr_t(), t.get_mpfr_t(), i.get_mpfr_t(), MPFR_RNDN);
677 return make_rcp<const RealMPFR>(
std::move(t));
683 RCP<const Number> RealMPFR::rpowreal(
const ComplexDouble &other)
const
685 #ifdef HAVE_SYMENGINE_MPC
686 mpc_class t(get_prec()), s(get_prec());
687 mpc_set_d_d(t.get_mpc_t(), other.i.real(), other.i.imag(), MPFR_RNDN);
688 mpc_set_fr(s.get_mpc_t(), this->i.get_mpfr_t(), MPFR_RNDN);
689 mpc_pow(t.get_mpc_t(), t.get_mpc_t(), s.get_mpc_t(), MPFR_RNDN);
692 throw SymEngineException(
"Result is complex. Recompile with MPC support.");
697 class EvaluateMPFR :
public Evaluate
699 RCP<const Basic>
sin(
const Basic &x)
const override
701 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
702 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
703 mpfr_sin(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
707 RCP<const Basic>
cos(
const Basic &x)
const override
709 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
710 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
711 mpfr_cos(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
715 RCP<const Basic>
tan(
const Basic &x)
const override
717 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
718 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
719 mpfr_tan(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
723 RCP<const Basic>
cot(
const Basic &x)
const override
725 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
726 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
727 mpfr_cot(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
731 RCP<const Basic>
sec(
const Basic &x)
const override
733 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
734 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
735 mpfr_sec(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
739 RCP<const Basic>
csc(
const Basic &x)
const override
741 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
742 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
743 mpfr_csc(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
747 RCP<const Basic>
asin(
const Basic &x)
const override
749 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
750 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
751 if (mpfr_cmp_si(x_, 1) <= 0 and mpfr_cmp_si(x_, -1) >= 0) {
752 mpfr_class t(mpfr_get_prec(x_));
753 mpfr_asin(t.get_mpfr_t(), x_, MPFR_RNDN);
756 #ifdef HAVE_SYMENGINE_MPC
757 mpc_class t(mpfr_get_prec(x_));
758 mpc_set_fr(t.get_mpc_t(), x_, MPFR_RNDN);
759 mpc_asin(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
762 throw SymEngineException(
763 "Result is complex. Recompile with MPC support.");
766 RCP<const Basic>
acos(
const Basic &x)
const override
768 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
769 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
770 if (mpfr_cmp_si(x_, 1) <= 0 and mpfr_cmp_si(x_, -1) >= 0) {
771 mpfr_class t(mpfr_get_prec(x_));
772 mpfr_acos(t.get_mpfr_t(), x_, MPFR_RNDN);
775 #ifdef HAVE_SYMENGINE_MPC
776 mpc_class t(mpfr_get_prec(x_));
777 mpc_set_fr(t.get_mpc_t(), x_, MPFR_RNDN);
778 mpc_acos(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
781 throw SymEngineException(
782 "Result is complex. Recompile with MPC support.");
785 RCP<const Basic>
atan(
const Basic &x)
const override
787 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
788 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
789 mpfr_atan(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
793 RCP<const Basic>
acot(
const Basic &x)
const override
795 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
796 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
797 mpfr_ui_div(t.get_mpfr_t(), 1,
798 down_cast<const RealMPFR &>(x).i.get_mpfr_t(), MPFR_RNDN);
799 mpfr_atan(t.get_mpfr_t(), t.get_mpfr_t(), MPFR_RNDN);
802 RCP<const Basic>
asec(
const Basic &x)
const override
804 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
805 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
806 if (mpfr_cmp_si(x_, 1) >= 0 or mpfr_cmp_si(x_, -1) <= 0) {
807 mpfr_class t(mpfr_get_prec(x_));
808 mpfr_ui_div(t.get_mpfr_t(), 1, x_, MPFR_RNDN);
809 mpfr_acos(t.get_mpfr_t(), t.get_mpfr_t(), MPFR_RNDN);
812 #ifdef HAVE_SYMENGINE_MPC
813 mpc_class t(mpfr_get_prec(x_));
814 mpc_set_ui(t.get_mpc_t(), 1, MPFR_RNDN);
815 mpc_div_fr(t.get_mpc_t(), t.get_mpc_t(), x_, MPFR_RNDN);
816 mpc_acos(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
819 throw SymEngineException(
820 "Result is complex. Recompile with MPC support.");
823 RCP<const Basic>
acsc(
const Basic &x)
const override
825 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
826 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
827 if (mpfr_cmp_si(x_, 1) >= 0 or mpfr_cmp_si(x_, -1) <= 0) {
828 mpfr_class t(mpfr_get_prec(x_));
829 mpfr_ui_div(t.get_mpfr_t(), 1, x_, MPFR_RNDN);
830 mpfr_asin(t.get_mpfr_t(), t.get_mpfr_t(), MPFR_RNDN);
833 #ifdef HAVE_SYMENGINE_MPC
834 mpc_class t(mpfr_get_prec(x_));
835 mpc_set_ui(t.get_mpc_t(), 1, MPFR_RNDN);
836 mpc_div_fr(t.get_mpc_t(), t.get_mpc_t(), x_, MPFR_RNDN);
837 mpc_asin(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
840 throw SymEngineException(
841 "Result is complex. Recompile with MPC support.");
844 RCP<const Basic>
sinh(
const Basic &x)
const override
846 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
847 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
848 mpfr_sinh(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
852 RCP<const Basic>
csch(
const Basic &x)
const override
854 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
855 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
856 mpfr_csch(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
860 RCP<const Basic>
cosh(
const Basic &x)
const override
862 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
863 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
864 mpfr_cosh(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
868 RCP<const Basic>
sech(
const Basic &x)
const override
870 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
871 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
872 mpfr_sech(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
876 RCP<const Basic>
tanh(
const Basic &x)
const override
878 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
879 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
880 mpfr_tanh(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
884 RCP<const Basic>
coth(
const Basic &x)
const override
886 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
887 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
888 mpfr_coth(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
892 RCP<const Basic>
asinh(
const Basic &x)
const override
894 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
895 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
896 mpfr_asinh(t.get_mpfr_t(),
897 down_cast<const RealMPFR &>(x).i.get_mpfr_t(), MPFR_RNDN);
900 RCP<const Basic>
acsch(
const Basic &x)
const override
902 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
903 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
904 mpfr_class t(mpfr_get_prec(x_));
905 mpfr_ui_div(t.get_mpfr_t(), 1, x_, MPFR_RNDN);
906 mpfr_asinh(t.get_mpfr_t(), t.get_mpfr_t(), MPFR_RNDN);
909 RCP<const Basic>
acosh(
const Basic &x)
const override
911 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
912 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
913 if (mpfr_cmp_si(x_, 1) >= 0) {
914 mpfr_class t(mpfr_get_prec(x_));
915 mpfr_acosh(t.get_mpfr_t(), x_, MPFR_RNDN);
918 #ifdef HAVE_SYMENGINE_MPC
919 mpc_class t(mpfr_get_prec(x_));
920 mpc_set_fr(t.get_mpc_t(), x_, MPFR_RNDN);
921 mpc_acosh(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
924 throw SymEngineException(
925 "Result is complex. Recompile with MPC support.");
928 RCP<const Basic>
atanh(
const Basic &x)
const override
930 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
931 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
932 if (mpfr_cmp_si(x_, 1) <= 0 and mpfr_cmp_si(x_, -1) >= 0) {
933 mpfr_class t(mpfr_get_prec(x_));
934 mpfr_atanh(t.get_mpfr_t(), x_, MPFR_RNDN);
937 #ifdef HAVE_SYMENGINE_MPC
938 mpc_class t(mpfr_get_prec(x_));
939 mpc_set_fr(t.get_mpc_t(), x_, MPFR_RNDN);
940 mpc_atanh(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
943 throw SymEngineException(
944 "Result is complex. Recompile with MPC support.");
947 RCP<const Basic>
acoth(
const Basic &x)
const override
949 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
950 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
951 if (mpfr_cmp_si(x_, 1) >= 0 or mpfr_cmp_si(x_, -1) <= 0) {
952 mpfr_class t(mpfr_get_prec(x_));
953 mpfr_ui_div(t.get_mpfr_t(), 1, x_, MPFR_RNDN);
954 mpfr_atanh(t.get_mpfr_t(), t.get_mpfr_t(), MPFR_RNDN);
957 #ifdef HAVE_SYMENGINE_MPC
958 mpc_class t(mpfr_get_prec(x_));
959 mpc_set_fr(t.get_mpc_t(), x_, MPFR_RNDN);
960 mpc_ui_div(t.get_mpc_t(), 1, t.get_mpc_t(), MPFR_RNDN);
961 mpc_atanh(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
964 throw SymEngineException(
965 "Result is complex. Recompile with MPC support.");
968 RCP<const Basic>
asech(
const Basic &x)
const override
970 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
971 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
972 if (mpfr_cmp_si(x_, 0) >= 0 and mpfr_cmp_si(x_, 1) <= 0) {
973 mpfr_class t(mpfr_get_prec(x_));
974 mpfr_ui_div(t.get_mpfr_t(), 1, x_, MPFR_RNDN);
975 mpfr_acosh(t.get_mpfr_t(), t.get_mpfr_t(), MPFR_RNDN);
978 #ifdef HAVE_SYMENGINE_MPC
979 mpc_class t(mpfr_get_prec(x_));
980 mpc_set_fr(t.get_mpc_t(), x_, MPFR_RNDN);
981 mpc_ui_div(t.get_mpc_t(), 1, t.get_mpc_t(), MPFR_RNDN);
982 mpc_acosh(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
985 throw SymEngineException(
986 "Result is complex. Recompile with MPC support.");
989 RCP<const Basic>
log(
const Basic &x)
const override
991 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
992 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
993 if (mpfr_cmp_si(x_, 0) >= 0) {
994 mpfr_class t(mpfr_get_prec(x_));
995 mpfr_log(t.get_mpfr_t(), x_, MPFR_RNDN);
998 #ifdef HAVE_SYMENGINE_MPC
999 mpc_class t(mpfr_get_prec(x_));
1000 mpc_set_fr(t.get_mpc_t(), x_, MPFR_RNDN);
1001 mpc_log(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
1004 throw SymEngineException(
1005 "Result is complex. Recompile with MPC support.");
1008 RCP<const Basic>
abs(
const Basic &x)
const override
1010 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
1011 mpfr_class t(down_cast<const RealMPFR &>(x).i.get_prec());
1012 mpfr_abs(t.get_mpfr_t(), down_cast<const RealMPFR &>(x).i.get_mpfr_t(),
1017 RCP<const Basic>
gamma(
const Basic &x)
const override
1019 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
1020 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
1021 if (mpfr_cmp_si(x_, 0) >= 0) {
1022 mpfr_class t(mpfr_get_prec(x_));
1023 mpfr_gamma(t.get_mpfr_t(), x_, MPFR_RNDN);
1026 throw NotImplementedError(
"Not Implemented.");
1029 RCP<const Basic>
exp(
const Basic &x)
const override
1031 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
1032 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
1033 mpfr_class t(mpfr_get_prec(x_));
1034 mpfr_exp(t.get_mpfr_t(), x_, MPFR_RNDN);
1037 RCP<const Basic>
floor(
const Basic &x)
const override
1039 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
1040 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
1042 mpfr_get_z(get_mpz_t(i), x_, MPFR_RNDD);
1046 RCP<const Basic>
ceiling(
const Basic &x)
const override
1048 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
1049 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
1051 mpfr_get_z(get_mpz_t(i), x_, MPFR_RNDU);
1055 RCP<const Basic>
truncate(
const Basic &x)
const override
1057 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
1058 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
1060 mpfr_get_z(get_mpz_t(i), x_, MPFR_RNDZ);
1064 RCP<const Basic>
erf(
const Basic &x)
const override
1066 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
1067 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
1068 mpfr_class t(mpfr_get_prec(x_));
1069 mpfr_erf(t.get_mpfr_t(), x_, MPFR_RNDN);
1072 RCP<const Basic>
erfc(
const Basic &x)
const override
1074 SYMENGINE_ASSERT(is_a<RealMPFR>(x))
1075 mpfr_srcptr x_ = down_cast<const RealMPFR &>(x).i.get_mpfr_t();
1076 mpfr_class t(mpfr_get_prec(x_));
1077 mpfr_erfc(t.get_mpfr_t(), x_, MPFR_RNDN);
1082 Evaluate &RealMPFR::get_eval()
const
1084 static EvaluateMPFR evaluate_mpfr;
1085 return evaluate_mpfr;
Main namespace for SymEngine package.
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
RCP< const Basic > sec(const RCP< const Basic > &arg)
Canonicalize Sec:
RCP< const Basic > coth(const RCP< const Basic > &arg)
Canonicalize Coth:
RCP< const Basic > ceiling(const RCP< const Basic > &arg)
Canonicalize Ceiling:
RCP< const Basic > abs(const RCP< const Basic > &arg)
Canonicalize Abs:
RCP< const Basic > acsc(const RCP< const Basic > &arg)
Canonicalize ACsc:
void hash_combine(hash_t &seed, const T &v)
RCP< const Basic > sech(const RCP< const Basic > &arg)
Canonicalize Sech:
RCP< const Basic > gamma(const RCP< const Basic > &arg)
Canonicalize Gamma:
RCP< const Basic > acoth(const RCP< const Basic > &arg)
Canonicalize ACoth:
RCP< const Basic > asec(const RCP< const Basic > &arg)
Canonicalize ASec:
RCP< const Basic > acsch(const RCP< const Basic > &arg)
Canonicalize ACsch:
RCP< const Basic > cot(const RCP< const Basic > &arg)
Canonicalize Cot:
RCP< const Basic > truncate(const RCP< const Basic > &arg)
Canonicalize Truncate:
RCP< const Basic > csc(const RCP< const Basic > &arg)
Canonicalize Csc:
RCP< const Basic > csch(const RCP< const Basic > &arg)
Canonicalize Csch:
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.
RCP< const Basic > asech(const RCP< const Basic > &arg)
Canonicalize ASech:
RCP< const Basic > acot(const RCP< const Basic > &arg)
Canonicalize ACot: