### Table of Contents

# Math

Arithmetic computations.

Logo understands quite a lot of math commands, from simple addition and subtraction up to functions like the cosecant, or the square root. Random numbers are part of the math functions as well.

## ^ (POWER)

Raises a number to the power of another number.

#### Syntax

number ^ number POWER number number (POWER number number number ...)

#### Description

POWER raises the first number to the power of the second number.
Its abbreviation is ^. When given multiple inputs, POWER and all its inputs
must be enclosed in parentheses. The ^ symbol for POWER may be used as either
a prefix or infix operator. See also `EXPN`

.

#### Example

## - (DIFFERENCE)

Outputs the difference of two or more numbers.

#### Syntax

number1 - number2 DIFFERENCE number1 number2 (DIFFERENCE number1 number2 number3 ...)

#### Description

DIFFERENCE reports the result of subtracting its inputs. DIFFERENCE expects two inputs, but will accept more if it and its inputs are enclosed within parentheses. DIFFERENCE is equivalent to the prefix or infix operator -.

#### Example

## + (SUM)

Reports the sum of its inputs.

#### Syntax

number1 + number2 SUM number1 number2 (SUM number1 number2 number3 ...)

#### Description

SUM reports the result of adding its inputs. SUM expects two inputs, but will accept more if it and its inputs are enclosed within parentheses. SUM is equivalent to the infix operator +.

#### Example

## * (PRODUCT)

Calculates the product of its inputs.

#### Syntax

number * number PRODUCT number number (PRODUCT number number number)

#### Description

PRODUCT multiplies its inputs and reports the result. PRODUCT expects two inputs, but will accept more if it and all its inputs are enclosed in parentheses. PRODUCT is equivalent to *. When used as the * symbol, PRODUCT may be a prefix or an infix operator.

#### Example

PRODUCT 2 3Result: 6PRODUCT 4 -1.2Result: -4.8PRODUCT -.5 -1.5Result: 0.75(PRODUCT 2 3 4 5)Result: 120

## / (QUOTIENT)

Reports the quotient of its inputs.

#### Syntax

number / number QUOTIENT number number (QUOTIENT number number number ...)

#### Description

QUOTIENT reports the result of dividing the first input by the second input.
QUOTIENT expects two inputs, but will accept more if it and all its inputs
are enclosed in parentheses. The symbol “/” can be used as a prefix
or an infix operator. See also `%`

and `MODULO`

.

#### Example

## % (REMAINDER)

Outputs the remainder of two numbers.

#### Syntax

dividend % divisor REMAINDER dividend divisor

#### Description

REMAINDER reports the number that is the remainder of dividing
the first input by the second. The symbol “%” can be used as a prefix
or an infix operator. See also `/`

.

REMAINDER reports the result of `(dividend - (divisor * int(dividend /divisor)))`

.
The result is the same as for `MODULO`

if the signs of both operand are
the same, but are different from `MODULO`

when the signs are different.

Until Logo version 4.0.4, REMAINDER was an alias for `MODULO`

.

#### Example

## = (.EQ,EQUAL?,EQUALP)

Tests its inputs for equality.

#### Syntax

object = object = object object

#### Description

The equality operator compares two objects. If they are equal, the output is
TRUE; otherwise it is FALSE. This operator is the same as the
`=`

command. The operator “=” may be used either as a prefix or as an infix operator.

The value of the `:EPSILON`

variable determines how the equality operator compares
two numbers. See `:EPSILON`

for details.

#### Example

4 = 5Result: FALSE= 4 5Result: FALSE.EQ 5 5Result: TRUEEQUAL? [6] [6]Result: TRUEEQUAL? 6 [6]Result: FALSE

## <> (!=,.NE,NOT.EQUAL?,NOT.EQUALP,NOTEQUAL?,NOTEQUALP)

Tests its inputs for inequality.

#### Syntax

object != object object <> object NOTEQUAL? object object

#### Description

NOTEQUAL? reports TRUE if its two inputs are not equal; otherwise it reports FALSE. Its inputs may be numbers, words, or lists. The symbols != and <> are abbreviations for NOTEQUAL?. The symbols “<>” and “!=” may be used as infix or prefix operators.

The value of the `:EPSILON`

