MAX: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
{{PageSyntax}} | {{PageSyntax}} | ||
: {{Parameter|maximum | : {{Parameter|maximum}} = [[_MAX]]({{Parameter|value1}}, {{Parameter|value2}}) | ||
{{PageParameters}} | {{PageParameters}} | ||
* {{Parameter|value1}} and {{Parameter|value2}} are the two numbers to compare, any integer or floating point type is supported. | * {{Parameter|value1}} and {{Parameter|value2}} are the two numbers to compare, any integer or floating point type is supported. | ||
* {{Parameter|maximum | * {{Parameter|maximum}} is the greater of both values. The [[Variable Types|type]] depends on the returned value and will be a best fit without losing precision (see Availability notes below). | ||
Line 28: | Line 28: | ||
</gallery> | </gallery> | ||
<!-- additional availability notes go below here --> | <!-- additional availability notes go below here --> | ||
* Before v4.2.0 the return type was always [[_FLOAT]]. | |||
Latest revision as of 11:26, 1 June 2025
The _MAX function returns the greater of two given numeric values.
Syntax
- maximum = _MAX(value1, value2)
Parameters
- value1 and value2 are the two numbers to compare, any integer or floating point type is supported.
- maximum is the greater of both values. The type depends on the returned value and will be a best fit without losing precision (see Availability notes below).
Description
- The function compares the given numeric values and then returns the greater of both numbers.
- Will return value1 if the values are equivalent.
Availability
-
none
-
v4.0.0
-
yes
-
yes
-
yes
- Before v4.2.0 the return type was always _FLOAT.
Examples
'minimum of two values PRINT _MIN(345, 123) PRINT _MIN(5.0001, 5.0) PRINT _MIN(-34, -1.0E+1) PRINT 'maximum 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) |
123 5 -34 345 5.0001 -10 123 413 |
- Example 2
- Find the minimum and maximum values in a numeric array.
'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 |
See also