1 #ifndef STAN_MATH_PRIM_SCAL_FUN_FMIN_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_FMIN_HPP
3 
4 #include <stan/math/prim/scal/fun/is_nan.hpp>
5 #include <boost/math/tools/promotion.hpp>
6 
7 namespace stan {
8 namespace math {
9 
10 /**
11  * Return the lesser of the two specified arguments.  If one is
12  * greater than the other, return not-a-number.
13  *
14  * @param x First argument.
15  * @param y Second argument.
16  * @return Minimum of x or y and if one is NaN return the other
17  */
18 template <typename T1, typename T2>
fmin(const T1 & x,const T2 & y)19 inline typename boost::math::tools::promote_args<T1, T2>::type fmin(
20     const T1& x, const T2& y) {
21   if (is_nan(x))
22     return y;
23   if (is_nan(y))
24     return x;
25   return y > x ? x : y;
26 }
27 
28 }  // namespace math
29 }  // namespace stan
30 #endif
31