[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. Arithmetic

4.1 Numeric Operations  
4.2 Numeric Predicates  
4.3 Random Numbers  
4.4 Print Formatting  
4.5 Bitwise Operations  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 Numeric Operations

sum  
difference  
minus  
product  
quotient  
remainder  
modulo  
int  
round  
sqrt  
power  
exp  
log10  
ln  
sin  
radsin  
cos  
radcos  
arctan  
radarctan  
iseq  
rseq  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

sum

 
SUM num1 num2
(SUM num1 num2 num3 ...)
num1 + num2

outputs the sum of its inputs.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

minus

 
MINUS num
- num

outputs the negative of its input. Minus sign means unary minus if it is immediately preceded by something requiring an input, or 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


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

product

 
PRODUCT num1 num2
(PRODUCT num1 num2 num3 ...)
num1 * num2

outputs the product of its inputs.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

remainder

 
REMAINDER num1 num2

outputs the remainder on dividing num1 by num2; both must be integers and the result is an integer with the same sign as num1.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

modulo

 
MODULO num1 num2

outputs the remainder on dividing num1 by num2; both must be integers and the result is an integer with the same sign as num2.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

int

 
INT num

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

round

 
ROUND num

outputs the nearest integer to the input.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

sqrt

 
SQRT num

outputs the square root of the input, which must be nonnegative.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

power

 
POWER num1 num2

outputs num1 to the num2 power. If num1 is negative, then num2 must be an integer.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

exp

 
EXP num

outputs e (2.718281828+) to the input power.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

log10

 
LOG10 num

outputs the common logarithm of the input.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

ln

 
LN num

outputs the natural logarithm of the input.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

sin

 
SIN degrees

outputs the sine of its input, which is taken in degrees.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

radsin

 
RADSIN radians

outputs the sine of its input, which is taken in radians.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

cos

 
COS degrees

outputs the cosine of its input, which is taken in degrees.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

radcos

 
RADCOS radians

outputs the cosine of its input, which is taken in radians.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

arctan

 
ARCTAN num
(ARCTAN x y)

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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]


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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]


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 Numeric Predicates

lessp  
greaterp  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

lessp

 
LESSP num1 num2
LESS? num1 num2
num1 < num2

outputs TRUE if its first input is strictly less than its second.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

greaterp

 
GREATERP num1 num2
GREATER? num1 num2
num1 > num2

outputs TRUE if its first input is strictly greater than its second.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 Random Numbers

random  
rerandom  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

random

 
RANDOM num

outputs a random nonnegative integer less than its input, which must be an integer.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

rerandom

 
RERANDOM
(RERANDOM seed)

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 Print Formatting

form  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

form

 
FORM num width precision

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5 Bitwise Operations

bitand  
bitor  
bitxor  
bitnot  
ashift  
lshift  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

bitand

 
BITAND num1 num2
(BITAND num1 num2 num3 ...)

outputs the bitwise AND of its inputs, which must be integers.

See section and .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

bitor

 
BITOR num1 num2
(BITOR num1 num2 num3 ...)

outputs the bitwise OR of its inputs, which must be integers.

See section or .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

bitxor

 
BITXOR num1 num2
(BITXOR num1 num2 num3 ...)

outputs the bitwise EXCLUSIVE OR of its inputs, which must be integers.

See section or .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

bitnot

 
BITNOT num

outputs the bitwise NOT of its input, which must be an integer.

See section not .


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

ashift

 
ASHIFT num1 num2

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

lshift

 
LSHIFT num1 num2

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.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Brian Harvey on October, 2 2002 using texi2html