4 Arithmetic
4.1 Numeric Operations
sum
SUM num1 num2
(SUM num1 num2 num3 ...)
num1 + num2
outputs the sum of its inputs.
difference
DIFFERENCE num1 num2
num1 - num2
outputs the difference of its inputs. Minus sign means infix difference
in ambiguous contexts (when preceded by a complete expression), unless
it is preceded by a space and followed by a nonspace. (See also MINUS
.)
minus
outputs the negative of its input. Minus sign means unary minus if
the previous token is an infix operator or open parenthesis, or it is
preceded by a space and followed by a nonspace. There is a difference
in binding strength between the two forms:
MINUS 3 + 4 means -(3+4)
- 3 + 4 means (-3)+4
product
PRODUCT num1 num2
(PRODUCT num1 num2 num3 ...)
num1 * num2
outputs the product of its inputs.
quotient
QUOTIENT num1 num2
(QUOTIENT num)
num1 / num2
outputs the quotient of its inputs. The quotient of two integers is an
integer if and only if the dividend is a multiple of the divisor. (In
other words, QUOTIENT 5 2 is 2.5, not 2, but QUOTIENT 4 2
is 2, not 2.0 — it does the right thing.) With a single input,
QUOTIENT
outputs the reciprocal of the input.
remainder
outputs the remainder on dividing num1 by num2; both must be
integers and the result is an integer with the same sign as num1.
modulo
outputs the remainder on dividing num1 by num2; both must be
integers and the result is an integer with the same sign as num2.
int
outputs its input with fractional part removed, i.e., an integer
with the same sign as the input, whose absolute value is the
largest integer less than or equal to the absolute value of
the input.
round
outputs the nearest integer to the input.
sqrt
outputs the square root of the input, which must be nonnegative.
power
outputs num1 to the num2 power. If num1 is negative, then
num2 must be an integer.
exp
outputs e (2.718281828+) to the input power.
log10
outputs the common logarithm of the input.
ln
outputs the natural logarithm of the input.
sin
outputs the sine of its input, which is taken in degrees.
radsin
outputs the sine of its input, which is taken in radians.
cos
outputs the cosine of its input, which is taken in degrees.
radcos
outputs the cosine of its input, which is taken in radians.
arctan
outputs the arctangent, in degrees, of its input. With two inputs,
outputs the arctangent of y/x, if x is nonzero, or 90 or –90 depending
on the sign of y, if x is zero.
radarctan
RADARCTAN num
(RADARCTAN x y)
outputs the arctangent, in radians, of its input. With two inputs,
outputs the arctangent of y/x, if x is nonzero, or pi/2 or –pi/2
depending on the sign of y, if x is zero.
The expression 2*(RADARCTAN 0 1) can be used to get the value of pi.
iseq
ISEQ from to (library procedure)
outputs a list of the integers from from to to, inclusive.
? show iseq 3 7
[3 4 5 6 7]
? show iseq 7 3
[7 6 5 4 3]
rseq
RSEQ from to count (library procedure)
outputs a list of count equally spaced rational numbers between
from and to, inclusive.
? show rseq 3 5 9
[3 3.25 3.5 3.75 4 4.25 4.5 4.75 5]
? show rseq 3 5 5
[3 3.5 4 4.5 5]
4.2 Numeric Predicates
lessp
LESSP num1 num2
LESS? num1 num2
num1 < num2
outputs TRUE
if its first input is strictly less than its second.
greaterp
GREATERP num1 num2
GREATER? num1 num2
num1 > num2
outputs TRUE
if its first input is strictly greater than its second.
lessequalp
LESSEQUALP num1 num2
LESSEQUAL? num1 num2
num1 <= num2
outputs TRUE
if its first input is less than or equal to its second.
greaterequalp
GREATEREQUALP num1 num2
GREATEREQUAL? num1 num2
num1 >= num2
outputs TRUE
if its first input is greater than or equal to its second.
4.3 Random Numbers
random
RANDOM num
(RANDOM start end)
with one input, outputs a random nonnegative integer less than its
input, which must be a positive integer.
With two inputs, RANDOM
outputs a random integer greater than or
equal to the first input, and less than or equal to the second
input. Both inputs must be integers, and the first must be less
than the second. (RANDOM 0 9) is equivalent to RANDOM 10;
(RANDOM 3 8) is equivalent to (RANDOM 6)+3.
rerandom
command. Makes the results of RANDOM
reproducible. Ordinarily the
sequence of random numbers is different each time Logo is used. If you need
the same sequence of pseudo-random numbers repeatedly, e.g. to debug a
program, say RERANDOM
before the first invocation of RANDOM
. If
you need more than one repeatable sequence, you can give RERANDOM
an integer
input; each possible input selects a unique sequence of numbers.
4.4 Print Formatting
form
outputs a word containing a printable representation of num, possibly
preceded by spaces (and therefore not a number for purposes of
performing arithmetic operations), with at least width characters,
including exactly precision digits after the decimal point. (If
precision is 0 then there will be no decimal point in the output.)
As a debugging feature, (FORM num -1 format) will print the floating
point num according to the C printf format, to allow
to hex :num
op form :num -1 "|%08X %08X|
end
to allow finding out the exact result of floating point operations. The
precise format needed may be machine-dependent.
4.5 Bitwise Operations
bitand
BITAND num1 num2
(BITAND num1 num2 num3 ...)
outputs the bitwise and of its inputs, which must be integers.
See section and .
bitor
BITOR num1 num2
(BITOR num1 num2 num3 ...)
outputs the bitwise or of its inputs, which must be integers.
See section or .
bitxor
BITXOR num1 num2
(BITXOR num1 num2 num3 ...)
outputs the bitwise exclusive or of its inputs, which must be integers.
See section or .
bitnot
outputs the bitwise not of its input, which must be an integer.
See section not .
ashift
outputs num1 arithmetic-shifted to the left by num2 bits. If
num2 is negative, the shift is to the right with sign extension. The
inputs must be integers.
lshift
outputs num1 logical-shifted to the left by num2 bits. If
num2 is negative, the shift is to the right with zero fill. The inputs
must be integers.
This document was generated on December 27, 2019 using texi2html 5.0.