1 #ifndef STAN_MATH_PRIM_FUN_LDEXP_HPP
2 #define STAN_MATH_PRIM_FUN_LDEXP_HPP
3
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/functor/apply_scalar_binary.hpp>
6 #include <cmath>
7
8 namespace stan {
9 namespace math {
10
11 /**
12 * Returns the product of a (the significand) and
13 * 2 to power b (the exponent).
14 *
15 * @tparam T1 scalar type of significand
16 * @param[in] a the significand
17 * @param[in] b an integer that is the exponent
18 * @return product of a times 2 to the power b
19 */
20 template <typename T1, require_arithmetic_t<T1>* = nullptr>
ldexp(T1 a,int b)21 inline double ldexp(T1 a, int b) {
22 using std::ldexp;
23 return ldexp(a, b);
24 }
25
26 /**
27 * Enables the vectorised application of the ldexp function,
28 * when the first and/or second arguments are containers.
29 *
30 * @tparam T1 type of first input
31 * @tparam T2 type of second input
32 * @param a First input
33 * @param b Second input
34 * @return ldexp function applied to the two inputs.
35 */
36 template <typename T1, typename T2, require_any_container_t<T1, T2>* = nullptr,
37 require_all_not_nonscalar_prim_or_rev_kernel_expression_t<
38 T1, T2>* = nullptr>
ldexp(const T1 & a,const T2 & b)39 inline auto ldexp(const T1& a, const T2& b) {
40 return apply_scalar_binary(
41 a, b, [&](const auto& c, const auto& d) { return ldexp(c, d); });
42 }
43
44 } // namespace math
45 } // namespace stan
46
47 #endif
48