1 #ifndef STAN_MATH_PRIM_FUN_POW_HPP
2 #define STAN_MATH_PRIM_FUN_POW_HPP
3
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/fun/constants.hpp>
6 #include <stan/math/prim/functor/apply_scalar_binary.hpp>
7 #include <cmath>
8 #include <complex>
9
10 namespace stan {
11 namespace math {
12
13 namespace internal {
14
15 /**
16 * Return the first argument raised to the power of the second
17 * argument. At least one of the arguments must be a complex number.
18 *
19 * @tparam U type of base
20 * @tparam V type of exponent
21 * @param[in] x base
22 * @param[in] y exponent
23 * @return base raised to the power of the exponent
24 */
25 template <typename U, typename V>
complex_pow(const U & x,const V & y)26 inline complex_return_t<U, V> complex_pow(const U& x, const V& y) {
27 return exp(y * log(x));
28 }
29 } // namespace internal
30
31 /**
32 * Enables the vectorised application of the pow function, when
33 * the first and/or second arguments are containers.
34 *
35 * @tparam T1 type of first input
36 * @tparam T2 type of second input
37 * @param a First input
38 * @param b Second input
39 * @return pow function applied to the two inputs.
40 */
41 template <typename T1, typename T2, require_any_container_t<T1, T2>* = nullptr>
pow(const T1 & a,const T2 & b)42 inline auto pow(const T1& a, const T2& b) {
43 return apply_scalar_binary(a, b, [&](const auto& c, const auto& d) {
44 using std::pow;
45 return pow(c, d);
46 });
47 }
48 } // namespace math
49 } // namespace stan
50 #endif
51