_cabs

计算复数的绝对值。

语法

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

另请参阅

数学和浮点支持
abslabsllabs_abs64
fabsfabsffabsl