Math.Abs Méthode

Définition

Retourne la valeur absolue d'un nombre spécifié.Returns the absolute value of a specified number.

Surcharges

Abs(Decimal)

Retourne la valeur absolue d'un nombre Decimal.Returns the absolute value of a Decimal number.

Abs(Double)

Retourne la valeur absolue d'un nombre à virgule flottante double précision.Returns the absolute value of a double-precision floating-point number.

Abs(Int16)

Retourne la valeur absolue d'un entier signé 16 bits.Returns the absolute value of a 16-bit signed integer.

Abs(Int32)

Retourne la valeur absolue d'un entier signé 32 bits.Returns the absolute value of a 32-bit signed integer.

Abs(Int64)

Retourne la valeur absolue d'un entier signé 64 bits.Returns the absolute value of a 64-bit signed integer.

Abs(SByte)

Retourne la valeur absolue d'un entier signé 8 bits.Returns the absolute value of an 8-bit signed integer.

Abs(Single)

Retourne la valeur absolue d'un nombre à virgule flottante simple précision.Returns the absolute value of a single-precision floating-point number.

Abs(Decimal)

Retourne la valeur absolue d'un nombre 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

Paramètres

value
Decimal

Nombre qui est supérieur ou égal à MinValue, mais inférieur ou égal à MaxValue.A number that is greater than or equal to MinValue, but less than or equal to MaxValue.

Retours

Decimal

Nombre décimal x, tel que 0 ≤ x ≤ MaxValue.A decimal number, x, such that 0 ≤ x ≤ MaxValue.

Exemples

L’exemple suivant utilise la Abs(Decimal) méthode pour obtenir la valeur absolue d’un certain nombre de Decimal valeurs.The following example uses the Abs(Decimal) method to get the absolute value of a number of Decimal values.

decimal[] decimals = { Decimal.MaxValue, 12.45M, 0M, -19.69M,
                       Decimal.MinValue };
