# Math.AbsMath.AbsMath.AbsMath.Abs Method

## オーバーロード

 Abs(Decimal) Abs(Decimal) Abs(Decimal) Abs(Decimal) Decimal 数値の絶対値を返します。Returns the absolute value of a Decimal number. Abs(Double) Abs(Double) Abs(Double) Abs(Double) 倍精度浮動小数点数の絶対値を返します。Returns the absolute value of a double-precision floating-point number. Abs(Int16) Abs(Int16) Abs(Int16) Abs(Int16) 16 ビット符号付き整数の絶対値を返します。Returns the absolute value of a 16-bit signed integer. Abs(Int32) Abs(Int32) Abs(Int32) Abs(Int32) 32 ビット符号付き整数の絶対値を返します。Returns the absolute value of a 32-bit signed integer. Abs(Int64) Abs(Int64) Abs(Int64) Abs(Int64) 64 ビット符号付き整数の絶対値を返します。Returns the absolute value of a 64-bit signed integer. Abs(SByte) Abs(SByte) Abs(SByte) Abs(SByte) 8 ビット符号付き整数の絶対値を返します。Returns the absolute value of an 8-bit signed integer. Abs(Single) Abs(Single) Abs(Single) Abs(Single) 単精度浮動小数点数の絶対値を返します。Returns the absolute value of a single-precision floating-point number.

## Abs(Decimal)Abs(Decimal)Abs(Decimal)Abs(Decimal)

Decimal 数値の絶対値を返します。Returns the absolute value of a Decimal number.

``````public:
static System::Decimal Abs(System::Decimal value);``````
``public static decimal Abs (decimal value);``
``static member Abs : decimal -> decimal``
``Public Shared Function Abs (value As Decimal) As Decimal``

#### パラメーター

value
Decimal Decimal Decimal Decimal

MinValue 以上で、MaxValue 以下の数値。A number that is greater than or equal to MinValue, but less than or equal to MaxValue.

#### 戻り値

0 ≤ x ≤MaxValue の 10 進数 x。A decimal number, x, such that 0 ≤ x ≤MaxValue.

### 例

``````using System;

public class Example
{
public static void Main()
{
decimal[] decimals = { Decimal.MaxValue, 12.45M, 0M, -19.69M,
Decimal.MinValue };
foreach (decimal value in decimals)
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));

}
}
// The example displays the following output:
//       Abs(79228162514264337593543950335) = 79228162514264337593543950335
//       Abs(12.45) = 12.45
//       Abs(0) = 0
//       Abs(-19.69) = 19.69
//       Abs(-79228162514264337593543950335) = 79228162514264337593543950335
``````
``````Module Example
Public Sub Main()
Dim decimals() As Decimal = { Decimal.MaxValue, 12.45D, 0D, -19.69D, _
Decimal.MinValue }
For Each value As Decimal In decimals
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Next
End Sub
End Module
' The example displays the following output:
'       Abs(79228162514264337593543950335) = 79228162514264337593543950335
'       Abs(12.45) = 12.45
'       Abs(0) = 0
'       Abs(-19.69) = 19.69
'       Abs(-79228162514264337593543950335) = 79228162514264337593543950335
``````

## Abs(Double)Abs(Double)Abs(Double)Abs(Double)

``````public:
static double Abs(double value);``````
``public static double Abs (double value);``
``static member Abs : double -> double``
``Public Shared Function Abs (value As Double) As Double``

#### パラメーター

value
Double Double Double Double

MinValue 以上で、MaxValue 以下の数値。A number that is greater than or equal to MinValue, but less than or equal to MaxValue.

#### 戻り値

0 ≤ x ≤MaxValue の倍精度浮動小数点数 x。A double-precision floating-point number, x, such that 0 ≤ x ≤MaxValue.

### 例

``````using System;

public class Example
{
public static void Main()
{
double[] doubles = { Double.MaxValue, 16.354e-17, 15.098123, 0,
-19.069713, -15.058e18, Double.MinValue };
foreach (double value in doubles)
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
}
}
// The example displays the following output:
//       Abs(1.79769313486232E+308) = 1.79769313486232E+308
//       Abs(1.6354E-16) = 1.6354E-16
//       Abs(15.098123) = 15.098123
//       Abs(0) = 0
//       Abs(-19.069713) = 19.069713
//       Abs(-1.5058E+19) = 1.5058E+19
//       Abs(-1.79769313486232E+308) = 1.79769313486232E+308
``````
``````Module Example
Public Sub Main()
Dim doubles() As Double = { Double.MaxValue, 16.354e-17, 15.098123, 0, _
-19.069713, -15.058e18, Double.MinValue }
For Each value As Double In doubles
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Next
End Sub
End Module
' The example displays the following output:
'       Abs(1.79769313486232E+308) = 1.79769313486232E+308
'       Abs(1.6354E-16) = 1.6354E-16
'       Abs(15.098123) = 15.098123
'       Abs(0) = 0
'       Abs(-19.069713) = 19.069713
'       Abs(-1.5058E+19) = 1.5058E+19
'       Abs(-1.79769313486232E+308) = 1.79769313486232E+308
``````

