Stan Math Library  2.15.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>
8 
9 namespace stan {
10  namespace math {
11 
12  template <typename T>
13  inline
14  fvar<T>
15  fmod(const fvar<T>& x1, const fvar<T>& x2) {
16  using std::fmod;
17  using std::floor;
18  return fvar<T>(fmod(x1.val_, x2.val_),
19  x1.d_ - x2.d_ * floor(x1.val_ / x2.val_));
20  }
21 
22  template <typename T>
23  inline
24  fvar<T>
25  fmod(const fvar<T>& x1, double x2) {
26  using std::fmod;
27  if (unlikely(is_nan(value_of(x1.val_))
28  || is_nan(x2)))
29  return fvar<T>(fmod(x1.val_, x2), NOT_A_NUMBER);
30  else
31  return fvar<T>(fmod(x1.val_, x2), x1.d_ / x2);
32  }
33 
34  template <typename T>
35  inline
36  fvar<T>
37  fmod(double x1, const fvar<T>& x2) {
38  using std::fmod;
39  using std::floor;
40  return fvar<T>(fmod(x1, x2.val_), -x2.d_ * floor(x1 / x2.val_));
41  }
42 
43  }
44 }
45 #endif
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:55
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of.hpp:16
var fmod(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 > fmod(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmod.hpp:15
#define unlikely(x)
Definition: likely.hpp:9
fvar< T > floor(const fvar< T > &x)
Definition: floor.hpp:11
int is_nan(const fvar< T > &x)
Returns 1 if the input&#39;s value is NaN and 0 otherwise.
Definition: is_nan.hpp:21

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