foreach (decimal value in decimals)
   Console.WriteLine($"Abs({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

Remarques

La valeur absolue d’un Decimal est sa valeur numérique sans son signe.The absolute value of a Decimal is its numeric value without its sign. Par exemple, la valeur absolue de 1,2 et-1,2 est 1,2.For example, the absolute value of both 1.2 and -1.2 is 1.2.

S’applique à

Abs(Double)

Retourne la valeur absolue d'un nombre à virgule flottante double précision.Returns the absolute value of a double-precision floating-point number.

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

Paramètres

value
Double

Nombre qui est supérieur ou égal à MinValue, mais inférieur ou égal à MaxValue.A number that is greater than or equal to MinValue, but less than or equal to MaxValue.

Retours

Double

Nombre à virgule flottante double précision x, tel que 0 ≤ x ≤ MaxValue.A double-precision floating-point number, x, such that 0 ≤ x ≤ MaxValue.

Exemples

L’exemple suivant utilise la Abs(Double) méthode pour obtenir la valeur absolue d’un certain nombre de Double valeurs.The following example uses the Abs(Double) method to get the absolute value of a number of Double values.

double[] doubles = { Double.MaxValue, 16.354e-17, 15.098123, 0,
                     -19.069713, -15.058e18, Double.MinValue };
foreach (double value in doubles)
   Console.WriteLine($"Abs({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

Remarques

La valeur absolue d’un Double est sa valeur numérique sans son signe.The absolute value of a Double is its numeric value without its sign. Par exemple, la valeur absolue de 1.2 E03 et-1.2 E03 est 1,2 E03.For example, the absolute value of both 1.2e03 and -1.2e03 is 1.2e03.

Si value est égal à NegativeInfinity ou PositiveInfinity , la valeur de retour est PositiveInfinity .If value is equal to NegativeInfinity or PositiveInfinity, the return value is PositiveInfinity. Si value est égal à NaN , la valeur de retour est NaN .If value is equal to NaN, the return value is NaN.

S’applique à

Abs(Int16)

Retourne la valeur absolue d'un entier signé 16 bits.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

Paramètres

value
Int16

Nombre qui est supérieur à MinValue, mais inférieur ou égal à MaxValue.A number that is greater than MinValue, but less than or equal to MaxValue.

Retours

Int16

Entier signé 16 bits x, tel que 0 ≤ x ≤ MaxValue.A 16-bit signed integer, x, such that 0 ≤ x ≤ MaxValue.

Exceptions

value est égal à MinValue.value equals MinValue.

Exemples

L’exemple suivant utilise la Abs(Int16) méthode pour obtenir la valeur absolue d’un certain nombre de Int16 valeurs.The following example uses the Abs(Int16) method to get the absolute value of a number of Int16 values.

short[] values = { Int16.MaxValue, 10328, 0, -1476, Int16.MinValue };
foreach (short value in values)
{
   try {
      Console.WriteLine($"Abs({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.

Remarques

La valeur absolue d’un Int16 est sa valeur numérique sans son signe.The absolute value of an Int16 is its numeric value without its sign. Par exemple, la valeur absolue de 123 et-123 est 123.For example, the absolute value of both 123 and -123 is 123.

S’applique à

Abs(Int32)

Retourne la valeur absolue d'un entier signé 32 bits.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

Paramètres

value
Int32

Nombre qui est supérieur à MinValue, mais inférieur ou égal à MaxValue.A number that is greater than MinValue, but less than or equal to MaxValue.

Retours

Int32

Entier signé 32 bits x, tel que 0 ≤ x ≤ MaxValue.A 32-bit signed integer, x, such that 0 ≤ x ≤ MaxValue.

Exceptions

value est égal à MinValue.value equals MinValue.

Exemples

L’exemple suivant utilise la Abs(Int32) méthode pour obtenir la valeur absolue d’un certain nombre de Int32 valeurs.The following example uses the Abs(Int32) method to get the absolute value of a number of Int32 values.

int[] values = { Int32.MaxValue, 16921, 0, -804128, Int32.MinValue };
foreach (int value in values)
{
   try {
      Console.WriteLine($"Abs({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.

Remarques

La valeur absolue d’un Int32 est sa valeur numérique sans son signe.The absolute value of an Int32 is its numeric value without its sign. Par exemple, la valeur absolue de 123 et-123 est 123.For example, the absolute value of both 123 and -123 is 123.

S’applique à

Abs(Int64)

Retourne la valeur absolue d'un entier signé 64 bits.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

Paramètres

value
Int64

Nombre qui est supérieur à MinValue, mais inférieur ou égal à MaxValue.A number that is greater than MinValue, but less than or equal to MaxValue.

Retours

Int64

Entier signé 64 bits x, tel que 0 ≤ x ≤ MaxValue.A 64-bit signed integer, x, such that 0 ≤ x ≤ MaxValue.

Exceptions

value est égal à MinValue.value equals MinValue.

Exemples

L’exemple suivant utilise la Abs(Int64) méthode pour obtenir la valeur absolue d’un certain nombre de Int64 valeurs.The following example uses the Abs(Int64) method to get the absolute value of a number of Int64 values.

long[] values = { Int64.MaxValue, 109013, 0, -6871982, Int64.MinValue };
foreach (long value in values)
{
   try {
      Console.WriteLine($"Abs({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.

Remarques

La valeur absolue d’un Int64 est sa valeur numérique sans son signe.The absolute value of an Int64 is its numeric value without its sign. Par exemple, la valeur absolue de 123 et-123 est 123.For example, the absolute value of both 123 and -123 is 123.

S’applique à

Abs(SByte)

Important

Cette API n’est pas conforme CLS.

Retourne la valeur absolue d'un entier signé 8 bits.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);
[<System.CLSCompliant(false)>]
static member Abs : sbyte -> sbyte
Public Shared Function Abs (value As SByte) As SByte

Paramètres

value
SByte

Nombre qui est supérieur à MinValue, mais inférieur ou égal à MaxValue.A number that is greater than MinValue, but less than or equal to MaxValue.

Retours

SByte

Entier signé 8 bits x, tel que 0 ≤ x ≤ MaxValue.An 8-bit signed integer, x, such that 0 ≤ x ≤ MaxValue.

Attributs

Exceptions

value est égal à MinValue.value equals MinValue.

Exemples

L’exemple suivant utilise la Abs(SByte) méthode pour obtenir la valeur absolue d’un certain nombre de SByte valeurs.The following example uses the Abs(SByte) method to get the absolute value of a number of SByte values.

sbyte[] values = { SByte.MaxValue, 98, 0, -32, SByte.MinValue };
foreach (sbyte value in values)
{
   try {
      Console.WriteLine($"Abs({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.

Remarques

La valeur absolue d’un octet signé est sa valeur numérique sans son signe.The absolute value of a signed byte is its numeric value without its sign. Par exemple, la valeur absolue de 12 et-12 est 12.For example, the absolute value of both 12 and -12 is 12.

S’applique à

Abs(Single)

Retourne la valeur absolue d'un nombre à virgule flottante simple précision.Returns the absolute value of a single-precision floating-point number.

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

Paramètres

value
Single

Nombre qui est supérieur ou égal à MinValue, mais inférieur ou égal à MaxValue.A number that is greater than or equal to MinValue, but less than or equal to MaxValue.

Retours

Single

Nombre à virgule flottante simple précision x, tel que 0 ≤ x ≤ MaxValue.A single-precision floating-point number, x, such that 0 ≤ x ≤ MaxValue.

Exemples

L’exemple suivant utilise la Abs(Single) méthode pour obtenir la valeur absolue d’un certain nombre de Single valeurs.The following example uses the Abs(Single) method to get the absolute value of a number of Single values.

float[] values= { Single.MaxValue, 16.354e-12F, 15.098123F, 0F,
                  -19.069713F, -15.058e17F, Single.MinValue };
foreach (float value in values)
   Console.WriteLine($"Abs({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

Remarques

La valeur absolue d’un Single est sa valeur numérique sans son signe.The absolute value of a Single is its numeric value without its sign. Par exemple, la valeur absolue de 1.2 e-03 et-1.2 E03 est 1,2 E03.For example, the absolute value of both 1.2e-03 and -1.2e03 is 1.2e03.

Si value est égal à NegativeInfinity ou PositiveInfinity , la valeur de retour est PositiveInfinity .If value is equal to NegativeInfinity or PositiveInfinity, the return value is PositiveInfinity. Si value est égal à NaN , la valeur de retour est NaN .If value is equal to NaN, the return value is NaN.

S’applique à