cabsf, cabs, cabsl

来自cppreference.com
< c‎ | numeric‎ | complex
 
 
 
复数算术
类型与虚数常量
(C99)
(C11)
(C99)
I
(C99)
操作
(C99)
(C99)
(C99)
cabs
(C99)
(C99)
(C99)
幂与指数函数
(C99)
(C99)
(C99)
(C99)
三角函数
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)
双曲函数
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)
 
在标头 <complex.h> 定义
float       cabsf( float complex z );
(1) (C99 起)
double      cabs( double complex z );
(2) (C99 起)
long double cabsl( long double complex z );
(3) (C99 起)
在标头 <tgmath.h> 定义
#define fabs( z )
(4) (C99 起)
1-3) 计算复数 z 的绝对值。
4) 泛型宏:若 z 拥有 long double complex long double imaginary 类型,则调用 cabsl。若 z 拥有 float complex float imaginary 类型,则调用 cabsf。若 z 拥有 double complex double imaginary 类型,则调用 cabs。对于实数和整数类型,调用对应版本的 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):
  • 7.3.8.1 The cabs functions (第 195 页)
  • 7.25 Type-generic math <tgmath.h> (第 373-375 页)
  • G.7 Type-generic math <tgmath.h> (第 545 页)
  • C99 标准(ISO/IEC 9899:1999):
  • 7.3.8.1 The cabs functions (第 177 页)
  • 7.22 Type-generic math <tgmath.h> (第 335-337 页)
  • G.7 Type-generic math <tgmath.h> (第 480 页)

[编辑] 参阅

(C99)(C99)(C99)
计算复数的辐角
(函数) [编辑]
计算整数的绝对值(\(\small{|x|}\)|x|)
(函数) [编辑]
(C99)(C99)
计算浮点数的绝对值(\(\small{|x|}\)|x|)
(函数) [编辑]
(C99)(C99)(C99)
计算两个给定数平方和的平方根(\(\scriptsize{\sqrt{x^2+y^2} }\)x2
+y2
)
(函数) [编辑]
abs 的 C++ 文档
来自"https://zh.cppreference.com/mwiki/index.php?title=c/numeric/complex/cabs&oldid=80675"

AltStyle によって変換されたページ (->オリジナル) /