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));
}
The absolute value of -9223372036854775806 is 9223372036854775806

另请参阅

数据转换
数学和浮点支持
abslabsllabs_abs64
_cabs
fabsfabsffabsl