Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fdim.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__FWD__FUNCTIONS__FDIM_HPP
2 #define STAN__AGRAD__FWD__FUNCTIONS__FDIM_HPP
3 
5 #include <stan/meta/traits.hpp>
7 
8 namespace stan {
9 
10  namespace agrad {
11 
12  template <typename T>
13  inline
14  fvar<T>
15  fdim(const fvar<T>& x1, const fvar<T>& x2) {
16  using stan::math::fdim;
17  using std::floor;
18  if(x1.val_ < x2.val_)
19  return fvar<T>(fdim(x1.val_, x2.val_), 0);
20  else
21  return fvar<T>(fdim(x1.val_, x2.val_),
22  x1.d_ - x2.d_ * floor(x1.val_ / x2.val_));
23  }
24 
25  template <typename T>
26  inline
27  fvar<T>
28  fdim(const fvar<T>& x1, const double x2) {
29  using stan::math::fdim;
30  using std::floor;
31  if(x1.val_ < x2)
32  return fvar<T>(fdim(x1.val_, x2), 0);
33  else
34  return fvar<T>(fdim(x1.val_, x2), x1.d_);
35  }
36 
37  template <typename T>
38  inline
39  fvar<T>
40  fdim(const double x1, const fvar<T>& x2) {
41  using stan::math::fdim;
42  using std::floor;
43  if(x1 < x2.val_)
44  return fvar<T>(fdim(x1, x2.val_), 0);
45  else
46  return fvar<T>(fdim(x1, x2.val_), x2.d_ * -floor(x1 / x2.val_));
47  }
48  }
49 }
50 #endif
fvar< T > floor(const fvar< T > &x)
Definition: floor.hpp:15
boost::math::tools::promote_args< T1, T2 >::type fdim(T1 a, T2 b)
The positive difference function (C99).
Definition: fdim.hpp:23
fvar< T > fdim(const fvar< T > &x1, const fvar< T > &x2)
Definition: fdim.hpp:15

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