BigInteger.Negate(BigInteger) Método

Definición

Crea el negativo de un valor BigInteger especificado.

public:
 static System::Numerics::BigInteger Negate(System::Numerics::BigInteger value);
public static System.Numerics.BigInteger Negate (System.Numerics.BigInteger value);
static member Negate : System.Numerics.BigInteger -> System.Numerics.BigInteger
Public Shared Function Negate (value As BigInteger) As BigInteger

Parámetros

value
BigInteger

Valor que se va a negar.

Devoluciones

Resultado del parámetro value multiplicado por menos uno (-1).

Ejemplos

En el ejemplo siguiente se muestran tres maneras de negar el valor de un BigInteger objeto .

BigInteger number = 12645002;

Console.WriteLine(BigInteger.Negate(number));        // Displays -12645002
Console.WriteLine(-number);                          // Displays -12645002
Console.WriteLine(number * BigInteger.MinusOne);     // Displays -12645002
Dim number As BigInteger = 12645002

Console.WriteLine(BigInteger.Negate(number))          ' Displays -12645002
Console.WriteLine(-number)                            ' Displays -12645002
Console.WriteLine(number * BigInteger.MinusOne)       ' Displays -12645002

Comentarios

La negación obtiene el inverso aditivo de un número. El inverso aditivo de un número es un número que genera un valor de cero cuando se agrega al número original.

El Negate método se implementa para lenguajes que no admiten operadores personalizados. Su comportamiento es idéntico a la negación mediante el operador de negación unaria. Además, el Negate método es un sustituto útil del operador de negación al crear una instancia de una BigInteger variable, como se muestra en el ejemplo siguiente.

// The statement
//    BigInteger number = -Int64.MinValue;
// produces compiler error CS0220: The operation overflows at compile time in checked mode.
// The alternative:
BigInteger number = BigInteger.Negate(Int64.MinValue);
' The statement
'    Dim number As BigInteger = -Int64.MinValue
' produces compiler error BC30439: Constant expression not representable in type 'Long'.
' The alternative:
Dim number As BigInteger = BigInteger.Negate(Int64.MinValue)

Se aplica a

Consulte también