Stan Math Library  2.20.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 
8 #include <boost/math/tools/promotion.hpp>
9 
10 namespace stan {
11 namespace math {
12 
24 template <typename T1, typename T2>
25 inline typename boost::math::tools::promote_args<T1, T2>::type fdim(T1 x,
26  T2 y) {
27  typedef typename boost::math::tools::promote_args<T1, T2>::type return_t;
28  using std::numeric_limits;
29  if (is_any_nan(x, y))
30  return NOT_A_NUMBER;
31  return (x <= y) ? 0 : x - y;
32 }
33 
34 } // namespace math
35 } // namespace stan
36 #endif
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:58
bool is_any_nan(const T &x)
Returns true if the input is NaN and false otherwise.
Definition: is_any_nan.hpp:21
fvar< T > fdim(const fvar< T > &x, const fvar< T > &y)
Return the positive difference of the specified values (C++11).
Definition: fdim.hpp:21

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