Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ fabs() [7/8]

var stan::math::fabs ( const var a)
inline

Return the absolute value of the variable (cmath).

Choosing an arbitrary value at the non-differentiable point 0,

\(\frac{d}{dx}|x| = \mbox{sgn}(x)\).

where \(\mbox{sgn}(x)\) is the signum function, taking values -1 if \(x < 0\), 0 if \(x == 0\), and 1 if \(x == 1\).

The function abs() provides the same behavior, with abs() defined in stdlib.h and fabs() defined in cmath. The derivative is 0 if the input is 0.

Returns std::numeric_limits<double>::quiet_NaN() for NaN inputs.

\[ \mbox{fabs}(x) = \begin{cases} |x| & \mbox{if } -\infty\leq x\leq \infty \\[6pt] \textrm{NaN} & \mbox{if } x = \textrm{NaN} \end{cases} \]

\[ \frac{\partial\, \mbox{fabs}(x)}{\partial x} = \begin{cases} -1 & \mbox{if } x < 0 \\ 0 & \mbox{if } x = 0 \\ 1 & \mbox{if } x > 0 \\[6pt] \textrm{NaN} & \mbox{if } x = \textrm{NaN} \end{cases} \]

Parameters
aInput variable.
Returns
Absolute value of variable.

Definition at line 50 of file fabs.hpp.