1 #ifndef STAN_MATH_PRIM_FUN_PROJ_HPP
2 #define STAN_MATH_PRIM_FUN_PROJ_HPP
3 
4 #include <stan/math/prim/fun/is_inf.hpp>
5 #include <complex>
6 #include <limits>
7 
8 namespace stan {
9 namespace math {
10 namespace internal {
11 /**
12  * Return the projection of the complex argument onto the Riemann
13  * sphere.
14  *
15  * @tparam V value type of argument
16  * @param[in] z argument
17  * @return projection of the argument onto the Riemann sphere
18  */
19 template <typename V>
complex_proj(const std::complex<V> & z)20 inline std::complex<V> complex_proj(const std::complex<V>& z) {
21   if (is_inf(z.real()) || is_inf(z.imag())) {
22     return {std::numeric_limits<V>::infinity(), z.imag() < 0 ? -0.0 : 0.0};
23   }
24   return z;
25 }
26 }  // namespace internal
27 }  // namespace math
28 }  // namespace stan
29 
30 #endif
31