1 #ifndef STAN_MATH_PRIM_FUN_DIVIDE_HPP
2 #define STAN_MATH_PRIM_FUN_DIVIDE_HPP
3
4 #include <stan/math/prim/fun/Eigen.hpp>
5 #include <stan/math/prim/meta.hpp>
6 #include <stan/math/prim/err.hpp>
7 #include <stan/math/prim/fun/as_array_or_scalar.hpp>
8 #include <cstddef>
9 #include <cstdlib>
10 #include <type_traits>
11
12 namespace stan {
13 namespace math {
14
15 /**
16 * Return the division of the first scalar by
17 * the second scalar.
18 * @param[in] x Specified scalar.
19 * @param[in] y Specified scalar.
20 * @return Scalar divided by the scalar.
21 */
22 template <typename Scal1, typename Scal2,
23 require_all_stan_scalar_t<Scal1, Scal2>* = nullptr>
divide(const Scal1 & x,const Scal2 & y)24 inline return_type_t<Scal1, Scal2> divide(const Scal1& x, const Scal2& y) {
25 return x / y;
26 }
27
divide(int x,int y)28 inline int divide(int x, int y) {
29 if (unlikely(y == 0)) {
30 throw_domain_error("divide", "denominator is", y, "");
31 }
32 return x / y;
33 }
34
35 /**
36 * Return matrix divided by scalar.
37 *
38 * @tparam Mat type of the matrix or expression
39 * @tparam Scal type of the scalar
40 * @param[in] m specified matrix or expression
41 * @param[in] c specified scalar
42 * @return matrix divided by the scalar
43 */
44 template <typename T1, typename T2, require_any_eigen_t<T1, T2>* = nullptr,
45 require_all_not_st_var<T1, T2>* = nullptr>
divide(const T1 & m,const T2 & c)46 inline auto divide(const T1& m, const T2& c) {
47 return (as_array_or_scalar(m) / as_array_or_scalar(c)).matrix();
48 }
49
50 } // namespace math
51 } // namespace stan
52
53 #endif
54