Stan Math Library: stan/math/fwd/scal/fun/fabs.hpp Source File

| Stan Math Library 2.10.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/value_of.hpp>
7 #include <stan/math/prim/scal/meta/likely.hpp>
8 #include <cmath>
9
10 namespace stan {
11 namespace math {
12
13 template<typename T>
14 inline fvar<T> fabs(const fvar<T>& x) {
15 using std::fabs;
16 using stan::math::NOT_A_NUMBER;
17 using stan::math::value_of;
18
19 if (unlikely(boost::math::isnan(value_of(x.val_))))
20 return fvar<T>(fabs(x.val_), stan::math::NOT_A_NUMBER);
21 else if (x.val_ > 0.0)
22 return x;
23 else if (x.val_ < 0.0)
24 return fvar<T>(-x.val_, -x.d_);
25 else
26 return fvar<T>(0, 0);
27 }
28
29 }
30 }
31 #endif
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:15
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:14
stan::math::NOT_A_NUMBER
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:56
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
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::fabs
var fabs(const var &a)
Return the absolute value of the variable (cmath).
Definition: fabs.hpp:50
likely.hpp
constants.hpp
value_of.hpp
stan::math::fvar
Definition: fvar.hpp:13

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