| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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
6 #include <stan/math/prim/scal/fun/value_of.hpp>
7 #include <stan/math/prim/scal/fun/constants.hpp>
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;
28 using stan::math::value_of;
29 if (unlikely(boost::math::isnan(value_of(x1.val_))
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
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:15
stan::math::NOT_A_NUMBER
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:56
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:16
boost::math::isnan
bool isnan(const stan::math::var &v)
Checks if the given number is NaN.
Definition: boost_isnan.hpp:22
unlikely
#define unlikely(x)
Definition: likely.hpp:9
stan::math::fvar::val_
T val_
Definition: fvar.hpp:14
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
value_of.hpp
stan::math::fvar
Definition: fvar.hpp:13

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