C# | Math.Abs() Method | Set - 2 Last Updated : 01 Feb, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report C# | Math.Abs() Method | Set – 1 In C#, Abs() is a Math class method which is used to return the absolute value of a specified number. This method can be overload by passing the different type of parameters to it. There are total 7 methods in its overload list. Math.Abs(Decimal) Math.Abs(Double) Math.Abs(Int16) Math.Abs(Int32) Math.Abs(Int64) Math.Abs(SByte) Math.Abs(Single) Math.Abs(Int64) This method is used to return the absolute value of a 64-bit signed integer. Syntax: public static long Abs (long val); Parameter: val: It is the required number which is greater than Int64.MinValue, but less than or equal to Int64.MaxValue of type System.Int64. Return Type: It returns a 64-bit signed integer say r, such that 0 ≤ r ≤ Int64.MaxValue. Exception: This method will give OverflowException if the value of val is equals to Int64.MinValue. Example: CSharp // C# Program to illustrate the // Math.Abs(Int64) Method using System; class Geeks { // Main Method public static void Main() { // Taking long values long[] val = {Int64.MaxValue, 78345482, -4687985, 0}; // using foreach loop foreach(long value in val) // Displaying the result Console.WriteLine("Absolute value of {0} = {1}", value, Math.Abs(value)); } } Output: Absolute value of 9223372036854775807 = 9223372036854775807 Absolute value of 78345482 = 78345482 Absolute value of -4687985 = 4687985 Absolute value of 0 = 0 Math.Abs(SByte) This method is used to return the absolute value of an 8-bit signed integer. Syntax: public static sbyte Abs (sbyte val); Parameter: val: It is the required number which is greater than SByte.MinValue, but less than or equal to SByte.MaxValue of type System.SByte. Return Type: It returns a 8-bit signed integer say r, such that 0 ≤ r ≤ SByte.MaxValue. Exception: This method will give OverflowException if the value of val is equals to SByte.MinValue. Example: CSharp // C# Program to illlustrate the // Math.Abs(SByte) Method using System; class Geeks { // Main Method public static void Main() { // Taking SByte values sbyte[] sb = {SByte.MaxValue, 45, -41, 0}; // using foreach loop foreach(sbyte value in sb) // Displaying the result Console.WriteLine("Absolute value of {0} = {1}", value, Math.Abs(value)); } } Output: Absolute value of 127 = 127 Absolute value of 45 = 45 Absolute value of -41 = 41 Absolute value of 0 = 0 Math.Abs(Single) This method is used to return the absolute value of a single-precision floating-point number. Syntax: public static float Abs (float val); Parameter: val: It is the required number which is greater than or equal to Single.MinValue, but less than or equal to MaxValue of type System.Single. Return Type: It returns a single-precision floating-point number say r, such that 0 ≤ r ≤ Single.MaxValue. Note: If val is equal to NegativeInfinity or PositiveInfinity, the return value will be PositiveInfinity. If the val is equal to NaN then return value will be NaN. Example: CSharp // C# Program to illlustrate the // Math.Abs(Single) Method using System; class Geeks { // Main Method public static void Main() { float nan = float.NaN; // Taking float values float[] fl = {float.MinValue, 127.58f, 0.000f, 7556.48e10f, nan, float.MaxValue}; // using foreach loop foreach(float value in fl) // Displaying the result Console.WriteLine("Absolute value of {0} = {1}", value, Math.Abs(value)); } } Output: Absolute value of -3.402823E+38 = 3.402823E+38 Absolute value of 127.58 = 127.58 Absolute value of 0 = 0 Absolute value of 7.55648E+13 = 7.55648E+13 Absolute value of NaN = NaN Absolute value of 3.402823E+38 = 3.402823E+38 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.math.abs?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Math.Abs() Method | Set - 2 K Kirti_Mangal Follow Improve Article Tags : Misc C# CSharp-method CSharp-Math Practice Tags : Misc Similar Reads C# | Math.Abs() Method | Set - 1 In C#, Abs() is a Math class method which is used to return the absolute value of a specified number. This method can be overload by passing the different type of parameters to it. Math.Abs(Decimal) Math.Abs(Double) Math.Abs(Int16) Math.Abs(Int32) Math.Abs(Int64) Math.Abs(SByte) Math.Abs(Single) Mat 4 min read C# | Math.Sign() Method In C#, Sign() is a math class method which returns an integer that specify the sign of the number. This method can be overloaded by changing the data type of the passed arguments as follows: Math.Sign(Decimal): Returns the integer that specifies the sign of a decimal number. Math.Sign(Double): Retur 3 min read JavaScript Math abs() Method Javascript Math.abs() method is used to return the absolute value of a number. It takes a number as its parameter and returns its absolute value. Syntax:Math.abs(value)Parameters:This method accepts a single parameter as mentioned above and described below:value: The number whose absolute value is t 2 min read Javascript Math sign() Method The Math.sign() is a built-in method in JavaScript and is used to know the sign of a number, indicating whether the number specified is negative or positive.Syntax:Math.sign(number)Parameters:This method accepts a single parameter number which represents the number whose sign you want to know. Retur 2 min read MathF.Abs() Method in C# with Examples MathF.Abs(Single) Method is used to return the absolute value of a specified float number. Syntax: public static float Abs (float x); Here, it takes a standard floating point number. Return Value: This method returns a floating point value less than Single.MaxValue. Example 1: csharp // C# program t 1 min read Like