C Standard Libraries C++

abs()

Declaration

double abs(double dX);

Description

This function returns the absolute value of the passed-in argument.

Overloads

int abs(int);
long abs(long);
float abs(float);
double abs(double);
long double abs(long double);

Related Functions

float fabs(float);
double fabs(double);
long double fabs(long double);
float fabsf(float);
long double fabsl(long double);

* Note: Since C does not allow function overloading, these other versions of this function exist.

Domain

(-∞, ∞)

Range

[0, ∞)

Periodicity

None

Symmetry

Y-axis

Asymptotes

None





Example

#include <iostream>
#include <cmath>

int main() {
    using namespace std;

    double dX = -3.4;
    cout << "x = " << dX << "  abs(x) = " << abs(dX) << endl;

    dX = 15.1;
    cout << "x = " << dX << "  abs(x) = " << abs(dX) << endl;

    return 0;
}

Output

abs() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.