BigInteger.Negate(BigInteger) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Anula um valor especificado BigInteger .
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
O valor a negar.
Devoluções
O resultado do value parâmetro multiplicado por menos um (-1).
Exemplos
O exemplo seguinte ilustra três formas de negar o valor de um BigInteger objeto.
BigInteger number = 12645002;
Console.WriteLine(BigInteger.Negate(number)); // Displays -12645002
Console.WriteLine(-number); // Displays -12645002
Console.WriteLine(number * BigInteger.MinusOne); // Displays -12645002
let number = 12645002I
printfn $"{BigInteger.Negate number}" // Displays -12645002
printfn $"{-number}" // Displays -12645002
printfn $"{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
Observações
A negação obtém o inverso aditivo de um número. O inverso aditivo de um número é um número que produz um valor zero quando é somado ao número original.
O Negate método é implementado para linguagens que não suportam operadores personalizados. O seu comportamento é idêntico ao da negação usando o operador de negação unária. Além disso, o Negate método é um substituto útil para o operador de negação ao instanciar uma BigInteger variável, como mostrado no exemplo seguinte.
// 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);
let 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)