C# Math Abs(Int64)
Description
Math Abs(Int64)
returns the absolute value of a 64-bit
signed integer.
Syntax
Math.Abs(Int64)
has the following syntax.
public static long Abs(
long value
)
Parameters
Math.Abs(Int64)
has the following parameters.
value
- A number that is greater than Int64.MinValue, but less than or equal to Int64.MaxValue.
Returns
Math.Abs(Int64)
method returns A 64-bit signed integer, x, such that 0 d x d Int64.MaxValue.
Example
The following example uses the Abs(Int64) method to get the absolute value of a number of Int64 values.
/*w w w . jav a 2 s . c o m*/
using System;
public class Example
{
public static void Main()
{
long[] values = { Int64.MaxValue, 112345, 0, -6876543, 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 code above generates the following result.