A RetroSearch Logo

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

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../../c/header/../numeric/math/fabs.html below:

fabs, fabsf, fabsl, fabsd32, fabsd64, fabsd128

float       fabsf( float arg );

(1) (since C99)

double      fabs( double arg );

(2)

long double fabsl( long double arg );

(3) (since C99)

_Decimal32  fabsd32( _Decimal32 arg );

(4) (since C23)

_Decimal64  fabsd64( _Decimal64 arg );

(5) (since C23)

_Decimal128 fabsd128( _Decimal128 arg );

(6) (since C23)

#define fabs( arith )

(7) (since C99) 1-6)

Computes the absolute value of a floating-point value

arg

.

The functions with decimal floating-point parameters are declared if and only if the implementation predefines __STDC_IEC_60559_DFP__ (i.e. the implementation supports decimal floating-point numbers).

(since C23) 7)

Type-generic macro: If the argument has type

_Decimal128, _Decimal64, _Decimal32,(since C23)long double

,

double

, or

float

,

fabsd128, fabsd64, fabsd32,(since C23)fabsl

,

fabs

, or

fabsf

is called, respectively. Otherwise, if the argument has integer type,

fabs

is called. Otherwise, if the argument is complex, then the macro invokes the corresponding complex function (

cabsf

,

cabs

,

cabsl

). Otherwise, the behavior is undefined.

[edit] Parameters arg - floating-point value arith - floating-point or integer value [edit] Return value

If successful, returns the absolute value of arg (\(\small |arg| \)|arg|). The value returned is exact and does not depend on any rounding modes.

[edit] Error handling

This function is not subject to any of the error conditions specified in math_errhandling.

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

[edit] Example
#include <math.h>
#include <stdio.h>
 
#define PI 3.14159
 
// This numerical integration assumes all area is positive.
double integrate(double f(double),
                 double a, double b, // assume a < b
                 unsigned steps) // assume steps > 0
{
    const double dx = (b - a) / steps;
    double sum = 0.0;
    for (double x = a; x < b; x += dx)
        sum += fabs(f(x));
    return dx * sum;
}
 
int main(void)
{
    printf("fabs(+3) = %f\n", fabs(+3.0));
    printf("fabs(-3) = %f\n", fabs(-3.0));
    // special values
    printf("fabs(-0) = %f\n", fabs(-0.0));
    printf("fabs(-Inf) = %f\n", fabs(-INFINITY));
 
    printf("Area under sin(x) in [-PI, PI] = %f\n", integrate(sin, -PI, PI, 5101));
}

Output:

fabs(+3) = 3.000000
fabs(-3) = 3.000000
fabs(-0) = 0.000000
fabs(-Inf) = inf
Area under sin(x) in [-PI, PI] = 4.000000
[edit] References
[edit] See also

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