Stan Math Library  2.10.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 
10  template <typename T>
11  inline fvar<T> fdim(const fvar<T>& x1, const fvar<T>& x2) {
12  using stan::math::fdim;
13  using std::floor;
14  if (x1.val_ < x2.val_)
15  return fvar<T>(fdim(x1.val_, x2.val_), 0);
16  else
17  return fvar<T>(fdim(x1.val_, x2.val_),
18  x1.d_ - x2.d_ * floor(x1.val_ / x2.val_));
19  }
20 
21  template <typename T>
22  inline fvar<T> fdim(const fvar<T>& x1, const double x2) {
23  using stan::math::fdim;
24  using std::floor;
25  if (x1.val_ < x2)
26  return fvar<T>(fdim(x1.val_, x2), 0);
27  else
28  return fvar<T>(fdim(x1.val_, x2), x1.d_);
29  }
30 
31  template <typename T>
32  inline fvar<T> fdim(const double x1, const fvar<T>& x2) {
33  using stan::math::fdim;
34  using std::floor;
35  if (x1 < x2.val_)
36  return fvar<T>(fdim(x1, x2.val_), 0);
37  else
38  return fvar<T>(fdim(x1, x2.val_), x2.d_ * -floor(x1 / x2.val_));
39  }
40 
41  }
42 }
43 #endif
fvar< T > fdim(const fvar< T > &x1, const fvar< T > &x2)
Definition: fdim.hpp:11
fvar< T > floor(const fvar< T > &x)
Definition: floor.hpp:11

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