cabs(), cabsf()

Compute the absolute value of a complex number

Synopsis:

#include <math.h>

struct __cabsargs {
    double  x;   /* real part      */
    double  y;   /* imaginary part */
};

double cabs( struct __cabsargs value );

struct __cabsfargs {
    float  x;   /* real part      */
    float  y;   /* imaginary part */
};

float cabsf( struct __cabsfargs value );

Arguments:

value
The complex value that you want to get the absolute value of.

Library:

libm

Use the -l m option to qcc to link against this library.

Description:

These functions compute the absolute value of the complex number specified by value, using a calculation equivalent to:

sqrt( ( value.x * value.x ) + ( value.y * value.y ) );

Returns:

The absolute value of value.

Examples:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

struct __cabsargs c = { -3.0, 4.0 };

int main( void )
{
    printf( "%f\n", cabs( c ) );

    return EXIT_SUCCESS;
}

produces the output:

5.000000

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

abs(), fabs(), labs(), llabs()