labs -- Calculate Absolute Value of Long Integer

Format

#include <stdlib.h>
long int labs(long int n);

Language Level: ANSI, XPG4
labs produces the absolute value of its long integer argument n. The result may be undefined when the argument is equal to LONG_MIN, the smallest available long integer (-2 147 483 647). The value LONG_MIN is defined in the <limits.h> include file.

Return Value
labs returns the absolute value of n. There is no error return value.

Example
This example computes y as the absolute value of the long integer -41567.

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
   long x,y;
   x = -41567L;
   y = labs(x);
   printf("The absolute value of %ld is %ld\n", x, y);
   return 0;
   /***************************************************
      The output should be:
      The absolute value of -41567 is 41567
   ***************************************************/
}


abs -- Calculate Integer Absolute Value
_cabs -- Calculate Absolute Value of Complex Number
fabs -- Calculate Floating-Point Absolute Value
<limits.h>
llabs -- Calculate Absolute Value of Long Long Integer