## Abs(Int16)Abs(Int16)Abs(Int16)Abs(Int16)

16 ビット符号付き整数の絶対値を返します。Returns the absolute value of a 16-bit signed integer.

``````public:
static short Abs(short value);``````
``public static short Abs (short value);``
``static member Abs : int16 -> int16``
``Public Shared Function Abs (value As Short) As Short``

#### パラメーター

value
Int16 Int16 Int16 Int16

MinValue より大きく、MaxValue 以下の数値。A number that is greater than MinValue, but less than or equal to MaxValue.

#### 戻り値

0 ≤ x ≤MaxValue である 16 ビット符号付き整数 x。A 16-bit signed integer, x, such that 0 ≤ x ≤MaxValue.

#### 例外

`value`MinValue は等しい。`value` equals MinValue.

### 例

``````using System;

public class Example
{
public static void Main()
{
short[] values = { Int16.MaxValue, 10328, 0, -1476, Int16.MinValue };
foreach (short value in values)
{
try {
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
}
catch (OverflowException) {
Console.WriteLine("Unable to calculate the absolute value of {0}.",
value);
}
}
}
}
// The example displays the following output:
//       Abs(32767) = 32767
//       Abs(10328) = 10328
//       Abs(0) = 0
//       Abs(-1476) = 1476
//       Unable to calculate the absolute value of -32768.
``````
``````Module Example
Public Sub Main()
Dim values() As Short = { Int16.MaxValue, 10328, 0, -1476, Int16.MinValue }
For Each value As Short In values
Try
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Catch e As OverflowException
Console.WriteLine("Unable to calculate the absolute value of {0}.", _
value)
End Try
Next
End Sub
End Module
' The example displays the following output:
'       Abs(32767) = 32767
'       Abs(10328) = 10328
'       Abs(0) = 0
'       Abs(-1476) = 1476
'       Unable to calculate the absolute value of -32768.
``````

## Abs(Int32)Abs(Int32)Abs(Int32)Abs(Int32)

32 ビット符号付き整数の絶対値を返します。Returns the absolute value of a 32-bit signed integer.

``````public:
static int Abs(int value);``````
``public static int Abs (int value);``
``static member Abs : int -> int``
``Public Shared Function Abs (value As Integer) As Integer``

#### パラメーター

value
Int32 Int32 Int32 Int32

MinValue より大きく、MaxValue 以下の数値。A number that is greater than MinValue, but less than or equal to MaxValue.

#### 戻り値

0 ≤ x ≤MaxValue である 32 ビット符号付き整数 x。A 32-bit signed integer, x, such that 0 ≤ x ≤MaxValue.

#### 例外

`value`MinValue は等しい。`value` equals MinValue.

### 例

``````using System;

public class Example
{
public static void Main()
{
int[] values = { Int32.MaxValue, 16921, 0, -804128, Int32.MinValue };
foreach (int value in values)
{
try {
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
}
catch (OverflowException) {
Console.WriteLine("Unable to calculate the absolute value of {0}.",
value);
}
}
}
}
// The example displays the following output:
//       Abs(2147483647) = 2147483647
//       Abs(16921) = 16921
//       Abs(0) = 0
//       Abs(-804128) = 804128
//       Unable to calculate the absolute value of -2147483648.
``````
``````Module Example
Public Sub Main()
Dim values() As Integer = { Int32.MaxValue, 16921, 0, -804128, Int32.MinValue }
For Each value As Integer In values
Try
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Catch e As OverflowException
Console.WriteLine("Unable to calculate the absolute value of {0}.", _
value)
End Try
Next
End Sub
End Module
' The example displays the following output:
'       Abs(2147483647) = 2147483647
'       Abs(16921) = 16921
'       Abs(0) = 0
'       Abs(-804128) = 804128
'       Unable to calculate the absolute value of -2147483648.
``````

## Abs(Int64)Abs(Int64)Abs(Int64)Abs(Int64)

64 ビット符号付き整数の絶対値を返します。Returns the absolute value of a 64-bit signed integer.

``````public:
static long Abs(long value);``````
``public static long Abs (long value);``
``static member Abs : int64 -> int64``
``Public Shared Function Abs (value As Long) As Long``

#### パラメーター

value
Int64 Int64 Int64 Int64

MinValue より大きく、MaxValue 以下の数値。A number that is greater than MinValue, but less than or equal to MaxValue.

#### 戻り値

0 ≤ x ≤MaxValue である 64 ビット符号付き整数 x。A 64-bit signed integer, x, such that 0 ≤ x ≤MaxValue.

#### 例外

`value`MinValue は等しい。`value` equals MinValue.

### 例

``````using System;

