How can I get max & min values

Discuss PocketC for Palm OS (including Desktop Edition)

Postby Velvis on Thu Apr 19, 2001 4:33 pm

I have a function that gets passed a float value, in addition to what the function does I would like to get the maximum and minimum value that has been passed to it. The High Value works since HighValue starts at zero, and any number passed to it will be larger the first time around. However the LowValue doesnt work since the starting LowValue is zero and is lower than any number passed.
Code is below.
Can anyone share some tips?


Point(float val, int item)
{int x,y;
if (val>HighValue) HighValue=val;
if(val<LowValue) LowValue=val;
Posts: 226
Joined: Mon Dec 11, 2000 2:32 am

Postby wolfgang on Thu Apr 19, 2001 10:40 pm


well, in "normal" C you could define HighValue and LowValue as static inside the function and initialize them with far-outlying values. In PocketC, you have to use global variables and initialize them in your main() function.



// define highest possible number
#define MAX_VAL 1e37

float HighValue, LowValue;

Point (float val, int item)
if (val > HighValue) { HighValue = val; }
if (val < LowValue) { LowValue = val; }

main ()
// initialize with impossibly low/high start values
HighValue = -MAX_VAL;
LowValue = MAX_VAL;
Composing music on the PocketPC! -
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA

Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 2 guests