abs

De RAD Studio
Aller à : navigation, rechercher

Remonter à Math.h - Index


Header File

stdlib.h, math.h

Category

Math Routines, Inline Routines

Prototype

int abs(int x);

Description

Returns the absolute value of an integer.

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

La fonction abs renvoie un entier d'une étendue de 0 à INT_MAX, sauf lorsqu'un argument a une valeur INT_MIN, qui renvoie INT_MIN. Les valeurs de INT_MAX et INT_MIN sont définies dans le fichier d'en-tête limits.h.

Example

#include <stdio.h>
#include <math.h>
int main(void)
{
  int number = -1234;
  printf("number: %d  absolute value: %d\n", number, abs(number));
  return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

+

+

+

+