imaxabs

计算所有大小整数的绝对值。

intmax_t imaxabs(
   intmax_t n 
);

参数

  • n
    整数值。

返回值

imaxabs 函数返回参数的绝对值。 无错误返回。

备注

由于可使用 intmax_t 表示的负整数的范围大于可表示的正整数的范围,因此可向 imaxabs 提供不能转换的参数。如果参数的绝对值不能由返回类型表示,则不定义 imaxabs 行为。

要求

例程

必需的标头

imaxabs

<inttypes.h>

有关其他兼容性信息,请参见兼容性

C 运行时库的所有版本。

示例

// crt_imaxabs.c
// Build using: cl /W3 /Tc crt_imaxabs.c
// This example calls imaxabs to compute an
// absolute value, then displays the results.

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int main(int argc, char *argv[])
{
   intmax_t x = LLONG_MIN + 2;

   printf("The absolute value of %lld is %lld\n", x, imaxabs(x));
}
  

.NET Framework 等效项

System::Math::Abs

请参见

参考

数据转换

浮点支持

abs、_abs64

_cabs

fabs、fabsf

labs、llabs