Share via


abs、_abs64

更新 : 2010 年 9 月

絶対値を計算します。

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 は常に整数を受け取り、整数を返します。

注意

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

履歴の変更

日付

History

理由

2010 年 9 月

についてのメモを追加INT_MIN。

情報の拡充