Borland C++ reference

abs

raw OCR

Returns the absolute value of an integer.

Defined in header <math.h>

Syntax

Real version:                       Complex version:
#include <math.h>                   #include <complex.h>
int abs(int x);                     double abs (complex  x);

Portability

DOSUNIXWindowsANSI CC++ only
Real abs ■■■■
Complex abs ■■■

Remarks

abs returns the absolute value of the integer argument x. If abs is called when stdlib.h has been included, it's treated as a macro that expands to inline code.

If you want to use the abs function instead of the macro, include #undef abs in your program, after the #include <stdlib.h>.

Return value

The real version of abs returns an integer in the range of 0 to 32,767, with the exception that an argument of -32,768 is returned as -32,768. The complex version of abs returns a double.

See also

Example

#include <stdio.h>
finclude <math.h>

int main(void)
{
   int number = -1234;
   printf("number: %d  absolute  value: %d\n", number, abs (number));
   return 0;
}

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • heading `obs` read as `abs`