labs ()-llabs ()- 计算长整数和长整数的绝对值

格式 (labs())

#include <stdlib.h>
long int labs(long int n);

格式 (llabs())

#include <stdlib.h>
long long int llabs(long long int i);

语言级别

ANSI

线程安全

描述

labs() 函数生成其长整数自变量 n的绝对值。 当自变量等于最小可用长整数 LONG_MIN时,结果可能未定义。 值 洛格-管理员<limits.h> 包含文件中定义。

llabs() 函数返回其长整型整数操作数的绝对值。 当自变量等于最小可用长整数 LONG_LONG_LONG_MIN时,结果可能未定义。 值 LONG_LONG_MIN<limits.h> 包含文件中定义。

返回值

labs() 函数返回 n的绝对值。 没有错误返回值。

llabs() 函数返回 i的绝对值。 没有错误返回值。

示例

此示例将 y 计算为长整数 -41567 的绝对值。
#include <stdlib.h>
#include <stdio.h>
 
int main(void)
{
   long x, y;
 
   x = -41567L;
   y = labs(x);
 
   printf("The absolute value of %ld is %ld\n", x, y);
}
 
/********************  Output should be similar to:  **************
 
The absolute value of -41567 is 41567
*/

相关信息