Stan Math Library  2.15.0
reverse mode automatic differentiation
fdim.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_FDIM_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_FDIM_HPP
3 
4 #include <stan/math/fwd/core.hpp>
6 
7 namespace stan {
8  namespace math {
9 
19  template <typename T>
20  inline fvar<T> fdim(const fvar<T>& x, const fvar<T>& y) {
21  if (x.val_ < y.val_)
22  return fvar<T>(fdim(x.val_, y.val_), 0);
23  else
24  return fvar<T>(fdim(x.val_, y.val_),
25  x.d_ - y.d_);
26  }
27 
37  template <typename T>
38  inline fvar<T> fdim(const fvar<T>& x, double y) {
39  if (x.val_ < y)
40  return fvar<T>(fdim(x.val_, y), 0);
41  else
42  return fvar<T>(fdim(x.val_, y), x.d_);
43  }
44 
54  template <typename T>
55  inline fvar<T> fdim(double x, const fvar<T>& y) {
56  if (x < y.val_)
57  return fvar<T>(fdim(x, y.val_), 0);
58  else
59  return fvar<T>(fdim(x, y.val_), -y.d_);
60  }
61 
62  }
63 }
64 #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

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