6 #include <symengine/complex_double.h>
14 SYMENGINE_ASSIGN_TYPEID()
20 hash_t seed = SYMENGINE_REAL_DOUBLE;
21 hash_combine<double>(seed, i);
27 if (is_a<RealDouble>(o)) {
28 const RealDouble &s = down_cast<const RealDouble &>(o);
29 return this->i == s.i;
36 SYMENGINE_ASSERT(is_a<RealDouble>(o))
37 const RealDouble &s = down_cast<const RealDouble &>(o);
40 return i < s.i ? -1 : 1;
43 RCP<const RealDouble> real_double(
double x)
45 return make_rcp<const RealDouble>(x);
50 return complex_double(x);
53 RCP<const Number> number(
double x)
55 return real_double(x);
62 RCP<const Basic> sin(
const Basic &x)
const override
64 SYMENGINE_ASSERT(is_a<T>(x))
65 return number(
std::sin(down_cast<const T &>(x).i));
67 RCP<const Basic> cos(
const Basic &x)
const override
69 SYMENGINE_ASSERT(is_a<T>(x))
70 return number(
std::cos(down_cast<const T &>(x).i));
72 RCP<const Basic> tan(
const Basic &x)
const override
74 SYMENGINE_ASSERT(is_a<T>(x))
75 return number(
std::tan(down_cast<const T &>(x).i));
77 RCP<const Basic> cot(
const Basic &x)
const override
79 SYMENGINE_ASSERT(is_a<T>(x))
80 return number(1.0 /
std::tan(down_cast<const T &>(x).i));
82 RCP<const Basic> sec(
const Basic &x)
const override
84 SYMENGINE_ASSERT(is_a<T>(x))
85 return number(1.0 /
std::cos(down_cast<const T &>(x).i));
87 RCP<const Basic> csc(
const Basic &x)
const override
89 SYMENGINE_ASSERT(is_a<T>(x))
90 return number(1.0 /
std::sin(down_cast<const T &>(x).i));
92 RCP<const Basic> atan(
const Basic &x)
const override
94 SYMENGINE_ASSERT(is_a<T>(x))
95 return number(
std::atan(down_cast<const T &>(x).i));
97 RCP<const Basic> acot(
const Basic &x)
const override
99 SYMENGINE_ASSERT(is_a<T>(x))
100 return number(
std::atan(1.0 / down_cast<const T &>(x).i));
102 RCP<const Basic> sinh(
const Basic &x)
const override
104 SYMENGINE_ASSERT(is_a<T>(x))
105 return number(
std::sinh(down_cast<const T &>(x).i));
107 RCP<const Basic> csch(
const Basic &x)
const override
109 SYMENGINE_ASSERT(is_a<T>(x))
110 return number(1.0 /
std::sinh(down_cast<const T &>(x).i));
112 RCP<const Basic> cosh(
const Basic &x)
const override
114 SYMENGINE_ASSERT(is_a<T>(x))
115 return number(
std::cosh(down_cast<const T &>(x).i));
117 RCP<const Basic> sech(
const Basic &x)
const override
119 SYMENGINE_ASSERT(is_a<T>(x))
120 return number(1.0 /
std::cosh(down_cast<const T &>(x).i));
122 RCP<const Basic> tanh(
const Basic &x)
const override
124 SYMENGINE_ASSERT(is_a<T>(x))
125 return number(
std::tanh(down_cast<const T &>(x).i));
127 RCP<const Basic> coth(
const Basic &x)
const override
129 SYMENGINE_ASSERT(is_a<T>(x))
130 return number(1.0 /
std::tanh(down_cast<const T &>(x).i));
132 RCP<const Basic> asinh(
const Basic &x)
const override
134 SYMENGINE_ASSERT(is_a<T>(x))
135 return number(
std::asinh(down_cast<const T &>(x).i));
137 RCP<const Basic> acsch(
const Basic &x)
const override
139 SYMENGINE_ASSERT(is_a<T>(x))
140 return number(
std::asinh(1.0 / down_cast<const T &>(x).i));
142 RCP<const Basic> abs(
const Basic &x)
const override
144 SYMENGINE_ASSERT(is_a<T>(x))
145 return number(std::abs(down_cast<const T &>(x).i));
147 RCP<const Basic> exp(
const Basic &x)
const override
149 SYMENGINE_ASSERT(is_a<T>(x))
150 return number(
std::exp(down_cast<const T &>(x).i));
156 RCP<const Basic> gamma(
const Basic &x)
const override
158 SYMENGINE_ASSERT(is_a<RealDouble>(x))
159 return number(
std::tgamma(down_cast<const RealDouble &>(x).i));
161 RCP<const Basic> asin(
const Basic &x)
const override
163 SYMENGINE_ASSERT(is_a<RealDouble>(x))
164 double d = down_cast<const RealDouble &>(x).i;
165 if (d <= 1.0 and d >= -1.0) {
171 RCP<const Basic> acos(
const Basic &x)
const override
173 SYMENGINE_ASSERT(is_a<RealDouble>(x))
174 double d = down_cast<const RealDouble &>(x).i;
175 if (d <= 1.0 and d >= -1.0) {
181 RCP<const Basic> acsc(
const Basic &x)
const override
183 SYMENGINE_ASSERT(is_a<RealDouble>(x))
184 double d = down_cast<const RealDouble &>(x).i;
185 if (d >= 1.0 or d <= -1.0) {
191 RCP<const Basic> asec(
const Basic &x)
const override
193 SYMENGINE_ASSERT(is_a<RealDouble>(x))
194 double d = down_cast<const RealDouble &>(x).i;
195 if (d >= 1.0 or d <= -1.0) {
201 RCP<const Basic> acosh(
const Basic &x)
const override
203 SYMENGINE_ASSERT(is_a<RealDouble>(x))
204 double d = down_cast<const RealDouble &>(x).i;
211 RCP<const Basic> atanh(
const Basic &x)
const override
213 SYMENGINE_ASSERT(is_a<RealDouble>(x))
214 double d = down_cast<const RealDouble &>(x).i;
215 if (d <= 1.0 and d >= -1.0) {
221 RCP<const Basic> acoth(
const Basic &x)
const override
223 SYMENGINE_ASSERT(is_a<RealDouble>(x))
224 double d = down_cast<const RealDouble &>(x).i;
225 if (d >= 1.0 or d <= -1.0) {
231 RCP<const Basic> asech(
const Basic &x)
const override
233 SYMENGINE_ASSERT(is_a<RealDouble>(x))
234 double d = down_cast<const RealDouble &>(x).i;
235 if (d <= 1.0 and d >= 0.0) {
241 RCP<const Basic> log(
const Basic &x)
const override
243 SYMENGINE_ASSERT(is_a<RealDouble>(x))
244 double d = down_cast<const RealDouble &>(x).i;
251 RCP<const Basic> floor(
const Basic &x)
const override
253 SYMENGINE_ASSERT(is_a<RealDouble>(x))
255 mp_set_d(i,
std::floor(down_cast<const RealDouble &>(x).i));
258 RCP<const Basic> ceiling(
const Basic &x)
const override
260 SYMENGINE_ASSERT(is_a<RealDouble>(x))
262 mp_set_d(i,
std::ceil(down_cast<const RealDouble &>(x).i));
265 RCP<const Basic> truncate(
const Basic &x)
const override
267 SYMENGINE_ASSERT(is_a<RealDouble>(x))
269 mp_set_d(i,
std::trunc(down_cast<const RealDouble &>(x).i));
272 RCP<const Basic> erf(
const Basic &x)
const override
274 SYMENGINE_ASSERT(is_a<RealDouble>(x))
275 return number(
std::erf(down_cast<const RealDouble &>(x).i));
277 RCP<const Basic> erfc(
const Basic &x)
const override
279 SYMENGINE_ASSERT(is_a<RealDouble>(x))
280 return number(
std::erfc(down_cast<const RealDouble &>(x).i));
286 RCP<const Basic> gamma(
const Basic &x)
const override
288 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
289 throw NotImplementedError(
"Not Implemented.");
291 RCP<const Basic> asin(
const Basic &x)
const override
293 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
294 return number(
std::asin(down_cast<const ComplexDouble &>(x).i));
296 RCP<const Basic> acos(
const Basic &x)
const override
298 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
299 return number(
std::acos(down_cast<const ComplexDouble &>(x).i));
301 RCP<const Basic> acsc(
const Basic &x)
const override
303 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
304 return number(
std::asin(1.0 / down_cast<const ComplexDouble &>(x).i));
306 RCP<const Basic> asec(
const Basic &x)
const override
308 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
309 return number(
std::acos(1.0 / down_cast<const ComplexDouble &>(x).i));
311 RCP<const Basic> acosh(
const Basic &x)
const override
313 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
314 return number(
std::acosh(down_cast<const ComplexDouble &>(x).i));
316 RCP<const Basic> atanh(
const Basic &x)
const override
318 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
319 return number(
std::atanh(down_cast<const ComplexDouble &>(x).i));
321 RCP<const Basic> acoth(
const Basic &x)
const override
323 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
324 return number(
std::atanh(1.0 / down_cast<const ComplexDouble &>(x).i));
326 RCP<const Basic> asech(
const Basic &x)
const override
328 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
329 return number(
std::acosh(1.0 / down_cast<const ComplexDouble &>(x).i));
331 RCP<const Basic> log(
const Basic &x)
const override
333 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
334 return number(
std::log(down_cast<const ComplexDouble &>(x).i));
336 RCP<const Basic> floor(
const Basic &x)
const override
338 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
339 integer_class re, im;
340 mp_set_d(re,
std::floor(down_cast<const ComplexDouble &>(x).i.real()));
341 mp_set_d(im,
std::floor(down_cast<const ComplexDouble &>(x).i.imag()));
345 RCP<const Basic> ceiling(
const Basic &x)
const override
347 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
348 integer_class re, im;
349 mp_set_d(re,
std::ceil(down_cast<const ComplexDouble &>(x).i.real()));
350 mp_set_d(im,
std::ceil(down_cast<const ComplexDouble &>(x).i.imag()));
354 RCP<const Basic> truncate(
const Basic &x)
const override
356 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
357 integer_class re, im;
358 mp_set_d(re,
std::trunc(down_cast<const ComplexDouble &>(x).i.real()));
359 mp_set_d(im,
std::trunc(down_cast<const ComplexDouble &>(x).i.imag()));
363 RCP<const Basic> erf(
const Basic &x)
const override
365 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
366 throw NotImplementedError(
"erf is not implemented for Complex numbers");
368 RCP<const Basic> erfc(
const Basic &x)
const override
370 SYMENGINE_ASSERT(is_a<ComplexDouble>(x))
371 throw NotImplementedError(
372 "erfc is not implemented for Complex numbers");
379 return evaluate_real_double;
385 return evaluate_complex_double;
The lowest unit of symbolic representation.
Evaluate & get_eval() const override
Get Evaluate singleton to evaluate numerically.
static RCP< const Number > from_two_nums(const Number &re, const Number &im)
Evaluate functions with double precision.
A class that will evaluate functions numerically.
RealDouble Class to hold double values.
hash_t __hash__() const override
Evaluate & get_eval() const override
Get Evaluate singleton to evaluate numerically.
bool __eq__(const Basic &o) const override
int compare(const Basic &o) const override
RealDouble(double i)
Constructor of RealDouble class.
Main namespace for SymEngine package.
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)