Two more really simple commands thich were added in version 4.0 for us, and which I'll cover here together as they both work exactly the same way: _MIN and _MAX.
The syntax for these are as simple as:
value = _MIN(num1, num2)
value = _MAX(num1, num2)
And, what these do for us is tell us which is the smallest (minimum) number and which is the largest (maximum) value.
The above would print:
Another useful application could be to find the minimum and maximum values in a numeric array:
That's all there is to these two commands as well. They're simple, straightforward functions which nobody should have any real issues implementing and using. They really don't need much explanation as a KotD, except to help draw awareness so folks will realize they're in the language now and there for you to use if/when you need them.
_MIN returns the lesser of two numbers, _MAX returns the greater of two numbers. What more needs be said about them?
The syntax for these are as simple as:
value = _MIN(num1, num2)
value = _MAX(num1, num2)
And, what these do for us is tell us which is the smallest (minimum) number and which is the largest (maximum) value.
Code: (Select All)
'maximum of two values
PRINT _MIN(345, 123)
PRINT _MIN(5.0001, 5.0)
PRINT _MIN(-34, -1.0E+1)
PRINT
'minimum of two values
PRINT _MAX(345, 123)
PRINT _MAX(5.0001, 5.0)
PRINT _MAX(-34, -1.0E+1)
PRINT
'min/max of multiple values
PRINT _MIN(_MIN(345, 123), 255)
PRINT _MAX(_MAX(_MAX(345, 123), 413), 255)
The above would print:
Quote: 123
5
-34
345
5.0001
-10
123
413
Another useful application could be to find the minimum and maximum values in a numeric array:
Code: (Select All)
'min/max in array
DIM a(5): RANDOMIZE TIMER 'some random values
a(0) = INT(RND * 10): a(1) = INT(RND * 10): a(2) = INT(RND * 10)
a(3) = INT(RND * 10): a(4) = INT(RND * 10): a(5) = INT(RND * 10)
PRINT "array values:"
FOR i = 0 TO 5: PRINT a(i);: NEXT i: PRINT: PRINT 'print array
minimum = _MIN(a(0), a(1)) 'initial min/max
maximum = _MAX(a(0), a(1))
FOR i = 2 TO 5
minimum = _MIN(minimum, a(i)) 'check remaining indexes
maximum = _MAX(maximum, a(i))
NEXT i
PRINT "array minimum ="; minimum
PRINT "array maximum ="; maximum
That's all there is to these two commands as well. They're simple, straightforward functions which nobody should have any real issues implementing and using. They really don't need much explanation as a KotD, except to help draw awareness so folks will realize they're in the language now and there for you to use if/when you need them.
_MIN returns the lesser of two numbers, _MAX returns the greater of two numbers. What more needs be said about them?