Share via


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

另請參閱

資料轉換
數學和浮點支援
abs, labs, llabs, _abs64
_cabs
fabs, fabsf, fabsl