7 #ifndef SYMENGINE_INTEGER_H
8 #define SYMENGINE_INTEGER_H
11 #include <symengine/symengine_exception.h>
12 #include <symengine/symengine_casts.h>
29 : i(_i){SYMENGINE_ASSIGN_TYPEID()}
Integer(integer_class && _i)
30 : i(std::move(_i)){SYMENGINE_ASSIGN_TYPEID()}
32 hash_t __hash__()
const override;
37 bool __eq__(
const Basic &o)
const override;
38 int compare(
const Basic &o)
const override;
41 signed long int as_int()
const;
43 unsigned long int as_uint()
const;
85 return make_rcp<const Integer>(this->i + other.
i);
90 return make_rcp<const Integer>(this->i - other.
i);
95 return make_rcp<const Integer>(this->i * other.
i);
98 RCP<const Number> divint(
const Integer &other)
const;
100 RCP<const Number> pow_negint(
const Integer &other)
const;
104 if (not(mp_fits_ulong_p(other.
i))) {
106 throw SymEngineException(
107 "powint: 'exp' does not fit unsigned long.");
109 return pow_negint(other);
112 mp_pow_ui(tmp, i, mp_get_ui(other.
i));
113 return make_rcp<const Integer>(std::move(tmp));
116 inline RCP<const Integer>
neg()
const
118 return make_rcp<const Integer>(-i);
124 RCP<const Number>
add(
const Number &other)
const override
126 if (is_a<Integer>(other)) {
127 return addint(down_cast<const Integer &>(other));
129 return other.
add(*
this);
133 RCP<const Number>
sub(
const Number &other)
const override
135 if (is_a<Integer>(other)) {
136 return subint(down_cast<const Integer &>(other));
138 return other.rsub(*
this);
142 RCP<const Number> rsub(
const Number &other)
const override
144 throw NotImplementedError(
"Not Implemented");
148 RCP<const Number>
mul(
const Number &other)
const override
150 if (is_a<Integer>(other)) {
151 return mulint(down_cast<const Integer &>(other));
153 return other.
mul(*
this);
157 RCP<const Number>
div(
const Number &other)
const override
159 if (is_a<Integer>(other)) {
160 return divint(down_cast<const Integer &>(other));
162 return other.rdiv(*
this);
166 RCP<const Number> rdiv(
const Number &other)
const override;
169 RCP<const Number>
pow(
const Number &other)
const override
171 if (is_a<Integer>(other)) {
172 return powint(down_cast<const Integer &>(other));
174 return other.rpow(*
this);
178 RCP<const Number> rpow(
const Number &other)
const override
180 throw NotImplementedError(
"Not Implemented");
188 const RCP<const Integer> &b)
const
190 return a->as_integer_class() < b->as_integer_class();
194 template <
typename T>
195 inline typename std::enable_if<std::is_integral<T>::value,
196 RCP<const Integer>>::type
199 return make_rcp<const Integer>(integer_class(i));
203 inline RCP<const Integer>
integer(integer_class i)
205 return make_rcp<const Integer>(std::move(i));
209 SYMENGINE_EXPORT RCP<const Integer>
isqrt(
const Integer &n);
212 int i_nth_root(
const Ptr<RCP<const Integer>> &r,
const Integer &a,
213 unsigned long int n);
219 SYMENGINE_EXPORT RCP<const Integer>
iabs(
const Integer &n);
#define IMPLEMENT_TYPEID(SYMENGINE_ID)
Inline members and functions.
RCP< const Number > div(const Number &other) const override
Slower Division.
RCP< const Number > mul(const Number &other) const override
Slower Multiplication.
RCP< const Integer > subint(const Integer &other) const
Fast Integer Subtraction.
RCP< const Number > add(const Number &other) const override
Slower Addition.
bool is_negative() const override
const integer_class & as_integer_class() const
Convert to integer_class.
RCP< const Number > sub(const Number &other) const override
Slower Subtraction.
RCP< const Integer > addint(const Integer &other) const
Fast Integer Addition.
bool is_positive() const override
bool is_minus_one() const override
bool is_one() const override
bool is_zero() const override
bool is_complex() const override
RCP< const Integer > neg() const
RCP< const Number > powint(const Integer &other) const
Fast Power Evaluation.
RCP< const Integer > mulint(const Integer &other) const
Fast Integer Multiplication.
RCP< const Number > pow(const Number &other) const override
Slower power evaluation.
integer_class i
i : object of integer_class
virtual RCP< const Number > mul(const Number &other) const =0
Multiplication.
virtual RCP< const Number > add(const Number &other) const =0
Addition.
Main namespace for SymEngine package.
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
int i_nth_root(const Ptr< RCP< const Integer >> &r, const Integer &a, unsigned long int n)
Integer nth root.
RCP< const Integer > isqrt(const Integer &n)
Integer Square root.
RCP< const Integer > iabs(const Integer &n)
Integer Absolute value.
bool perfect_square(const Integer &n)
Perfect Square.
bool perfect_power(const Integer &n)
Perfect Square.
less operator (<) for Integers
bool operator()(const RCP< const Integer > &a, const RCP< const Integer > &b) const