C
数值 | Numerics

cabsl

cabsf, cabs, cabsl

在头文件中定义
float cabsf( float complex z (1)(since C99)
double cabs( double complex z (2)(since C99)
long double cabsl( long double complex z (3)(since C99)
Defined in header <tgmath.h>
#define fabs( z )(4)(since C99)

1-3)计算复数的绝对值(也称为范数,模数或大小)z

4)类型 - 通用宏:如果z有类型long double complexlong double imaginarycabsl被调用。如果z已键入float complexfloat imaginarycabsf被调用。如果z已键入double complexdouble imaginarycabs被调用。对于实数和整数类型,fabs调用相应的版本。

参数

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标准(ISO / IEC 9899:2011):