labs, llabs

Calculates the absolute value of an integer.

long labs(
   long n 
);
long long llabs(
   long long n 
);

Parameters

  • n
    Integer value.

Return Value

The labs and llabs functions return the absolute value of the argument. There is no error return.

Microsoft Specific

Because the range of negative integers that can be represented by using an integral type is larger than the range of positive integers that can be represented by using that type, it's possible to supply an argument to labs or llabs that can’t be converted. If the absolute value of the argument cannot be represented by the return type, the labs and llabs functions return the argument value unchanged. Specifically, labs(LONG_MIN) returns LONG_MIN, and llabs(LLONG_MIN) returns LLONG_MIN. This means that the labs and llabs functions cannot be used to guarantee a positive value.

End Microsoft Specific

Requirements

Routine

Required header

labs, llabs

<stdlib.h> or <math.h>

For additional compatibility information, see Compatibility.

Libraries

All versions of the C run-time libraries.

Example

See the example for abs.

.NET Framework Equivalent

System::Math::Abs

See Also

Reference

Data Conversion

Floating-Point Support

abs, _abs64

_cabs

fabs, fabsf

imaxabs