Loading...
Searching...
No Matches
complex_double.cpp
1
6#include <symengine/complex_double.h>
7
8namespace SymEngine
9{
10
12{
13 SYMENGINE_ASSIGN_TYPEID()
14 this->i = i;
15}
17RCP<const Number> ComplexDouble::real_part() const
18{
19 return real_double(i.real());
20}
22RCP<const Number> ComplexDouble::imaginary_part() const
23{
24 return real_double(i.imag());
25}
27RCP<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
41bool 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
50int 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
62RCP<const ComplexDouble> complex_double(std::complex<double> x)
63{
64 return make_rcp<const ComplexDouble>(x);
65}
66
67} // namespace SymEngine
The lowest unit of symbolic representation.
Definition: basic.h:97
Complex Double Class to hold std::complex<double> values.
virtual hash_t __hash__() const
virtual int compare(const Basic &o) const
virtual RCP< const Number > real_part() const
Get the real part of the complex number.
virtual RCP< const Number > imaginary_part() const
Get the imaginary part of the complex number.
ComplexDouble(std::complex< double > i)
Constructor of ComplexDouble class.
virtual RCP< const Basic > conjugate() const
Get the conjugate of the complex number.
virtual bool __eq__(const Basic &o) const
T imag(T... args)
Main namespace for SymEngine package.
Definition: add.cpp:19
T real(T... args)