abs() — Calculate integer absolute value

Format

#include <stdlib.h>

int abs(int n);

General description

The abs() function returns the absolute value of an argument n.

For the integer version of abs(), the minimum allowable integer is INT_MIN+1. (INT_MIN is a macro that is defined in the limits.h header file.) For example, with the Metal C compiler, INT_MIN+1 is -2147483647.

Returned value

The returned value is the absolute value, if the absolute value is possible to represent.

Otherwise the input value is returned.

Related Information