-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Common evals method and its CWrappers #987
Changes from 16 commits
c1e62d0
affb2c9
7d8a617
fbf5dba
7abea89
d4ce540
7c84b0a
93cc8cb
99cef42
fb562f6
43277fa
f2fdd43
36a09ea
ebb9993
a8fd30e
9de8231
5f7bb63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <exception> | ||
#include <symengine/eval.h> | ||
#include <symengine/eval_double.h> | ||
#include <symengine/real_double.h> | ||
#include <symengine/complex_double.h> | ||
#include <symengine/symengine_rcp.h> | ||
#ifdef HAVE_SYMENGINE_MPFR | ||
#include <mpfr.h> | ||
#include <symengine/real_mpfr.h> | ||
#include <symengine/eval_mpfr.h> | ||
#endif // HAVE_SYMENGINE_MPFR | ||
|
||
#ifdef HAVE_SYMENGINE_MPC | ||
#include <mpc.h> | ||
#include <symengine/complex_mpc.h> | ||
#include <symengine/eval_mpc.h> | ||
#endif // HAVE_SYMENGINE_MPC | ||
|
||
namespace SymEngine | ||
{ | ||
|
||
RCP<const Number> evalf(const Basic &b, unsigned long bits, bool real) | ||
{ | ||
if (bits <= 53 && real) { // double | ||
double d = eval_double(b); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return a |
||
return real_double(d); | ||
} else if (bits <= 53 && !real) { // complex double | ||
std::complex<double> d = eval_complex_double(b); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return a |
||
return complex_double(d); | ||
} else if (bits > 53 && real) { // mpfr | ||
#ifdef HAVE_SYMENGINE_MPFR | ||
mpfr_class mc = mpfr_class(bits); | ||
mpfr_ptr result = mc.get_mpfr_t(); | ||
eval_mpfr(result, b, MPFR_RNDN); | ||
return make_rcp<RealMPFR>(std::move(mc)); | ||
#else | ||
throw std::invalid_argument( | ||
"For multiple bit precision, MPFR is needed"); | ||
#endif // HAVE_SYMENGINE_MPFR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. throw an error here if |
||
} else { // mpc | ||
#ifdef HAVE_SYMENGINE_MPC | ||
mpc_class mc = mpc_class(bits); | ||
mpc_ptr result = mc.get_mpc_t(); | ||
eval_mpc(result, b, MPFR_RNDN); | ||
return make_rcp<ComplexMPC>(std::move(mc)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
#else | ||
throw std::invalid_argument( | ||
"For multiple bit precision, MPC is needed"); | ||
#endif // HAVE_SYMENGINE_MPC | ||
} | ||
} | ||
} // SymEngine |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* \file eval.h | ||
* | ||
**/ | ||
#ifndef SYMENGINE_EVAL_H | ||
#define SYMENGINE_EVAL_H | ||
|
||
#include <symengine/basic.h> | ||
#include <symengine/dict.h> | ||
#include <symengine/symengine_rcp.h> | ||
|
||
#ifdef HAVE_SYMENGINE_MPFR | ||
#include <mpfr.h> | ||
#endif // HAVE_SYMENGINE_MPFR | ||
|
||
#ifdef SYMENGINE_HAVE_MPC | ||
#include <mpc.h> | ||
#endif // HAVE_SYMENGINE_MPC | ||
|
||
namespace SymEngine | ||
{ | ||
|
||
/* | ||
* Evaluates basic b, according to the number of significant bits, and the | ||
* complex / real nature of the number | ||
*/ | ||
|
||
RCP<const Number> evalf(const Basic &b, unsigned long bits, bool real); | ||
|
||
} // SymEngine | ||
|
||
#endif // SYMENGINE_EVAL_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<mpc.h>
is already there in<symengine/complex_mpc.h>
. I am not sure if occurrences like these are removed.