Taking minimum of three values

  • Thread starter Thread starter Sona
  • Start date Start date
S

Sona

I need to find a minimum of three float values.. what would be the most
efficient way of doing this? Can someone please share some code with me
for doing this? Thanks

Sona
 
Sona,
Have you looked at System.Math.Min for finding the minimum of two values.
Using the result of the min of two of the values with the third will give
you the minimum of all three.

Hope this helps
Jay
 
Assuming that the three variables are a, b and c you could simply do the
following:
float minimumValue = Math.Min( Math.Min( a, b ), c );

Its not horribly inefficient. Probably doing the comparisons yourself would
be a bit faster -- maybe.

-ben
 
Sona said:
I need to find a minimum of three float values.. what would be the most
efficient way of doing this? Can someone please share some code with me
for doing this? Thanks

float min = a;

if (b < min)
{
min = b;
}

if (c < min)
{
min = c;
}

....is probably as efficient as you will get. Any takers on a more efficient
way? :)

Hilton
 
Back
Top