7 bool ComplexBase::is_re_zero()
const
9 return this->real_part()->is_zero();
13 : real_{real}, imaginary_{imaginary}
15 SYMENGINE_ASSIGN_TYPEID()
20 const rational_class &imaginary)
const
22 rational_class re = real;
23 rational_class im = imaginary;
30 if (get_num(re) != get_num(real))
32 if (get_den(re) != get_den(real))
34 if (get_num(im) != get_num(imaginary))
36 if (get_den(im) != get_den(imaginary))
45 hash_t seed = SYMENGINE_COMPLEX;
46 hash_combine<long long int>(seed, mp_get_si(get_num(this->
real_)));
47 hash_combine<long long int>(seed, mp_get_si(get_den(this->
real_)));
48 hash_combine<long long int>(seed, mp_get_si(get_num(this->imaginary_)));
49 hash_combine<long long int>(seed, mp_get_si(get_den(this->imaginary_)));
55 if (is_a<Complex>(o)) {
56 const Complex &s = down_cast<const Complex &>(o);
58 and (this->imaginary_ == s.imaginary_));
65 SYMENGINE_ASSERT(is_a<Complex>(o))
66 const Complex &s = down_cast<const Complex &>(o);
68 if (imaginary_ == s.imaginary_) {
71 return imaginary_ < s.imaginary_ ? -1 : 1;
94 const rational_class im)
97 if (get_num(im) == 0) {
100 return make_rcp<const Complex>(re, im);
111 if (is_a<Integer>(re) and is_a<Integer>(im)) {
112 rational_class re_mpq(
113 down_cast<const Integer &>(re).as_integer_class(),
114 down_cast<const Integer &>(*one).as_integer_class());
115 rational_class im_mpq(
116 down_cast<const Integer &>(im).as_integer_class(),
117 down_cast<const Integer &>(*one).as_integer_class());
119 }
else if (is_a<Rational>(re) and is_a<Integer>(im)) {
120 rational_class re_mpq
121 = down_cast<const Rational &>(re).as_rational_class();
122 rational_class im_mpq(
123 down_cast<const Integer &>(im).as_integer_class(),
124 down_cast<const Integer &>(*one).as_integer_class());
126 }
else if (is_a<Integer>(re) and is_a<Rational>(im)) {
127 rational_class re_mpq(
128 down_cast<const Integer &>(re).as_integer_class(),
129 down_cast<const Integer &>(*one).as_integer_class());
130 rational_class im_mpq
131 = down_cast<const Rational &>(im).as_rational_class();
133 }
else if (is_a<Rational>(re) and is_a<Rational>(im)) {
134 rational_class re_mpq
135 = down_cast<const Rational &>(re).as_rational_class();
136 rational_class im_mpq
137 = down_cast<const Rational &>(im).as_rational_class();
140 throw SymEngineException(
141 "Invalid Format: Expected Integer or Rational");
145 RCP<const Number> pow_number(
const Complex &x,
unsigned long n)
147 unsigned long mask = 1;
148 rational_class r_re(1);
149 rational_class r_im(0);
151 rational_class p_re = x.
real_;
152 rational_class p_im = x.imaginary_;
159 tmp = r_re * p_re - r_im * p_im;
160 r_im = r_re * p_im + r_im * p_re;
164 if (not(mask > 0 and n >= mask)) {
168 tmp = p_re * p_re - p_im * p_im;
169 p_im = 2 * p_re * p_im;
177 if (this->is_re_zero()) {
181 RCP<const Number> res;
184 }
else if (rem == 1) {
186 }
else if (rem == 2) {
189 res =
mulnum(I, minus_one);
191 return mulnum(im->pow(other), res);
193 return pow_number(*
this, other.
as_int());
195 return one->div(*pow_number(*
this, -1 * other.
as_int()));
The lowest unit of symbolic representation.
Complex(rational_class real, rational_class imaginary)
Constructor of Complex class.
static RCP< const Number > from_mpq(const rational_class re, const rational_class im)
RCP< const Number > imaginary_part() const override
Get the imaginary part of the complex number.
RCP< const Basic > conjugate() const override
Get the conjugate of the complex number.
RCP< const Number > powcomp(const Integer &other) const
static RCP< const Number > from_two_rats(const Rational &re, const Rational &im)
bool is_canonical(const rational_class &real, const rational_class &imaginary) const
int compare(const Basic &o) const override
hash_t __hash__() const override
static RCP< const Number > from_two_nums(const Number &re, const Number &im)
bool __eq__(const Basic &o) const override
RCP< const Number > real_part() const override
Get the real part of the complex number.
bool is_positive() const override
signed long int as_int() const
Convert to int, raise an exception if it does not fit.
static RCP< const Number > from_mpq(const rational_class &i)
const rational_class & as_rational_class() const
Convert to rational_class.
Main namespace for SymEngine package.
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
RCP< const Number > mulnum(const RCP< const Number > &self, const RCP< const Number > &other)
Multiply self and other
RCP< const Integer > mod_f(const Integer &n, const Integer &d)
modulo round toward -inf