Having trouble comparing 4 float values in objective c, I would like to return the highest or equal values of these 4 integers. As you can see two are the same here.
This is the NSLOG output
2011-08-17 17:17:30.328 [21087:c203] 1 = 6.000000
2011-08-17 17:17:30.328 [21087:c203] 2 = 4.400000
2011-08-17 17:17:30.352 [21087:c203] 3 = 0.000000
2011-08-17 17:17:30.353 [21087:c203] 4 = 6.000000
Lets say 1-4
I have tried the MAX(1,2) Statement
Also checked >= value using if and statements too..
I am able to write my own code for comparing the values using an algorythm but I wanted to check to see if there is an easier way to do it and save me some headache??
Perhaps creating a float with a really high value and then comparing which one was the closest to it??
I have tried reading this site and its just confusing me
I am kind of new to objective c, have done it for 2 years but still sometimes it stumps you!!
Edit – Solved by brain!..
2011-08-18 12:10:26.798 iT[2093:c203] 1 = 6.710000
2011-08-18 12:10:26.798 iT[2093:c203] 2 = 0.000000
2011-08-18 12:10:26.799 iT[2093:c203] 3 = 7.000000
2011-08-18 12:10:26.800 iT[2093:c203] 4 is 9.000000
float max = MAX(1,MAX(2,MAX(3,4))); NSLog(@"Max is %f", max);
NSLog Output "Max is 9.000000"
Such an easy way to solve it, Brilliant!
Seems pretty simple to me to just nest the max calls:
Where 1,2,3,4 refer to the variable names.
Usually this sort of thing is done over collections, in which case you can so something like this (in pseudocode):