IonicWind Software

Aurora Compiler => Tips and Tricks => Topic started by: pistol350 on July 06, 2007, 05:59:51 AM

Title: Min() and Max() functions
Post by: pistol350 on July 06, 2007, 05:59:51 AM
These functions take 2 arguments and return the argument with the smallest (minimum)  or the largest (maximum) value
They are very simple to use and can also be very helpful. :)
There are similar functions that support more than 2 arguments, so this may be the next step to reach. :)


"minmax.inc"

declare Min(int imin, int jmin),int;
declare Max(int imax, int jmax),int;

/* min function definition */
Sub Min(int imin, int jmin),int
{
    if (imin<jmin)
{
return imin;
}
    else
{
return jmin;
}
}



/* max function definition */
Sub Max(int imax, int jmax),int
{
    if (imax<jmax)
{
return jmax;
}
    else
{
return imax;
}
}


here is an example code

#include "minmax.inc"

global sub  main()
{
    int i = Min(5,8);
    int j = Max(5,8);

   print(" min : ",i);
   print(" min : ",j);
   print("press any key to close");
   While GetKey() = "";
   return 0;
}


I hope it can be helpful!
regards.
Peter
Title: Re: Min() and Max() functions
Post by: sapero on July 06, 2007, 07:04:21 AM
Hey, he have already __min and __max in windef.inc (include windows.inc)  :)

BTW, the 'else' is not neccesary in this case, just 'return jmin' will be fine.
Title: Re: Min() and Max() functions
Post by: pistol350 on July 06, 2007, 07:25:04 AM
LOL!
I was sure it was somewhere in the include files you added but i did not managed to find it. :D
Thanks!