complex_double.cpp
1 
6 #include <symengine/complex_double.h>
7 
8 namespace SymEngine
9 {
10 
12 {
13  SYMENGINE_ASSIGN_TYPEID()
14  this->i = i;
15 }
17 RCP<const Number> ComplexDouble::real_part() const
18 {
19  return real_double(i.real());
20 }
22 RCP<const Number> ComplexDouble::imaginary_part() const
23 {
24  return real_double(i.imag());
25 }
27 RCP<const Basic> ComplexDouble::conjugate() const
28 {
29  double re = i.real();
30  double im = -i.imag();
31  return complex_double(std::complex<double>(re, im));
32 }
34 {
35  hash_t seed = SYMENGINE_COMPLEX_DOUBLE;
36  hash_combine<double>(seed, i.real());
37  hash_combine<double>(seed, i.imag());
38  return seed;
39 }
40 
41 bool ComplexDouble::__eq__(const Basic &o) const
42 {
43  if (is_a<ComplexDouble>(o)) {
44  const ComplexDouble &s = down_cast<const ComplexDouble &>(o);
45  return this->i == s.i;
46  }
47  return false;
48 }
49 
50 int ComplexDouble::compare(const Basic &o) const
51 {
52  SYMENGINE_ASSERT(is_a<ComplexDouble>(o))
53  const ComplexDouble &s = down_cast<const ComplexDouble &>(o);
54  if (i == s.i)
55  return 0;
56  if (i.real() == s.i.real()) {
57  return i.imag() < s.i.imag() ? -1 : 1;
58  }
59  return i.real() < s.i.real() ? -1 : 1;
60 }
61 
62 RCP<const ComplexDouble> complex_double(std::complex<double> x)
63 {
64  return make_rcp<const ComplexDouble>(x);
65 }
66 
67 RCP<const ComplexDouble> complex_double(double real, double imag)
68 {
69  return make_rcp<const ComplexDouble>(std::complex<double>(real, imag));
70 }
71 
72 } // namespace SymEngine
The lowest unit of symbolic representation.
Definition: basic.h:97
Complex Double Class to hold std::complex<double> values.
bool __eq__(const Basic &o) const override
int compare(const Basic &o) const override
RCP< const Basic > conjugate() const override
Get the conjugate of the complex number.
hash_t __hash__() const override
RCP< const Number > real_part() const override
Get the real part of the complex number.
ComplexDouble(std::complex< double > i)
Constructor of ComplexDouble class.
RCP< const Number > imaginary_part() const override
Get the imaginary part of the complex number.
T imag(T... args)
Main namespace for SymEngine package.
Definition: add.cpp:19
T real(T... args)