| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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

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