All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
fabs.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_FWD_SCAL_FUN_FABS_HPP
#define STAN_MATH_FWD_SCAL_FUN_FABS_HPP
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/scal/fun/constants.hpp>
#include <stan/math/prim/scal/fun/value_of.hpp>
#include <stan/math/prim/scal/meta/likely.hpp>
#include <cmath>
namespace stan {
namespace math {
template<typename T>
inline fvar<T> fabs(const fvar<T>& x) {
using std::fabs;
using stan::math::NOT_A_NUMBER;
using stan::math::value_of;
if (unlikely(boost::math::isnan(value_of(x.val_))))
return fvar<T>(fabs(x.val_), stan::math::NOT_A_NUMBER);
else if (x.val_ > 0.0)
return x;
else if (x.val_ < 0.0)
return fvar<T>(-x.val_, -x.d_);
else
return fvar<T>(0, 0);
}
}
}
#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::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–2015, Stan Development Team.