Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#
maxmagnitude
math
communitycreator

What is Math.MaxMagnitude() in C#?

Arslan Bajwa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

C# has a built-in Math class that provides useful mathematical functions and operations. The class has the MaxMagnitude() function, which is used to compute the larger magnitude of two double-precision, floating-point numbers.

Syntax

public static double MaxMagnitude (double value1, double value2);

Parameters

  • value1: This is of double precision floating point type and represents the first input value for comparision. Its range is all double numbers.
  • value2: This is of double precision floating point type and represents the second input value for comparision. Its range is all double numbers.

Return value

  • Double: This returns a Double type number from value1 and value2 that has a larger magnitude.
  • NaN: The function returns this for NaN input in value1 or value2.

Example

using System;
class Educative
{
static void Main()
{
double result = Math.MaxMagnitude(20, 30);
System.Console.WriteLine("MaxMagnitude(20, 30) = "+ result);
double result1 = Math.MaxMagnitude(Double.NaN, 30);
System.Console.WriteLine("MaxMagnitude(NaN, 30) = "+ result1);
double result2 = Math.MaxMagnitude(20, -30);
System.Console.WriteLine("MaxMagnitude(20, -30) = "+ result2);
}
}

Output

MaxMagnitude(20,30) = 30
MaxMagnitude(NaN,30) = NaN
MaxMagnitude(20,-30) = 30

RELATED TAGS

c#
maxmagnitude
math
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring