Go to the first, previous, next, last section, table of contents.


Absolute Value

These functions are provided for obtaining the absolute value (or magnitude) of a number. The absolute value of a real number x is x is x is positive, -x if x is negative. For a complex number z, whose real part is x and whose imaginary part is y, the absolute value is sqrt (x*x + y*y).

Prototypes for abs and labs are in `stdlib.h'; fabs and cabs are declared in `math.h'.

Function: int abs (int number)
This function returns the absolute value of number.

Most computers use a two's complement integer representation, in which the absolute value of INT_MIN (the smallest possible int) cannot be represented; thus, abs (INT_MIN) is not defined.

Function: long int labs (long int number)
This is similar to abs, except that both the argument and result are of type long int rather than int.

Function: double fabs (double number)
This function returns the absolute value of the floating-point number number.

Function: double cabs (struct { double real, imag; } z)
The cabs function returns the absolute value of the complex number z, whose real part is z.real and whose imaginary part is z.imag. (See also the function hypot in section Exponentiation and Logarithms.) The value is:

sqrt (z.real*z.real + z.imag*z.imag)


Go to the first, previous, next, last section, table of contents.