variable determines how the inequality operator compares
two numbers. See `:EPSILON`

for details.

#### Example

NOTEQUAL? 6 6Result: TRUENOTEQUAL? 6 66Result: TRUENOTEQUAL? "AZURE "AZUREResult: FALSENOTEQUAL? [SPRING GREEN] [SPRING GREEN]Result: FALSENOTEQUAL? "AZURE [AZURE]Result: TRUE

## < (.LT,LESS?,LESSP)

Tests if its first input is less than its second input.

#### Syntax

number < number .LT number number

#### Description

The Less Than operator compares two numbers. If the first number is less than the second number, the output is TRUE; otherwise it is FALSE. The symbol “<” may be used either as a prefix or as an infix operator.

#### Example

## > (GREATER?,GREATERP,.GT)

Tests if its first input is greater than its second input.

#### Syntax

number > number .GT number number

#### Description

The Greater Than operator compares two numbers. If the first number is greater than the second number, the output is TRUE; otherwise it is FALSE. The symbol “>” may be used either as a prefix or as an infix operator.

#### Example

## >= (.GE,GREATEREQUAL?,GREATEREQUALP)

Tests if its first input is greater than or equal to its second input.

#### Syntax

number >= number .GE number number

#### Description

The Greater Than or Equal operator compares two numbers. If the first number is greater than or equal to the second number, the output is TRUE; otherwise, it is FALSE. The symbol “>=” may be used either as a prefix or as an infix operator.

#### Example

## <= (.LE,LESSEQUAL?,LESSEQUALP)

Tests if its first input is less than or equal to its second input.

#### Syntax

number <= number .LE number number

#### Description

The Less Than or Equal operator compares two numbers. If the first number is less than or equal to the second number, the output is TRUE; otherwise it is FALSE. The symbol “⇐” may be used either as a prefix or as an infix operator.

#### Example

## ABS

Reports the absolute value of a number.

#### Syntax

ABS number

#### Description

ABS reports the absolute value of its input.

#### Example

## AND

Logical AND.

#### Syntax

AND input1 input2 (AND input1 input2 input3 ...)

#### Description

AND accepts two or more inputs, which must be either TRUE or FALSE. AND reports
TRUE if all of its inputs are true; otherwise it reports FALSE. By default, AND
expects two inputs. If more inputs are supplied, both AND and its inputs must be enclosed in
parentheses. See also `OR`

.

#### Example

## ARCCOS (ACOS)

Reports the arccosine.

#### Syntax

ARCCOS number

#### Description

ARCCOS takes as input a number between -1 and 1 and reports its arccosine, a value between 0 and 180.

#### Example

## ARCCOT (ACOT)

Reports the arccotangent.

#### Syntax

ARCCOT number

#### Description

ARCCOT reports the arccotangent of its input.

#### Example

## ARCCSC (ACSC)

Reports the arccosecant.

#### Syntax

ARCCSC number

#### Description

ARCCSC reports the arccosecant of its input.

#### Example

## ARCSEC (ASEC)

Reports the arcsecant.

#### Syntax

ARCSEC number

#### Description

ARCSEC reports the arcsecant of its input.

#### Example

## ARCSIN (ASIN)

Reports the arcsine.

#### Syntax

ARCSIN number

#### Description

ARCSIN takes as input a number between -1 and 1 and reports its arcsine, a value between -90 and 90.

#### Example

## ARCTAN (ATAN)

Reports the arctangent.

#### Syntax

ARCTAN number

#### Description

ARCTAN reports the arc tangent of its input as degrees.

#### Example

## ARCTAN2 (ATAN2)

Reports the polar angle heading of the motion vector (position change) deltaX deltaY.

#### Syntax

ARCTAN2 deltaX deltaY

#### Description

ARCTAN2 reports the full-circle polar angle (in degrees) of its input motion vector deltaX deltaY. Output 0 represents the positive x-axis direction (3 o'clock). Polar angles increase going counter clockwise.

See also `PANGLE`

, `PSETHEADING`

and `PHEADING`

.

#### Example

## COS

Reports the cosine.

#### Syntax

COS number

#### Description

COS reports the cosine of its input, a number of degrees. Remember that COS x = adjacent / hypotenuse.
See also `ARCTAN`

and `SIN`

.

#### Example

## COT

Reports the cotangent.

#### Syntax

COT number

#### Description

COT reports the cotangent of its input.

#### Example

## CSC

Reports the cosecant.

#### Syntax

CSC number

#### Description

CSC reports the cosecant of its input.

#### Example

## EXPN (EXP)

Calculates the natural base e raised to a power.

#### Syntax

EXPN number

#### Description

EXPN calculates the natural base e (2.7183. . .) raised to the power
specified by its input. See also `^`

.

#### Example

## INT

Reports the integer part of a number.

#### Syntax

INT number

#### Description

INT reports the integer portion of its input by removing the decimal portion, if any.
No rounding occurs. See also `ROUND`

.

#### Example

## LOG (LN)

Outputs the natural logarithm of its input.

#### Syntax

LOG number

#### Description

LOG reports the natural logarithm of its input. See also `LOG10`

.

#### Example

## LOG10

Outputs the logarithm of its input.

#### Syntax

LOG10 number

#### Description

LOG10 reports the base 10 logarithm of its input. See also `LOG`

.

#### Example

## LOGAND

Combines its inputs with a boolean AND operation.

#### Syntax

LOGAND integer1 integer2

#### Description

LOGAND reports the bitwise logical AND of its two inputs. Each input is expressed internally as a 32 digit binary number. A logical AND operation is performed on the pair of binary digits (bits) in each position, resulting in a 32 bit integer. The logical AND operation is defined on the binary digits 0 and 1 as follows:

`LOGAND 0 0 = 0`

`LOGAND 1 0 = 0`

`LOGAND 0 1 = 0`

`LOGAND 1 1 = 1`

#### Example

## LOGNOT

Reports the bitwise logical complement of its input.

#### Syntax

LOGNOT integer

#### Description

LOGNOT reports the bitwise logical complement of its input, replacing all 1's
with 0's and all 0's with 1's. Since integers are stored in the computer as
base 2 numbers 32 digits long, all the leading 0's turn into 1's.
See also `LOGAND`

, `LOGOR`

, and `LOGXOR`

.

#### Example

## LOGOR

Combines its inputs with a boolean OR operation.

#### Syntax

LOGOR integer1 integer2

#### Description

LOGOR reports the bitwise logical OR of its two inputs. Each input is expressed internally as a 32 digit binary number. A logical OR operation is performed on the pair of binary digits (bits) in each position, resulting in a 32 bit integer. The logical OR operation is defined on the binary digits 0 and 1 as follows:

`LOGOR 0 0 = 0`

`LOGOR 1 0 = 1`

`LOGOR 0 1 = 1`

`LOGOR 1 1 = 1`

#### Example

## LOGXOR

Combines its inputs with a boolean XOR operation.

#### Syntax

LOGXOR integer1 integer2

#### Description

LOGXOR reports the bitwise logical XOR of its two inputs. Each input is expressed internally as a 32 digit binary number. A logical XOR operation is performed on the pair of binary digits (bits) in each position, resulting in a 32 bit integer. The logical XOR operation is defined on the binary digits 0 and 1 as follows:

`LOGXOR 0 0 = 0`

`LOGXOR 1 0 = 1`

`LOGXOR 0 1 = 1`

`LOGXOR 1 1 = 0`

#### Example

## LSH (ASHIFT)

Shifts its input with sign extension.

#### Syntax

LSH integer integer

#### Description

LSH reports the first input logically shifted the number of bit positions
specified by the second input. If the second input is positive, the logical
shift is to the left. If the second input is negative, the logical shift is to the right, with the extension of the sign bit. This is the difference to `LSHIFT`

.

#### Example

## LSHIFT

Shifts its input without sign extension.

#### Syntax

LSHIFT integer integer

#### Description

LSHIFT reports the first input logically shifted the number of bit positions
specified by the second input. If the second input is positive, the logical
shift is to the left. If the second input is negative, the logical shift is to the right, filling up the field with zero bits. This is the difference to `LSH`

.

See also `LSH`

.

#### Example

## MINUS

Outputs the negative value of its input.

#### Syntax

MINUS number

#### Description

MINUS reports the result of subtracting its input from 0. Note that MINUS binds less than other operators. Thus, MINUS 3 + 4 is -7 (-(3+4)) and not 1 (-3+4).

#### Example

## MODULO

Outputs the remainder of two numbers.

#### Syntax

MODULO dividend divisor

#### Description

MODULO reports the number that is the remainder of dividing
the first input by the second. See also `%`

and `/`

.

MODULO reports the result of `(dividend - (divisor * floor(dividend / divisor)))`

.
The result is the same as for `%`

if the signs of both operand are
the same, but are different from `%`

when the signs are different.

#### Example

## NOT

Negates its input.

#### Syntax

NOT expression

#### Description

NOT reports TRUE if its input is false; otherwise it reports FALSE.

#### Example

NOT "FALSEResult: TRUENOT "TRUEResult: FALSENOT NUMBER? "AResult: TRUEIF NOT (2 > 3) THEN PRINT "YESYES

## OR

Performs a logical OR on its input.

#### Syntax

OR object1 object2 (OR object1 object2 object3 ...)

#### Description

OR reports FALSE if all of its inputs are false; otherwise, it reports TRUE. OR accepts two or more inputs, which must be either TRUE or FALSE.

#### Example

OR "TRUE "TRUEResult: TRUEOR "TRUE "FALSEResult: TRUE(OR "FALSE "TRUE "FALSE)Result: TRUEIF OR (2 = 3) (3 = 3) [PRINT "YES]YES

## PI

Reports the number Pi.

#### Syntax

PI

#### Description

PI reports the value of pi. The number of digits displayed for PI is determined
by the current value of `:PRECISION`

. The full value of PI is always used in
calculations, regardless of the value of `:PRECISION`

.

#### Example

## RADARCTAN (RADATAN)

Reports the arc tangent of an angle expressed in radians.

#### Syntax

RADARCTAN number

#### Description

RADARCTAN reports the arc tangent of its input as radians.
If RADARCTAN has two inputs x and y, it uses y/x if x is nonzero; if x is zero,
it outputs PI/2 if y is positive, or -PI/2 if y is negative. To compute the value of
pi, use 2*(RADARCTAN 0 1), or use `PI`

.

#### Example

## RADCOS

Reports the cosine of an angle expressed in radians.

#### Syntax

RADCOS number

#### Description

RADCOS reports the cosine of its input as radians. Remember that RADCOS x = adjacent / hypotenuse.
See also `RADARCTAN`

and `RADSIN`

.

#### Example

## RADSIN

Reports the sine of an angle expressed in radians.

#### Syntax

RADSIN number

#### Description

RADSIN reports the sine of its input, which is the number of radians in an angle.
Remember that SIN x = opposite/hypotenuse. See also `RADARCTAN`

and `RADCOS`

.

#### Example

## RANDOM

Outputs a random number.

#### Syntax

RANDOM number (RANDOM bottom top)

#### Description

RANDOM reports a randomly selected number from 1 through its input. The output can only be a positive integer. For example: RANDOM 5 could report 1, 2, 3, 4, or 5. If RANDOM has two inputs, RANDOM outputs a random number between, and including, these two numbers. RANDOM delivers cryptographically secure numbers.

#### Example

## RERANDOM

Seed the random number generator.

#### Syntax

RERANDOM number (RERANDOM)

#### Description

RERANDOM seeds the random number generator with its input. If RERANDOM is used
without inputs, it uses a random number to seed the gemerator. See also `RANDOM`

.

## ROUND

Rounds a number.

#### Syntax

ROUND number

#### Description

ROUND reports the input number rounded to the nearest integer. See also `INT`

.

#### Example

## SEC

Reports the secant.

#### Syntax

SEC number

#### Description

SEC reports the secant of its input.

#### Example

## SIN

Reports the sine.

#### Syntax

SIN number

#### Description

SIN reports the sine of its input, which is the number of degrees in an angle.
Remember that SIN x = opposite/hypotenuse. See also `ARCTAN`

and `COS`

.

#### Example

## SQRT

Reports the square root.

#### Syntax

SQRT number

#### Description

SQRT reports the square root of its input. The input number must be a positive number or 0.

#### Example

## TAN

Reports the tangent.

#### Syntax

TAN number

#### Description

TAN reports the tangent of its input, specified in degrees.

#### Example

TAN 45Result: 1