4: BASIC Stamp Architecture – MAX
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 71
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.
SYMBOL Value1 = W0
SYMBOL Value2 = W1
FOR Value1= 100 TO 0 STEP -10 ' Walk value of Value1 from 100 to 0.
Value2 = Value1 MIN 50 ' Use MIN to clamp at 50.
DEBUG Value2 ' Show "clamped" value
NEXT
-- or --
Value1 VAR WORD
FOR Value1= 100 TO 0 STEP 10 ' Walk value of Value1 from 100 to 0.
DEBUG ? Value1 MIN 50 ' Show Value1, but use MIN to clamp at 50.
NEXT
The Maximum operator (MAX) limits a value to a specified 16-bit positive
maximum. The syntax of MAX is:
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,
1
2
e
2
sx
2
p
2
M
AXIMUM
: MAX
1
2
e
2
sx
2
p
2
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...