名稱空間
變體
操作

cabsf, cabs, cabsl

來自 cppreference.com
< c‎ | numeric‎ | complex
定義在標頭檔案 <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 complexlong double imaginary,則呼叫 cabsl。如果 z 的型別是 float complexfloat imaginary,則呼叫 cabsf。如果 z 的型別是 double complexdouble imaginary,則呼叫 cabs。對於實數和整數型別,則呼叫相應版本的 fabs

目錄

[edit] 引數

z - 複數引數

[edit] 返回值

如果沒有發生錯誤,返回 z 的絕對值(範數、大小)。

錯誤和特殊情況的處理方式,就如同函式實現為 hypot(creal(z), cimag(z))

[edit] 示例

#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

[edit] 參考

  • C11 標準 (ISO/IEC 9899:2011)
  • 7.3.8.1 cabs 函式 (p: 195)
  • 7.25 型別通用數學 <tgmath.h> (p: 373-375)
  • G.7 型別通用數學 <tgmath.h> (p: 545)
  • C99 標準 (ISO/IEC 9899:1999)
  • 7.3.8.1 cabs 函式 (p: 177)
  • 7.22 型別通用數學 <tgmath.h> (p: 335-337)
  • G.7 型別通用數學 <tgmath.h> (p: 480)

[edit] 另請參閱

(C99)(C99)(C99)
計算複數的幅角
(函式) [編輯]
計算整數值的絕對值 (|x|)
(函式) [編輯]
(C99)(C99)
計算浮點值的絕對值 (|x|)
(函式) [編輯]
(C99)(C99)(C99)
計算兩個給定數的平方和的平方根 (x2
+y2
)
(函式) [編輯]
C++ 文件 用於 abs