4 #include <symengine/real_double.h>
5 #include <symengine/complex_double.h>
6 #include <symengine/symengine_rcp.h>
8 #ifdef HAVE_SYMENGINE_MPFR
10 #include <symengine/real_mpfr.h>
14 #ifdef HAVE_SYMENGINE_MPC
16 #include <symengine/complex_mpc.h>
23 RCP<const Number> evalf_numeric(
const Basic &b,
unsigned long bits,
bool real)
25 if (bits <= 53 && real) {
26 double d = eval_double(b);
27 return real_double(d);
28 }
else if (bits <= 53 && !real) {
30 return complex_double(d);
31 }
else if (bits > 53 && real) {
32 #ifdef HAVE_SYMENGINE_MPFR
33 mpfr_class mc = mpfr_class(bits);
34 mpfr_ptr result = mc.get_mpfr_t();
35 eval_mpfr(result, b, MPFR_RNDN);
39 "For multiple bit precision, MPFR is needed");
42 #ifdef HAVE_SYMENGINE_MPC
43 mpc_class mc = mpc_class(bits);
44 mpc_ptr result = mc.get_mpc_t();
45 eval_mpc(result, b, MPFR_RNDN);
46 return make_rcp<ComplexMPC>(
std::move(mc));
49 "For multiple bit precision, MPC is needed");
61 using TransformVisitor::apply;
62 using TransformVisitor::bvisit;
63 void bvisit(
const Number &x)
65 result_ = evalf_numeric(x, bits,
true);
69 result_ = evalf_numeric(x, bits,
false);
73 result_ = evalf_numeric(x, bits,
true);
77 result_ = x.eval(bits)->rcp_from_this();
81 result_ = x.eval(bits)->rcp_from_this();
85 RCP<const Basic> evalf(
const Basic &b,
unsigned long bits, EvalfDomain domain)
87 #ifndef HAVE_SYMENGINE_MPFR
90 "For multiple bit precision, MPFR is needed");
93 #ifndef HAVE_SYMENGINE_MPC
94 if (bits > 53 and domain == EvalfDomain::Complex) {
96 "For multiple bit precision, MPC is needed");
99 if (domain == EvalfDomain::Real) {
100 return evalf_numeric(b, bits,
true);
101 }
else if (domain == EvalfDomain::Complex) {
102 return evalf_numeric(b, bits,
false);
The lowest unit of symbolic representation.
ComplexBase Class for deriving all complex classes.
RCP< T > rcp_from_this()
Get RCP<T> pointer to self (it will cast the pointer to T)
Main namespace for SymEngine package.