6#ifndef SYMENGINE_RATIONAL_H
7#define SYMENGINE_RATIONAL_H
10#include <symengine/symengine_exception.h>
26 SYMENGINE_ASSIGN_TYPEID()
31 static RCP<const Number>
from_mpq(
const rational_class &
i);
32 static RCP<const Number>
from_mpq(rational_class &&
i);
48 static RCP<const Number>
from_two_ints(
const long n,
const long d);
97 bool is_perfect_power(
bool is_expected =
false)
const override;
99 bool nth_root(
const Ptr<RCP<const Number>> &,
100 unsigned long n)
const override;
130 inline RCP<const Number> rsubrat(
const Integer &
other)
const
168 if (
other.as_integer_class() == 0) {
178 inline RCP<const Number> rdivrat(
const Integer &
other)
const
181 if (
other.is_zero()) {
196 integer_class exp_ =
other.as_integer_class();
199 if (
not mp_fits_ulong_p(exp_))
200 throw SymEngineException(
"powrat: 'exp' does not fit ulong.");
201 unsigned long exp = mp_get_ui(exp_);
203#if SYMENGINE_INTEGER_CLASS == SYMENGINE_BOOSTMP
208 mp_pow_ui(
num, SymEngine::get_num(
i),
exp);
209 mp_pow_ui(
den, SymEngine::get_den(
i),
exp);
213 mp_pow_ui(SymEngine::get_num(
val), SymEngine::get_num(
i),
exp);
214 mp_pow_ui(SymEngine::get_den(
val), SymEngine::get_den(
i),
exp);
243 return other.add(*
this);
254 return other.rsub(*
this);
274 return other.mul(*
this);
285 return other.rdiv(*
this);
303 return other.rpow(*
this);
307 RCP<const Number> rpow(
const Number &
other)
const override
314 return integer(SymEngine::get_num(
i));
319 return integer(SymEngine::get_den(
i));
#define IMPLEMENT_TYPEID(SYMENGINE_ID)
Inline members and functions.
The lowest unit of symbolic representation.
bool is_positive() const override
RCP< const Basic > rpowrat(const Integer &other) const
static RCP< const Number > from_mpq(const rational_class &i)
bool is_minus_one() const override
RCP< const Number > divrat(const Integer &other) const
RCP< const Number > addrat(const Integer &other) const
hash_t __hash__() const override
RCP< const Number > addrat(const Rational &other) const
RCP< const Number > mulrat(const Rational &other) const
int compare(const Basic &o) const override
RCP< const Number > div(const Number &other) const override
Converts the param other appropriately and then calls divrat
bool is_complex() const override
rational_class i
i : object of rational_class
RCP< const Number > mul(const Number &other) const override
Converts the param other appropriately and then calls mulrat
bool is_zero() const override
RCP< const Number > rsub(const Number &other) const override
Converts the param other appropriately and then calls rsubrat
RCP< const Number > powrat(const Integer &other) const
RCP< const Number > pow(const Number &other) const override
Converts the param other appropriately and then calls powrat
RCP< const Number > subrat(const Integer &other) const
const rational_class & as_rational_class() const
Convert to rational_class.
static RCP< const Number > from_two_ints(const Integer &n, const Integer &d)
RCP< const Number > add(const Number &other) const override
Converts the param other appropriately and then calls addrat
RCP< const Number > sub(const Number &other) const override
Converts the param other appropriately and then calls subrat
bool is_canonical(const rational_class &i) const
RCP< const Number > rdiv(const Number &other) const override
Converts the param other appropriately and then calls rdivrat
RCP< const Number > mulrat(const Integer &other) const
bool is_one() const override
RCP< const Rational > neg() const
bool __eq__(const Basic &o) const override
RCP< const Number > subrat(const Rational &other) const
bool is_negative() const override
RCP< const Number > divrat(const Rational &other) const
Main namespace for SymEngine package.
void hash_combine(hash_t &seed, const T &v)
RCP< const Basic > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)
void get_num_den(const Rational &rat, const Ptr< RCP< const Integer > > &num, const Ptr< RCP< const Integer > > &den)
returns the num and den of rational rat as RCP<const Integer>
RCP< const Number > rational(long n, long d)
convenience creator from two longs
std::enable_if< std::is_integral< T >::value, RCP< constInteger > >::type integer(T i)