計算複數的絕對值。
語法
double _cabs(
struct _complex z
);
參數
z
複數。
傳回值
成功時,_cabs 會傳回其引數的絕對值。 溢位時,_cabs 會傳回 HUGE_VAL,並將 errno 設為 ERANGE。 您可以使用 變更錯誤處理 _matherr。
備註
函 _cabs 式會計算複數的絕對值,其必須是 型 _complex別的結構。 結構 z 包含實數元件 x 和虛數元件 y。 的 _cabs 呼叫會產生相當於表達式 sqrt( z.x * z.x + z.y * z.y )的值。
根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
需求
| 常式 | 必要的標頭 |
|---|---|
_cabs |
<math.h> |
如需相容性詳細資訊,請參閱相容性。
範例
// crt_cabs.c
// Using _cabs, this program calculates
// the absolute value of a complex number.
#include <math.h>
#include <stdio.h>
int main( void )
{
struct _complex number = { 3.0, 4.0 };
double d;
d = _cabs( number );
printf( "The absolute value of %f + %fi is %f\n",
number.x, number.y, d );
}
The absolute value of 3.000000 + 4.000000i is 5.000000