labs() — llabs() — Calculate Absolute Value of Long and Long Long Integer

Format (labs())

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

Format (llabs())

#include <stdlib.h>
long long int llabs(long long int i);

Language Level: ANSI

Threadsafe: Yes.

Description

The labs() function produces the absolute value of its long integer argument n. The result might be undefined when the argument is equal to LONG_MIN, the smallest available long integer. The value LONG_MIN is defined in the <limits.h> include file.

The llabs() function returns the absolute value of its long long integer operand. The result might be undefined when the argument is equal to LONG_LONG_MIN, the smallest available long integer. The value LONG_LONG_MIN is defined in the <limits.h> include file.

Return Value

The labs() function returns the absolute value of n. There is no error return value.

The llabs() function returns the absolute value of i. There is no error return value.

Example that uses labs()

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

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

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]