Specifications
BASIC Stamp II
Page 236 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Unary (one-argument) Operators
Six Unary Operators are listed and explained below.
Table M-5. Unary Operators
Operator Description
ABS Returns absolute value
SQR Returns square root of value
DCD 2
n
-power decoder
NCD Priority encoder of a 16-bit value
SIN Returns two’s compliment sine
COS Returns two’s compliment cosine
ABS
Converts a signed (two’s complement) 16-bit number to its absolute
value. The absolute value of a number is a positive number represent-
ing the difference between that number and 0. For example, the abso-
lute value of -99 is 99. The absolute value of 99 is also 99. ABS can be
said to strip off the minus sign from a negative number, leaving posi-
tive numbers unchanged.
ABS works on two’s complement negative numbers. Examples of ABS
at work:
w1 = -99 ' Put -99 (two's complement format) into w1.
debug sdec ? w1 ' Display it on the screen as a signed #.
w1 = ABS w1 ' Now take its absolute value.
debug sdec ? w1 ' Display it on the screen as a signed #.
SQR
Computes the integer square root of an unsigned 16-bit number. (The
number must be unsigned, when you think about it, because the square
root of a negative number is an ‘imaginary’ number.) Remember that
most square roots have a fractional part that the BS2 discards in doing
its integer-only math. So it computes the square root of 100 as 10 (cor-
rect), but the square root of 99 as 9 (the actual is close to 9.95). Example:










