By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,730 Members | 1,156 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,730 IT Pros & Developers. It's quick & easy.

Taking minimum of three values

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"Sona" <so**********@nospam.com> wrote in message
news:3f********@clarion.carno.net.au...
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

Nov 15 '05 #2

P: n/a
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" <so**********@nospam.com> wrote in message
news:3f********@clarion.carno.net.au...
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

Nov 15 '05 #3

P: n/a
Sona wrote:
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
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.