lines 10-69 of file: include/cppad/core/abs.hpp

{xrst_begin abs}
{xrst_spell
   differentiable
   faq
   rl
}

AD Absolute Value Functions: abs, fabs
######################################

Syntax
******

| *y* = ``abs`` ( *x* )
| *y* = ``fabs`` ( *x* )

x, y
****
See the :ref:`unary_standard_math@Possible Types`
for a unary standard math function.

Atomic
******
In the case where *x* is an AD type,
this is an :ref:`atomic operation<glossary@Operation@Atomic>` .

Complex Types
*************
The functions ``abs`` and *fabs*
are not defined for the base types
``std::complex<float>`` or ``std::complex<double>``
because the complex ``abs`` function is not complex differentiable
(see :ref:`complex types faq<Faq@Complex Types>` ).

Derivative
**********
CppAD defines the derivative of the ``abs`` function is
the :ref:`sign-name` function; i.e.,

.. math::

   {\rm abs}^{(1)} ( x ) = {\rm sign} (x ) =
   \left\{ \begin{array}{rl}
      +1 & {\rm if} \; x > 0 \\
      0  & {\rm if} \; x = 0 \\
      -1 & {\rm if} \; x < 0
   \end{array} \right.

The result for *x*  == 0 used to be a directional derivative.

Example
*******
{xrst_toc_hidden
   example/general/fabs.cpp
}
The file
:ref:`fabs.cpp-name`
contains an example and test of this function.

{xrst_end abs}
