Trusted answers to developer questions

What is Math.MinMagnitude() in C#?

Free System Design Interview Course

Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2024 with this popular free course.

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

Syntax

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

Parameters

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

Return value

  • Double: This returns a Double type number from value1 and value2, which have a smaller magnitude.
  • NaN: This returns an input of NaN in value1 or value2.

Example

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

Output

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

RELATED TAGS

c#
minmagnitude
math
Did you find this helpful?