Automatic Differentiation
 
Loading...
Searching...
No Matches
fabs.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_FABS_HPP
2#define STAN_MATH_FWD_FUN_FABS_HPP
3
10#include <cmath>
11
12namespace stan {
13namespace math {
14
15template <typename T>
16inline fvar<T> fabs(const fvar<T>& x) {
17 if (unlikely(is_nan(value_of(x.val_)))) {
18 return fvar<T>(fabs(x.val_), NOT_A_NUMBER);
19 } else if (x.val_ > 0.0) {
20 return x;
21 } else if (x.val_ < 0.0) {
22 return fvar<T>(-x.val_, -x.d_);
23 } else {
24 return fvar<T>(0, 0);
25 }
26}
27
28} // namespace math
29} // namespace stan
30#endif
#define unlikely(x)
static constexpr double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition constants.hpp:56
bool is_nan(T &&x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition is_nan.hpp:22
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
fvar< T > fabs(const fvar< T > &x)
Definition fabs.hpp:16
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Scalar val_
The value of this variable.
Definition fvar.hpp:49
Scalar d_
The tangent (derivative) of this variable.
Definition fvar.hpp:61
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40