Specifications

BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 243
2
Its logic is, ‘if value is less than limit, then make value = limit; if value
is greater than or equal to limit, leave value alone.’ MIN works in posi-
tive math only; its comparisons are not valid when used on two’s
complement negative numbers, since the positive-integer representa-
tion 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.
for w1 = 100 to 0 step -10 ' Walk value of w1 from 100 to 0.
debug ? w1 MIN 50 ' Show w1, but use MIN to clamp at 50.
next
MAX
Limits a value to a specified 16-bit positive maximum. The syntax of
MAX is:
value MAX limit
Where:
value is value to perform the MAX function upon.
limit is the maximum value that value is allowed to be.
Its logic is, ‘if value is greater than limit, then make value = limit; if
value is less than or equal to limit, leave value alone.’ MAX works in
positive math only; its comparisons are not valid when used on two’s
complement negative numbers, since the positive-integer representa-
tion 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. Also be careful of expressions involving MAX
65535. For example 65535 + 1 MAX 65535 will result in 0 because of the
way fixed-size integers wrap around.
for w1 = 0 to 100 step 10 ' Walk value of w1 from 0 to 100.
debug ? w1 MAX 50 ' Show w1, but use MAX to clamp at 50.
next