BERKELEY LOGO 6.1: 4 Arithmetic

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

# 4 Arithmetic

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

## 4.1 Numeric Operations

[ << ] | [ < ] | [ 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 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

[ << ] | [ < ] | [ 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

[ << ] | [ < ] | [ 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] | [ ? ]

### lessequalp

    LESSEQUALP num1 num2
    LESSEQUAL? num1 num2
    num1 <= num2

outputs `TRUE` if its first input is less than or equal to its second.

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

### greaterequalp

    GREATEREQUALP num1 num2
    GREATEREQUAL? num1 num2
    num1 >= num2

outputs `TRUE` if its first input is greater than or equal to its second.

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

## 4.3 Random Numbers

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

### 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`.

[ << ] | [ < ] | [ 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

[ << ] | [ < ] | [ 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

[ << ] | [ < ] | [ 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 on December 27, 2019 using texi2html 5.0.