Class Rational

Inheritance Relationships

Base Type

Class Documentation

class SymEngine::Rational : public SymEngine::Number

Rational Class.

Public Functions

Rational(rational_class &&_i)

Constructor of Rational class.

hash_t __hash__() const

Return

size of the hash

bool __eq__(const Basic &o) const

Equality comparator

Return

whether the 2 objects are equal

Parameters
  • o: - Object to be compared with

int compare(const Basic &o) const

Returns -1, 0, 1 for this < o, this == o, this > o. This method is used when you want to sort things like x+y+z into canonical order. This function assumes that o is the same type as this. Use __cmp__ if you want general comparison.

bool is_canonical(const rational_class &i) const

Return

true if canonical

const rational_class &as_rational_class() const

Convert to rational_class.

bool is_zero() const

Return

true if 0

bool is_one() const

Return

true if 1

bool is_minus_one() const

Return

true if -1

bool is_int() const

Return

true if denominator is 1

bool is_positive() const

Return

true if positive

bool is_negative() const

Return

true if negative

bool is_complex() const

Return

false

RCP<const Rational> neg() const

Return

negative of this

bool is_perfect_power(bool is_expected = false) const
bool nth_root(const Ptr<RCP<const Number>>&, unsigned long n) const
RCP<const Number> addrat(const Rational &other) const

Add Rationals

Parameters

RCP<const Number> addrat(const Integer &other) const

Add Rationals

Parameters

RCP<const Number> subrat(const Rational &other) const

Subtract Rationals

Parameters

RCP<const Number> subrat(const Integer &other) const

Subtract Rationals

Parameters

RCP<const Number> rsubrat(const Integer &other) const
RCP<const Number> mulrat(const Rational &other) const

Multiply Rationals

Parameters

RCP<const Number> mulrat(const Integer &other) const

Multiply Rationals

Parameters

RCP<const Number> divrat(const Rational &other) const

Divide Rationals

Parameters

RCP<const Number> divrat(const Integer &other) const

Divide Rationals

Parameters

RCP<const Number> rdivrat(const Integer &other) const
RCP<const Number> powrat(const Integer &other) const

Raise Rationals to power other

Parameters
  • other: power to be raised

RCP<const Basic> powrat(const Rational &other) const

Raise *this to power other

Parameters
  • other: exponent

RCP<const Basic> rpowrat(const Integer &other) const

Reverse powrat Raise ‘other’ to power *this

Parameters
  • other: base

RCP<const Number> add(const Number &other) const

Converts the param other appropriately and then calls addrat

RCP<const Number> sub(const Number &other) const

Converts the param other appropriately and then calls subrat

RCP<const Number> rsub(const Number &other) const

Converts the param other appropriately and then calls rsubrat

RCP<const Number> mul(const Number &other) const

Converts the param other appropriately and then calls mulrat

RCP<const Number> div(const Number &other) const

Converts the param other appropriately and then calls divrat

RCP<const Number> rdiv(const Number &other) const

Converts the param other appropriately and then calls rdivrat

RCP<const Number> pow(const Number &other) const

Converts the param other appropriately and then calls powrat

RCP<const Number> rpow(const Number &other) const
RCP<const Integer> get_num() const
RCP<const Integer> get_den() const

Public Static Functions

RCP<const Number> from_mpq(const rational_class &i)

Return

Integer or Rational depending on denumerator.

Parameters
  • <tt>i</tt>: must already be in rational_class canonical form

RCP<const Number> from_mpq(rational_class &&i)
RCP<const Number> from_two_ints(const Integer &n, const Integer &d)

Constructs Rational as n/d, where n, d can be any Integers. If n/d is an Integer, it will return an Integer instead.

RCP<const Number> from_two_ints(const long n, const long d)