Automatic Differentiation
 
Loading...
Searching...
No Matches
polar.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_POLAR_HPP
2#define STAN_MATH_PRIM_FUN_POLAR_HPP
3
7#include <cmath>
8#include <complex>
9#include <limits>
10
11namespace stan {
12namespace math {
13namespace internal {
21template <typename U, typename V>
22inline complex_return_t<U, V> complex_polar(const U& r, const V& theta) {
23 using std::cos;
24 using std::sin;
25 if (!(r >= 0) || is_inf(theta)) {
26 return {std::numeric_limits<double>::quiet_NaN()};
27 }
28 return {r * cos(theta), r * sin(theta)};
29}
30} // namespace internal
31
39inline std::complex<double> polar(double r, double theta) {
40 return internal::complex_polar(r, theta);
41}
42inline std::complex<double> polar(double r, int theta) {
43 return internal::complex_polar(r, static_cast<double>(theta));
44}
45inline std::complex<double> polar(int r, double theta) {
46 return internal::complex_polar(static_cast<double>(r), theta);
47}
48inline std::complex<double> polar(int r, int theta) {
49 return internal::complex_polar(static_cast<double>(r),
50 static_cast<double>(theta));
51}
52
53} // namespace math
54} // namespace stan
55
56#endif
std::complex< real_return_t< Ts... > > complex_return_t
Convenience type to calculate the complex return type, which wraps std::complex around the return typ...
complex_return_t< U, V > complex_polar(const U &r, const V &theta)
Returns complex number with specified magnitude and phase angle.
Definition polar.hpp:22
fvar< T > sin(const fvar< T > &x)
Definition sin.hpp:14
std::complex< fvar< T > > polar(const fvar< T > &r, const fvar< T > &theta)
Returns complex number with specified magnitude and phase angle.
Definition polar.hpp:22
fvar< T > cos(const fvar< T > &x)
Definition cos.hpp:14
int is_inf(const fvar< T > &x)
Returns 1 if the input's value is infinite and 0 otherwise.
Definition is_inf.hpp:21
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...