cabs
Return the absolute value of a complex number.
Interface Definition
C interface:
float cabsf(float complex x);
double cabs(double complex x);
double cabs_18(double complex x);
long double cabsl(long double complex x);
cabs_18 is provided only in the high-precision version.
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data. |
Input |
Return Value
- The absolute value of x is returned.
- If x.real or x.imag is SNaN, NaN is returned.
- If x.real or x.imag is ±∞, ±∞ is returned.
- If x.real or x.imag is QNaN, NaN is returned.
- If x.real is ±0 and x.imag is ±0, +0 is returned.
- If
, +∞ is returned.
Dependency
C: "km.h"
Example
C interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | // typical usage double x1 = INFINITY, y1 = INFINITY; double x2 = 2.0, y2 = 3.0; double x3 = -2.5, y3 = -3.4; double x4 = NAN, y4 = NAN; double x5 = 0, y5 = 0; // print result printf("cabs(%.2f + %.2f*I) = %.6f\n", x1, y1, cabs(__builtin_complex(x1, y1))); printf("cabs(%.2f + %.2f*I) = %.6f\n", x2, y2, cabs(__builtin_complex(x2, y2))); printf("cabs(%.2f + %.2f*I) = %.6f\n", x3, y3, cabs(__builtin_complex(x3, y3))); printf("cabs(%.2f + %.2f*I) = %.6f\n", x4, y4, cabs(__builtin_complex(x4, y4))); printf("cabs(%.2f + %.2f*I) = %.6f\n", x5, y5, cabs(__builtin_complex(x5, y5))); /* * cabs(inf + inf*I) = inf * cabs(2.00 + 3.00*I) = 3.605551 * cabs(-2.50 + -3.40*I) = 4.220190 * cabs(nan + nan*I) = nan * cabs(0.00 + 0.00*I) = 0.000000 **/ |
Parent topic: Complex Functions