Maximum (Max) - Parallax BASIC Stamp 2e Programming Manual

Table of Contents

Advertisement

2
2
e
M
: MAX
AXIMUM
2
1
2
e
Value MIN Limit
Where Value is a constant or variable value to perform the MIN function
upon and Limit is the minimum value that Value is allowed to be. Its logic
is, 'if Value is less than Limit, then make result = Limit; if Value is greater
than or equal to Limit, make result = Value.' MIN works in positive math
only; its comparisons are not valid when used on two's complement
negative numbers, since the positive-integer representation of a number
like -1 ($FFFF or 65535 in unsigned decimal) is larger than that of a
number like 10 ($000A or 10 decimal). Use MIN only with unsigned
integers. Because of the way fixed-size integers work, you should be
careful when using an expression involving MIN 0. For example, 0-1 MIN
0 will result in 65535 because of the way fixed-size integers wrap around.
1
SYMBOL
Value1 = W0
SYMBOL
Value2 = W1
FOR Value1= 100 TO 0 STEP -10
Value2 = Value1 MIN 50
DEBUG Value2
NEXT
-- or --
2
2
Value1
VAR
sx
p
FOR Value1= 100 TO 0 STEP 10
DEBUG ? Value1 MIN 50
NEXT
The Maximum operator (MAX) limits a value to a specified 16-bit positive
maximum. The syntax of MAX is:
2
2
p
sx
Value MAX Limit
Where Value is a constant or variable value to perform the MAX function
upon and Limit is the maximum value that Value is allowed to be. Its logic
is, 'if Value is greater than Limit, then make result = Limit; if Value is less
than or equal to Limit, make result = Value.' MAX works in positive math
only; its comparisons are not valid when used on two's complement
negative numbers, since the positive-integer representation of a number
like -1 ($FFFF or 65535 in unsigned decimal) is larger than that of a
number like 10 ($000A or 10 decimal). Use MAX only with unsigned
integers. Because of the way fixed-size integers work, you should be
careful when using an expression involving MAX 65535. For example,
4: BASIC Stamp Architecture – MAX
WORD
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 71
' Walk value of Value1 from 100 to 0.
' Use MIN to clamp at 50.
' Show "clamped" value
' Walk value of Value1 from 100 to 0.
' Show Value1, but use MIN to clamp at 50.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?

Table of Contents