cabsf, cabs, cabsl_C语言中文网
| 定义于头文件 |
||
| float cabsf( float complex z ); |
(1) | (C99 起) |
| double cabs( double complex z ); |
(2) | (C99 起) |
| long double cabsl( long double complex z ); |
(3) | (C99 起) |
| 定义于头文件 |
||
| #define fabs( z ) |
(4) | (C99 起) |
1-3) 计算复数 z 的绝对值。
参数
返回值
若不出现错误,则返回 z 的绝对值(范数、模)。
如同函数实现为 hypot(creal(z), cimag(z)) 一般处理错误和特殊情况。
示例
#include <stdio.h> #include <complex.h> int main(void) { double complex z = 1.0 + 1.0*I; printf("%.1f%+.1fi cartesian is rho=%f theta=%f polar\n", creal(z), cimag(z), cabs(z), carg(z)); }
输出:
1.0+1.0i cartesian is rho=1.414214 theta=0.785398 polar
引用
- C11 standard (ISO/IEC 9899:2011):
- 7.3.8.1 The cabs functions (p: 195)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- G.7 Type-generic math <tgmath.h> (p: 545)
- C99 standard (ISO/IEC 9899:1999):
- 7.3.8.1 The cabs functions (p: 177)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- G.7 Type-generic math <tgmath.h> (p: 480)