return the absolute value of a long integer

You're viewing an older version of this page (#4053). View the current version.

View versions (3)

INTERFACE

#include <stdlib.h> long labs ( long j )

DESCRIPTION

The labs function returns the absolute value of the long integer &#92;c j, denoted by |j| and defined through:

|j| :=
\left\{
\begin{array}{ll}
j, & j \geq 0, \\
-j, & j < 0.
\end{array} 
\right.
(1)
Example 1
Workings

\code #include <stdio.h> #include <stdlib.h> int main() { long int a = -231564565; printf("|a| = %ld
", labs(a)); return 0; } \endcode

Solution

Output:

|a| = 231564565

SEE ALSO

abs, floor

BUGS

The absolute value of the most negative integer remains negative.