| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

fabs.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_FABS_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_FABS_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 #include <stan/math/prim/scal/meta/likely.hpp>
9 #include <cmath>
10
11 namespace stan {
12 namespace math {
13
14 template<typename T>
15 inline fvar<T> fabs(const fvar<T>& x) {
16 using std::fabs;
17
18 if (unlikely(is_nan(value_of(x.val_))))
19 return fvar<T>(fabs(x.val_), NOT_A_NUMBER);
20 else if (x.val_ > 0.0)
21 return x;
22 else if (x.val_ < 0.0)
23 return fvar<T>(-x.val_, -x.d_);
24 else
25 return fvar<T>(0, 0);
26 }
27
28 }
29 }
30 #endif
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:14
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
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
unlikely
#define unlikely(x)
Definition: likely.hpp:9
stan::math::fvar::val_
T val_
Definition: fvar.hpp:13
stan::math::fabs
var fabs(const var &a)
Return the absolute value of the variable (cmath).
Definition: fabs.hpp:49
likely.hpp
constants.hpp
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.