Automatic Differentiation
 
Loading...
Searching...
No Matches
abs.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_ABS_HPP
2#define STAN_MATH_FWD_FUN_ABS_HPP
3
9#include <complex>
10
11namespace stan {
12namespace math {
13
14template <typename T>
15inline fvar<T> abs(const fvar<T>& x) {
16 if (x.val_ > 0.0) {
17 return x;
18 } else if (x.val_ < 0.0) {
19 return fvar<T>(-x.val_, -x.d_);
20 } else if (x.val_ == 0.0) {
21 return fvar<T>(0, 0);
22 } else {
23 return fvar<T>(abs(x.val_), NOT_A_NUMBER);
24 }
25}
26
34template <typename T>
35inline fvar<T> abs(const std::complex<fvar<T>>& z) {
36 return internal::complex_abs(z);
37}
38
39} // namespace math
40} // namespace stan
41#endif
V complex_abs(const std::complex< V > &z)
Return the absolute value of the complex argument.
Definition abs.hpp:94
fvar< T > abs(const fvar< T > &x)
Definition abs.hpp:15
static constexpr double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition constants.hpp:56
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