public class Example
{
public static void Main()
{
long[] values = { Int64.MaxValue, 109013, 0, -6871982, Int64.MinValue };
foreach (long value in values)
{
try {
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
}
catch (OverflowException) {
Console.WriteLine("Unable to calculate the absolute value of {0}.",
value);
}
}
}
}
// The example displays the following output:
//       Abs(9223372036854775807) = 9223372036854775807
//       Abs(109013) = 109013
//       Abs(0) = 0
//       Abs(-6871982) = 6871982
//       Unable to calculate the absolute value of -9223372036854775808.
``````
``````Module Example
Public Sub Main()
Dim values() As Long = { Int64.MaxValue, 109013, 0, -6871982, Int64.MinValue }
For Each value As Long In values
Try
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Catch e As OverflowException
Console.WriteLine("Unable to calculate the absolute value of {0}.", _
value)
End Try
Next
End Sub
End Module
' The example displays the following output:
'       Abs(9223372036854775807) = 9223372036854775807
'       Abs(109013) = 109013
'       Abs(0) = 0
'       Abs(-6871982) = 6871982
'       Unable to calculate the absolute value of -9223372036854775808.
``````

## Abs(SByte)Abs(SByte)Abs(SByte)Abs(SByte)

この API は CLS 準拠ではありません。

8 ビット符号付き整数の絶対値を返します。Returns the absolute value of an 8-bit signed integer.

``````public:
static System::SByte Abs(System::SByte value);``````
``````[System.CLSCompliant(false)]
public static sbyte Abs (sbyte value);``````
``static member Abs : sbyte -> sbyte``
``Public Shared Function Abs (value As SByte) As SByte``

#### パラメーター

value
SByte SByte SByte SByte

MinValue より大きく、MaxValue 以下の数値。A number that is greater than MinValue, but less than or equal to MaxValue.

#### 戻り値

0 ≤ x ≤MaxValue である 8 ビット符号付き整数 x。An 8-bit signed integer, x, such that 0 ≤ x ≤MaxValue.

#### 例外

`value`MinValue は等しい。`value` equals MinValue.

### 例

``````using System;

public class Example
{
public static void Main()
{
sbyte[] values = { SByte.MaxValue, 98, 0, -32, SByte.MinValue };
foreach (sbyte value in values)
{
try {
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
}
catch (OverflowException) {
Console.WriteLine("Unable to calculate the absolute value of {0}.",
value);
}
}
}
}
// The example displays the following output:
//       Abs(127) = 127
//       Abs(98) = 98
//       Abs(0) = 0
//       Abs(-32) = 32
//       Unable to calculate the absolute value of -128.
``````
``````Module Example
Public Sub Main()
Dim values() As SByte = { SByte.MaxValue, 98, 0, -32, SByte.MinValue }
For Each value As SByte In values
Try
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Catch e As OverflowException
Console.WriteLine("Unable to calculate the absolute value of {0}.", _
value)
End Try
Next
End Sub
End Module
' The example displays the following output:
'       Abs(127) = 127
'       Abs(98) = 98
'       Abs(0) = 0
'       Abs(-32) = 32
'       Unable to calculate the absolute value of -128.
``````

## Abs(Single)Abs(Single)Abs(Single)Abs(Single)

``````public:
static float Abs(float value);``````
``public static float Abs (float value);``
``static member Abs : single -> single``
``Public Shared Function Abs (value As Single) As Single``

#### パラメーター

value
Single Single Single Single

MinValue 以上で、MaxValue 以下の数値。A number that is greater than or equal to MinValue, but less than or equal to MaxValue.

#### 戻り値

0 ≤ x ≤MaxValue の単精度浮動小数点数 x。A single-precision floating-point number, x, such that 0 ≤ x ≤MaxValue.

### 例

``````using System;

public class Example
{
public static void Main()
{
float[] values= { Single.MaxValue, 16.354e-12F, 15.098123F, 0F,
-19.069713F, -15.058e17F, Single.MinValue };
foreach (float value in values)
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
}
}
// The example displays the following output:
//       Abs(3.402823E+38) = 3.402823E+38
//       Abs(1.6354E-11) = 1.6354E-11
//       Abs(15.09812) = 15.09812
//       Abs(0) = 0
//       Abs(-19.06971) = 19.06971
//       Abs(-1.5058E+18) = 1.5058E+18
//       Abs(-3.402823E+38) = 3.402823E+38
``````
``````Module Example
Public Sub Main()
Dim values() As Single = { Single.MaxValue, 16.354e-12, 15.098123, 0, _
-19.069713, -15.058e17, Single.MinValue }
For Each value As Single In values
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Next
End Sub
End Module
' The example displays the following output:
'       Abs(3.402823E+38) = 3.402823E+38
'       Abs(1.6354E-11) = 1.6354E-11
'       Abs(15.09812) = 15.09812
'       Abs(0) = 0
'       Abs(-19.06971) = 19.06971
'       Abs(-1.5058E+18) = 1.5058E+18
'       Abs(-3.402823E+38) = 3.402823E+38
``````