-
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
[WIP] Wrappers for Real MPFR and Complex MPC #972
Changes from 6 commits
2da29b6
71b0aff
abba2a0
2e9ccd7
52ff18a
db49b4f
5408fb2
a05bd15
b7565d5
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 |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
#include <symengine/number.h> | ||
#include <symengine/complex.h> | ||
#include <symengine/complex_double.h> | ||
#include <symengine/real_mpfr.h> | ||
#include <symengine/complex_mpc.h> | ||
#include <symengine/constants.h> | ||
#include <symengine/visitor.h> | ||
#include <symengine/printer.h> | ||
|
@@ -32,6 +34,13 @@ using SymEngine::Number; | |
using SymEngine::Complex; | ||
using SymEngine::ComplexDouble; | ||
using SymEngine::RealDouble; | ||
#ifdef HAVE_SYMENGINE_MPFR | ||
using SymEngine::RealMPFR; | ||
using SymEngine::mpfr_class; | ||
#endif //HAVE_SYMENGINE_MPFR | ||
#ifdef HAVE_SYMENGINE_MPC | ||
using SymEngine::ComplexMPC; | ||
#endif //HAVE_SYMENGINE_MPC | ||
using SymEngine::rcp_static_cast; | ||
using SymEngine::is_a; | ||
using SymEngine::RCPBasicKeyLess; | ||
|
@@ -200,6 +209,45 @@ double real_double_get_d(const basic s) | |
return (rcp_static_cast<const RealDouble>(s->m))->as_double(); | ||
} | ||
|
||
#ifdef HAVE_SYMENGINE_MPFR | ||
|
||
void real_mpfr_set_d(basic s, double d, int prec) | ||
{ | ||
mpfr_class mc = mpfr_class(prec); | ||
mpfr_set_d (mc.get_mpfr_t(), d, MPFR_RNDN); | ||
s->m = SymEngine::real_mpfr(std::move(mc)); | ||
} | ||
|
||
void real_mpfr_set_str(basic s, char *c, int prec) | ||
{ | ||
s->m = SymEngine::real_mpfr(mpfr_class(c, prec, 10)); | ||
} | ||
|
||
double real_mpfr_get_d(const basic s) | ||
{ | ||
SYMENGINE_ASSERT(is_a<RealMPFR>(*(s->m))); | ||
return mpfr_get_d ( ((rcp_static_cast<const RealMPFR>(s->m))->as_mpfr()).get_mpfr_t() , MPFR_RNDN); | ||
} | ||
|
||
void real_mpfr_set(basic s, mpfr_srcptr m) | ||
{ | ||
s->m = SymEngine::real_mpfr(mpfr_class(m)); | ||
} | ||
|
||
void real_mpfr_get(mpfr_ptr m, const basic s) | ||
{ | ||
SYMENGINE_ASSERT(is_a<RealMPFR>(*(s->m))); | ||
m = ((rcp_static_cast<const RealMPFR>(s->m))->as_mpfr()).get_mpfr_t(); | ||
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. Use |
||
} | ||
|
||
mpfr_prec_t real_mpfr_get_prec(const basic s) | ||
{ | ||
SYMENGINE_ASSERT(is_a<RealMPFR>(*(s->m))); | ||
return ((rcp_static_cast<const RealMPFR>(s->m))->as_mpfr()).get_prec(); | ||
} | ||
|
||
#endif // HAVE_SYMENGINE_MPFR | ||
|
||
signed long integer_get_si(const basic s) | ||
{ | ||
SYMENGINE_ASSERT(is_a<Integer>(*(s->m))); | ||
|
@@ -410,6 +458,22 @@ int is_a_ComplexDouble(const basic c) | |
{ | ||
return is_a<ComplexDouble>(*(c->m)); | ||
} | ||
int is_a_RealMPFR(const basic c) | ||
{ | ||
#ifdef HAVE_SYMENGINE_MPFR | ||
return is_a<RealMPFR>(*(c->m)); | ||
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. This should return false if |
||
#else | ||
return false; | ||
#endif // HAVE_SYMENGINE_MPFR | ||
} | ||
int is_a_ComplexMPC(const basic c) | ||
{ | ||
#ifdef HAVE_SYMENGINE_MPC | ||
return is_a<ComplexMPC>(*(c->m)); | ||
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. This should return false if |
||
#else | ||
return false; | ||
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. Use an |
||
#endif // HAVE_SYMENGINE_MPC | ||
} | ||
|
||
// C wrapper for std::vector<int> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ | |
#include <stdlib.h> | ||
#include <gmp.h> | ||
|
||
#ifdef 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. You should include |
||
#include <mpfr.h> | ||
#endif // HAVE_SYMENGINE_MPFR | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
@@ -129,6 +133,21 @@ void real_double_set_d(basic s, double d); | |
//! Returns double value of s. | ||
double real_double_get_d(const basic s); | ||
|
||
#ifdef HAVE_SYMENGINE_MPFR | ||
//! Assign to s, a real mpfr that has value d with precision prec. | ||
void real_mpfr_set_d(basic s, double d, int prec); | ||
//! Assign to s, a real mpfr that has base 10 representation c with precision prec. | ||
void real_mpfr_set_str(basic s, char *c, int prec); | ||
//! Returns double value of s. | ||
double real_mpfr_get_d(const basic s); | ||
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. For completeness, you'll need,
|
||
//! Assign to s, a real mpfr that has value pointed by m. | ||
void real_mpfr_set(basic s, mpfr_srcptr m); | ||
//! Assign to m, the mpfr_t given in s. | ||
void real_mpfr_get(mpfr_ptr m, const basic s); | ||
//! Returns the precision of the mpfr_t given by s. | ||
mpfr_prec_t real_mpfr_get_prec(const basic s); | ||
#endif // HAVE_SYMENGINE_MPFR | ||
|
||
//! Returns signed long value of s. | ||
signed long integer_get_si(const basic s); | ||
//! Returns unsigned long value of s. | ||
|
@@ -264,6 +283,14 @@ int is_a_Rational(const basic s); | |
int is_a_Symbol(const basic s); | ||
//! Return 1 if s is a Complex, 0 if not. | ||
int is_a_Complex(const basic s); | ||
//! Return 1 if s is a RealDouble, 0 if not. | ||
int is_a_RealDouble(const basic c); | ||
//! Return 1 if s is a ComplexDouble, 0 if not. | ||
int is_a_ComplexDouble(const basic c); | ||
//! Return 1 if s is a RealMPFR, 0 if not. | ||
int is_a_RealMPFR(const basic c); | ||
//! Return 1 if s is a ComplexMPC, 0 if not. | ||
int is_a_ComplexMPC(const basic c); | ||
|
||
//! Wrapper for std::vector<int> | ||
|
||
|
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.
Same here