다음을 통해 공유


abs, _abs64

절대 값을 계산 합니다.

int abs( 
   int n 
);
long abs( 
   long n 
);   // C++ only
double abs( 
   double n 
);   // C++ only
long double abs(
   long double n
);   // C++ only
float abs(
   float n 
);   // C++ only
__int64 _abs64( 
   __int64 n 
);

매개 변수

  • n
    정수 값입니다.

반환 값

abs 함수 매개 변수의 절대 값을 반환 합니다.없음 오류가 반환이 됩니다.

설명

C + +를 오버 로드할 수 있으므로 오버 로드를 호출할 수 있습니다 abs.C 프로그램에서 abs 항상 사용 하 고 int를 반환 합니다.

[!참고]

Both abs(INT_MIN) and _abs64(INT_MIN) return a value of INT_MIN.하지만 경우에이 시간 abs_abs64 음수 값을 반환 함을 의미 abs_abs64 양수 값을 보장 하기 위해 사용할 수 없습니다.

요구 사항

루틴

필수 헤더

abs

<math.h>

_abs64

<stdlib.h>

예제

이 프로그램이 계산 하 고 몇 가지 숫자의 절대 값을 표시 합니다.

// crt_abs.c
// This program demonstrates the user of the abs function
// by computing and displaying the absolute values of
// several numbers.

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

int main( void )
{
    int     ix = -4,
            iy;
    long    lx = -41567L,
            ly;
    double  dx = -3.141593,
            dy;
    __int64 wx = -1, wy;

    // absolute 64 bit integer value
    wy = _abs64( wx );
    printf_s( "The absolute value of %I64x is %I64x\n", wx, wy);

    // absolute 32 bit integer value
    iy = abs( ix );
    printf_s( "The absolute value of %d is %d\n", ix, iy);

    // absolute long integer value
    ly = labs( lx );
    printf_s( "The absolute value of %ld is %ld\n", lx, ly);

    // absolute double value
    dy = fabs( dx );
    printf_s( "The absolute value of %f is %f\n", dx, dy );
}
  

해당 .NET Framework 항목

System::Math::Abs

참고 항목

참조

데이터 변환

부동 소수점 지원

_cabs

fabs, fabsf

labs