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
8#include <cmath>
9#include <complex>
10#include <limits>
11
12namespace stan {
13namespace math {
14namespace internal {
22template <typename U, typename V>
23inline complex_return_t<U, V> complex_polar(const U& r, const V& theta) {
24 if (!(r >= 0) || is_inf(theta)) {
25 return {std::numeric_limits<double>::quiet_NaN()};
26 }
27 return {r * cos(theta), r * sin(theta)};
28}
29} // namespace internal
30
38template <typename U, typename V, require_all_arithmetic_t<U, V>* = nullptr>
39inline std::complex<double> polar(U r, V theta) {
40 return internal::complex_polar(static_cast<double>(r),
41 static_cast<double>(theta));
42}
43
44} // namespace math
45} // namespace stan
46
47#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:23
fvar< T > sin(const fvar< T > &x)
Definition sin.hpp:16
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:25
fvar< T > cos(const fvar< T > &x)
Definition cos.hpp:16
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 ...