Stan Math Library  2.14.0
reverse mode automatic differentiation
fdim.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_FDIM_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_FDIM_HPP
3 
5 #include <boost/math/tools/promotion.hpp>
6 #include <limits>
7 
8 namespace stan {
9  namespace math {
10 
22  template <typename T1, typename T2>
23  inline typename boost::math::tools::promote_args<T1, T2>::type
24  fdim(T1 x, T2 y) {
25  typedef typename boost::math::tools::promote_args<T1, T2>::type return_t;
26  using std::numeric_limits;
27  if (is_nan(x) || is_nan(y))
28  return numeric_limits<return_t>::quiet_NaN();
29  return (x <= y) ? 0 : x - y;
30  }
31 
32  }
33 }
34 #endif
fvar< T > fdim(const fvar< T > &x, const fvar< T > &y)
Return the positive difference of the specified values (C++11).
Definition: fdim.hpp:20
int is_nan(const fvar< T > &x)
Returns 1 if the input&#39;s value is NaN and 0 otherwise.
Definition: is_nan.hpp:21

     [ Stan Home Page ] © 2011–2016, Stan Development Team.