A RetroSearch Logo

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

Search Query:

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

function

<cmath> <ctgmath>

abs
     double abs (double x);      float abs (float x);long double abs (long double x);
     double abs (double x);      float abs (float x);long double abs (long double x);     double abs (T x);           // additional overloads for integral types

Compute absolute value

Returns the absolute value of x: |x|.

These convenience abs overloads are exclusive of C++. In C, abs is only declared in <stdlib.h> (and operates on int values).

Since C++11, additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).



Parameters
x
Value whose absolute value is returned.

Return Value The absolute value of x.

Example
1
2
3
4
5
6
7
8
9
10
// cmath's abs example
#include <iostream>     // std::cout
#include <cmath>        // std::abs

int main ()
{
  std::cout << "abs (3.1416) = " << std::abs (3.1416) << '\n';
  std::cout << "abs (-10.6)  = " << std::abs (-10.6) << '\n';
  return 0;
}

Output:
abs (3.1416) = 3.1416
abs (-10.6) = 10.6


See also
abs (cstdlib)
Absolute value (function)
fabs
Compute absolute value (function)
labs
Absolute value (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