Stan Math Library  2.11.0
reverse mode automatic differentiation
fmod.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_FMOD_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_FMOD_HPP
3 
4 #include <stan/math/fwd/core.hpp>
5 
8 
9 namespace stan {
10 
11  namespace math {
12 
13  template <typename T>
14  inline
15  fvar<T>
16  fmod(const fvar<T>& x1, const fvar<T>& x2) {
17  using std::fmod;
18  using std::floor;
19  return fvar<T>(fmod(x1.val_, x2.val_),
20  x1.d_ - x2.d_ * floor(x1.val_ / x2.val_));
21  }
22 
23  template <typename T>
24  inline
25  fvar<T>
26  fmod(const fvar<T>& x1, const double x2) {
27  using std::fmod;
30  || boost::math::isnan(x2)))
31  return fvar<T>(fmod(x1.val_, x2), stan::math::NOT_A_NUMBER);
32  else
33  return fvar<T>(fmod(x1.val_, x2), x1.d_ / x2);
34  }
35 
36  template <typename T>
37  inline
38  fvar<T>
39  fmod(const double x1, const fvar<T>& x2) {
40  using std::fmod;
41  using std::floor;
42  return fvar<T>(fmod(x1, x2.val_), -x2.d_ * floor(x1 / x2.val_));
43  }
44  }
45 }
46 #endif
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:56
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of.hpp:16
fvar< T > fmod(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmod.hpp:16
bool isnan(const stan::math::var &v)
Checks if the given number is NaN.
Definition: boost_isnan.hpp:22
#define unlikely(x)
Definition: likely.hpp:9
var fmod(const double a, const var &b)
Return the floating point remainder after dividing the first scalar by the second variable (cmath)...
Definition: fmod.hpp:137
fvar< T > floor(const fvar< T > &x)
Definition: floor.hpp:11

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