A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/cstdlib/abs/ below:

function

<cstdlib>

abs
     int abs (     int n);long int abs (long int n);
          int abs (          int n);     long int abs (     long int n);long long int abs (long long int n);

Absolute value

Returns the absolute value of parameter n ( /n/ ).

In C++, this function is also overloaded in header <cmath> for floating-point types (see cmath abs), in header <complex> for complex numbers (see complex abs), and in header <valarray> for valarrays (see valarray abs).



Parameters
n
Integral value.

Return Value The absolute value of n.

Portability In C, only the int version exists.
For the long int equivalent see labs.
For the long long int equivalent see llabs.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
/* abs example */
#include <stdio.h>      /* printf */
#include <stdlib.h>     /* abs */

int main ()
{
  int n,m;
  n=abs(23);
  m=abs(-11);
  printf ("n=%d\n",n);
  printf ("m=%d\n",m);
  return 0;
}

Output:


Data races Concurrently calling this function is safe, causing no data races.

Exceptions (C++)No-throw guarantee: this function throws no exceptions.

If the result cannot be represented by the returned type (such as abs(INT_MIN) in an implementation with two's complement signed values), it causes undefined behavior.



See also
labs
Absolute value (function)
fabs
Compute absolute value (function)
div
Integral division (function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4