Stan Math Library  2.14.0
reverse mode automatic differentiation
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>
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
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
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
#define unlikely(x)
Definition: likely.hpp:9
var fabs(const var &a)
Return the absolute value of the variable (cmath).
Definition: fabs.hpp:49
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.