次の方法で共有


Math.Abs メソッド (Int16)

16 ビット符号付き整数の絶対値を返します。

Overloads Public Shared Function Abs( _
   ByVal value As Short _) As Short
[C#]
public static short Abs(shortvalue);
[C++]
public: static short Abs(shortvalue);
[JScript]
public static function Abs(
   value : Int16) : Int16;

パラメータ

戻り値

0 ≤ x ≤ MaxValue の 16 ビット符号付き整数 x。

例外

例外の種類 条件
OverflowException value と MinValue が等しい値です。

使用例

 
' This example demonstrates Math.Abs()
Imports System

Class Sample
   Public Shared Sub Main()
      ' Dim sb1 As System.SByte = - 16 'Signed Bytes are not supported.
      ' Dim sb2 As System.SByte = 16   'Signed Bytes are not supported.
      Dim sh1 As Short = - 15
      Dim sh2 As Short = 15
      Dim in1 As Integer = - 14
      Dim in2 As Integer = 14
      Dim lg1 As Long = - 13
      Dim lg2 As Long = 13
      Dim fl1 As Single = - 12F
      Dim fl2 As Single = 12F
      Dim db1 As Double = - 11.1
      Dim db2 As Double = 11.1
      Dim de1 As [Decimal] = - 10D
      Dim de2 As [Decimal] = 10D
      
      Console.WriteLine()
      ' Signed bytes are not supported.
      ' Console.WriteLine("SByte:   1) {0,-5} 2) {1,-5}", Math.Abs(sb1), Math.Abs(sb2))
      Console.WriteLine("Int16:   1) {0,-5} 2) {1,-5}", Math.Abs(sh1), Math.Abs(sh2))
      Console.WriteLine("Int32:   1) {0,-5} 2) {1,-5}", Math.Abs(in1), Math.Abs(in2))
      Console.WriteLine("Int64:   1) {0,-5} 2) {1,-5}", Math.Abs(lg1), Math.Abs(lg2))
      Console.WriteLine("Single:  1) {0,-5} 2) {1,-5}", Math.Abs(fl1), Math.Abs(fl2))
      Console.WriteLine("Double:  1) {0,-5} 2) {1,-5}", Math.Abs(db1), Math.Abs(db2))
      Console.WriteLine("Decimal: 1) {0,-5} 2) {1,-5}", Math.Abs(de1), Math.Abs(de2))
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'Int16:   1) 15    2) 15
'Int32:   1) 14    2) 14
'Int64:   1) 13    2) 13
'Single:  1) 12    2) 12
'Double:  1) 11.1  2) 11.1
'Decimal: 1) 10.0  2) 10.0
'

[C#] 
// This example demonstrates Math.Abs()
using System;

class Sample 
{
    public static void Main()
    {
    sbyte    sb1 = -16, sb2 = 16;
    short    sh1 = -15, sh2 = 15;
    int      in1 = -14, in2 = 14;
    long     lg1 = -13, lg2 = 13;
    float    fl1 = -12.0f, fl2 = 12.0f;
    double   db1 = -11.1, db2 = 11.1;
    Decimal  de1 = -10.0m, de2 = 10.0m;

    Console.WriteLine();
    Console.WriteLine("SByte:   1) {0,-5} 2) {1,-5}", Math.Abs(sb1), Math.Abs(sb2));
    Console.WriteLine("Int16:   1) {0,-5} 2) {1,-5}", Math.Abs(sh1), Math.Abs(sh2));
    Console.WriteLine("Int32:   1) {0,-5} 2) {1,-5}", Math.Abs(in1), Math.Abs(in2));
    Console.WriteLine("Int64:   1) {0,-5} 2) {1,-5}", Math.Abs(lg1), Math.Abs(lg2));
    Console.WriteLine("Single:  1) {0,-5} 2) {1,-5}", Math.Abs(fl1), Math.Abs(fl2));
    Console.WriteLine("Double:  1) {0,-5} 2) {1,-5}", Math.Abs(db1), Math.Abs(db2));
    Console.WriteLine("Decimal: 1) {0,-5} 2) {1,-5}", Math.Abs(de1), Math.Abs(de2));
    }
}
/*
This example produces the following results:

SByte:   1) 16    2) 16
Int16:   1) 15    2) 15
Int32:   1) 14    2) 14
Int64:   1) 13    2) 13
Single:  1) 12    2) 12
Double:  1) 11.1  2) 11.1
Decimal: 1) 10.0  2) 10.0
*/

[C++] 
// This example demonstrates Math.Abs()
#using <mscorlib.dll>
using namespace System;

int main()
{
    SByte    sb1 = -16, sb2 = 16;
    Int16    sh1 = -15, sh2 = 15;
    Int32    in1 = -14, in2 = 14;
    Int64    lg1 = -13, lg2 = 13;
    Single   fl1 = -12.0f, fl2 = 12.0f;
    Double   db1 = -11.1, db2 = 11.1;
    Decimal  de1 = Decimal::Parse(S"-10.0"), de2 = Decimal::Parse(S"10.0");

    Console::WriteLine();
    Console::WriteLine(S"SByte:   1) {0,-5} 2) {1,-5}", __box(Math::Abs(sb1)), __box(Math::Abs(sb2)));
    Console::WriteLine(S"Int16:   1) {0,-5} 2) {1,-5}", __box(Math::Abs(sh1)), __box(Math::Abs(sh2)));
    Console::WriteLine(S"Int32:   1) {0,-5} 2) {1,-5}", __box(Math::Abs(in1)), __box(Math::Abs(in2)));
    Console::WriteLine(S"Int64:   1) {0,-5} 2) {1,-5}", __box(Math::Abs(lg1)), __box(Math::Abs(lg2)));
    Console::WriteLine(S"Single:  1) {0,-5} 2) {1,-5}", __box(Math::Abs(fl1)), __box(Math::Abs(fl2)));
    Console::WriteLine(S"Double:  1) {0,-5} 2) {1,-5}", __box(Math::Abs(db1)), __box(Math::Abs(db2)));
    Console::WriteLine(S"Decimal: 1) {0,-5} 2) {1,-5}", __box(Math::Abs(de1)), __box(Math::Abs(de2)));
}
/*
This example produces the following results:

SByte:   1) 16    2) 16
Int16:   1) 15    2) 15
Int32:   1) 14    2) 14
Int64:   1) 13    2) 13
Single:  1) 12    2) 12
Double:  1) 11.1  2) 11.1
Decimal: 1) 10.0  2) 10.0
*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

Math クラス | Math メンバ | System 名前空間 | Math.Abs オーバーロードの一覧