1 #ifndef STAN_MATH_PRIM_SCAL_FUN_I_TIMES_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_I_TIMES_HPP
3 
4 #include <complex>
5 
6 namespace stan {
7 namespace math {
8 
9 /**
10  * Return the specified complex number multiplied by `i`.
11  *
12  * This compound function is more efficient than mulitplying by a
13  * constant `i` because it involves only a single arithmetic negation.
14  *
15  * @tparam value type of complex argument
16  * @param[in] z complex argument
17  * @return argument multipled by `i`
18  */
19 template <typename T>
i_times(const std::complex<T> & z)20 inline std::complex<T> i_times(const std::complex<T>& z) {
21   return {-z.imag(), z.real()};
22 }
23 
24 /**
25  * Return the specified complex number multiplied by `-i`.
26  *
27  * This compound function is more efficient than mulitplying by the
28  * constant `-i` because it involves only a single arithmetic
29  * negation.
30  *
31  * @tparam value type of complex argument
32  * @param[in] z complex argument
33  * @return argument multipled by `-i`
34  */
35 template <typename T>
neg_i_times(const std::complex<T> & z)36 inline std::complex<T> neg_i_times(const std::complex<T>& z) {
37   return {z.imag(), -z.real()};
38 }
39 
40 /**
41  * Return the complex negation of the specified complex argument.
42  *
43  * @tparam V value type of complex argument
44  * @param[in] z argument
45  * @return negation of argument
46  */
47 template <typename V>
complex_negate(const std::complex<V> & z)48 inline std::complex<V> complex_negate(const std::complex<V>& z) {
49   return {-z.real(), -z.imag()};
50 }
51 
52 }  // namespace math
53 }  // namespace stan
54 
55 #endif
56