.. index:: py::builtins::abs .. _doxycast_pypp_namespacepy_1_1builtins_1aa1a2f425fddc8c717040b54fb89d5e74: .. _py-builtins-abs: *py::builtins::*\ abs ===================== *Defined in* ```` .. code-block:: cpp template auto abs(const type& x) -> decltype(x * 1) Returns the absolute value of ``x``. Template parameters ------------------- ``type``: The type of paramter. .. admonition:: Requirement of ``type`` ``type`` must be a scalar type or any other type meeting the following requirements: * Comparable with operator ``<`` * Multiplable with operator ``*`` Parameters ---------- ``x``: The value whose absolute value to return. Return value ------------ The absolute value of ``x``. The type of return value is ``decltype(x * 1)``. Complexity ---------- Constant. Specializing ------------ ``py::builtins::abs`` specialized as the following when the return value and the parameter type is same:: template <> /* type */ py::builtins::abs< /* type */ >(const /* type */ & x); Example ------- .. code-block:: cpp #include #include int main() { py::print(py::abs(-5)); } **Output**: .. code-block:: text 5