Compute the absolute value of a complex number
#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 );
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 ) );
The absolute value of value.
#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
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |