| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 #include <stan/math/prim/scal/fun/constants.hpp>
6 #include <stan/math/prim/scal/fun/is_nan.hpp>
7 #include <stan/math/prim/scal/fun/value_of.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, const 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(const 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
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:14
stan::math::NOT_A_NUMBER
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:55
is_nan.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::value_of
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of.hpp:16
stan::math::fmod
fvar< T > fmod(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmod.hpp:15
unlikely
#define unlikely(x)
Definition: likely.hpp:9
stan::math::fvar::val_
T val_
Definition: fvar.hpp:13
stan::math::fmod
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
constants.hpp
stan::math::floor
fvar< T > floor(const fvar< T > &x)
Definition: floor.hpp:11
stan::math::is_nan
int is_nan(const fvar< T > &x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition: is_nan.hpp:21
value_of.hpp
stan::math::fvar
Definition: fvar.hpp:12

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