Command List

Here are a list of commands that affect math. Note that all math commands can also be executed by patches.

Turtle, Observer, Patch

number1 +, -, *, /, ^ number2

Parameters:
number1 Number
number2 Number

Description:
Basic math functions. Be sure to put a space between the numbers and the symbol.

Examples:
5 + 3 returns 8

variable1 * variable2 returns the product of the numbers stored in variable1 and variable2

xcor ^ 2 returns the square of the turtle's x coordinate.


Turtle, Observer, Patch

number1 >, <, =, !=, <=, >=, not= number2

Parameters:
number1 Number
number2 Number

Description:
Equivalency operators. A space is needed between the numbers and the symbol.

Examples:
5 = 5 returns true

5 != 3 returns true

number1 <= number2 returns true if the number stored in number1 was less than or equal to the number stored in number2, otherwise it would return false

Notes:
!= and not= both return true if number1 and number2 are not equal to each other


Turtle, Observer, Patch

abs number

Parameters:
number Number the number whose absolute value is to be determined

Description:
Reports the absolute value of number.

Turtle, Observer, Patch

acos number

Parameters:
number Number

Description:
Trigonometric function. Returns the arccosine of number. All angles returned are in degrees.

Related Commands:
asin atan cos sin tan
Turtle, Observer, Patch

condition1 and condition2

Parameters:
condition1 Boolean
condition2 Boolean

Description:
Reports true if condition1 and condition2 report true.

Related Commands:
not or xor
Turtle, Observer, Patch

asin number

Parameters:
number Number

Description:
Trigonometric function. Returns the arcsine of number. All angles returned are in degrees.

Related Commands:
acos sin tan
Turtle, Observer, Patch

atan numerator denominator

Parameters:
numerator Number
denominator Number

Description:
Trigonometric function. Returns the arctangent of the specified number numerator/denominator. All angles returned are in degrees.

Related Commands:
acos sin tan
Turtle, Observer, Patch

integer1 bitand integer2

Parameters:
integer1 Integer First argument
integer2 Integer Second argument

Description:
Reports the value of bitwise-and on the inputs.

Examples:
2 bitand 3 returns 2. This statement is executed in binary form as 0010 and 0011, which returns 0010.

Related Commands:
bitnot bitor bitxor
Turtle, Observer, Patch

bitnot value

Parameters:
value Integer The argument to be negated

Description:
Reports the bitwise-negation of its input.

Examples:
bitnot 4 returns -5. The negation of 00000100 is 11111011.

Related Commands:
bitand
Turtle, Observer, Patch

integer1 bitor integer2

Parameters:
integer1 Integer First argument
integer2 Integer Second argument

Description:
Reports the bitwise-or of the inputs.

Examples:
1 bitor 2 returns 3. This statement is executed in binary form as 0001 or 0010 which returns 0011.

Related Commands:
bitand
Turtle, Observer, Patch

integer1 bitxor integer2

Parameters:
integer1 Integer First argument
integer2 Integer Second argument

Description:
Reports the value of the bitwise-exclusive-or of the inputs.

Examples:
2 bitxor 3 returns 1. This statement is executed in binary form as 0010 xor 0011 which returns 0001.

Related Commands:
bitand
Turtle, Observer, Patch

cos angle

Parameters:
angle Number angle in degrees

Description:
Trigonometry function. Returns the cosine of angle. All angles are in degrees.

Related Commands:
acos sin tan
Turtle, Observer, Patch

number1 div number2

Parameters:
number1 Number dividend
number2 Number divisor

Description:
Reports the integer part of the answer to number1 / number2.

Examples:
5 div 2 returns 2.

6 div 2 returns 3.

Related Commands:
mod
Turtle, Observer, Patch

e

Description:
Reports the value of e (approximately 2.718281828).

Related Commands:
exp ln pi
Turtle, Observer, Patch

exp number

Parameters:
number Number exponent to raise e

Description:
Reports e (approximately 2.71828) raised to the power of number.

Related Commands:
e ln
Observer

get-random-seed

Description:
Returns the current random seed.

Notes:
StarLogo uses the random generator provided by Java, which, as of now, is a linear congruential formula (Knuth Art of Computer Programming, Vol 2, Section 3.2.1.), which uses a 48-bit seed. StarLogo only allows you to set the lower 32 bits of this seed.

Related Commands:
set-random-seed setrandom-seed
Turtle, Observer, Patch

int number

Parameters:
number Number A real number to turn into an integer

Description:
Reports the largest integer less than or equal to number. For negative numbers, returns the smallest integer greater than or equal to number.

Examples:
int 5 returns 5.

int 5.9 returns 5

int -3 returns -3

Notes:
int -3.5 returns -3

Related Commands:
round
Turtle, Observer, Patch

ln number

Parameters:
number Number number of which you want the natural log

Description:
Returns the natural logarithm of number.

Examples:
ln 1 returns 0

ln e returns 1

ln -2 returns NaN (the error message Not a Number)

Related Commands:
e exp log
Turtle, Observer, Patch

log number base

Parameters:
number Number number of which you want the log
base Number base of the log

Description:
Math function. Returns the log of number according to specified base.

Examples:
log 100 10 returns 2

Related Commands:
ln
Turtle, Observer, Patch

maximum (max) number 1 number 2

Parameters:
number 1 Number first number that you are comparing
number 2 Number second number that you are comparing

Description:
Reports the larger value of the two numbers.

Examples:
max 4 6 returns 6

Related Commands:
maxnum minimum minnum
Turtle, Observer, Patch

maxnum

Description:
Returns the largest number possible without going into positive infinity.

Related Commands:
maximum minimum minnum
Turtle, Observer, Patch

minimum (min) number1 number2

Parameters:
number1 Number first number
number2 Number second number

Description:
Reports the smaller value of the two numbers

Examples:
min 3 5 returns 3

Related Commands:
maximum maxnum minnum
Turtle, Observer, Patch

minnum

Description:
Returns the lowest number possible without going into negative infinity.

Related Commands:
maximum maxnum minimum
Turtle, Observer, Patch

number1 mod number2

Parameters:
number1 Number
number2 Number

Description:
Modulo function. number1 mod number2 is equal to the remainder when number1 is divided by number2. The answer to mod is always positive.

Examples:
6 mod 2 returns 0.

10 mod 3 returns 1.

14 mod 5 returns 4.

Related Commands:
div
Turtle, Observer, Patch

not condition1

Parameters:
condition1 Boolean

Description:
Reports true if condition1 reports false.

Related Commands:
and or xor
Turtle, Observer, Patch

number? thing

Parameters:
thing Anything

Description:
Returns true if thing is a number.

Examples:
number? 5.3 returns true.

number? [3] returns false.

Related Commands:
list? word?
Turtle, Observer, Patch

condition1 or condition2

Parameters:
condition1 Boolean
condition2 Boolean

Description:
Reports true if either condition1 or condition2 reports true.

Examples:
if (color = black) or (color = red) [fd 2] makes all black or red turtles move forward 2 steps.

Related Commands:
and not xor
Turtle, Observer, Patch

pi

Description:
Returns the value of pi (approximately 3.14159).

Related Commands:
e
Turtle, Observer, Patch

random number

Parameters:
number Number upper-limit of range of random numbers to generate

Description:
Reports a random number between 0 and number, including 0 but not number, based on a uniform distribution.

Examples:
random 2 reports either 0 or 1, each with fifty percent probability.

Notes:
StarLogo uses the random generator provided by Java, which, as of now, is a linear congruential formula (Knuth Art of Computer Programming, Vol 2, Section 3.2.1.), which uses a 48-bit seed. StarLogo only allows you to set 32 bits of this seed.

Related Commands:
pick random-gaussian set-random-seed setrandom-seed
Turtle, Observer, Patch

random-gaussian number

Parameters:
number Number standard deviation of Gaussian distribution

Description:
Reports a random number with mean 0 and standard deviation number.

Examples:
random-gaussian 5 returns a random number with mean 0 and standard deviation 5.

Notes:
StarLogo uses the random generator provided by Java, which, as of now, is a linear congruential formula (Knuth Art of Computer Programming, Vol 2, Section 3.2.1.), which uses a 48-bit seed. StarLogo only allows you to set 32 bits of this seed.

Related Commands:
random set-random-seed setrandom-seed
Turtle, Observer, Patch

round number

Parameters:
number Number number to be rounded

Description:
Reports the integer closest to number.

Examples:
round 4.6 returns 5.

Related Commands:
int
Observer

set-scheduler-random-seed seed

Parameters:
seed Integer The seed for the random number generator

Description:
Sets the random seed of the thread scheduler to seed. Integers allowed are in the range -2^31 to 2^31-1.

This is not the same seed as used by the random command.

Notes:
Note: StarLogo uses the random generator provided by Java, which, as of now, is a linear congruential formula (Knuth Art of Computer Programming, Vol 2, Section 3.2.1.), which uses a 48-bit seed. StarLogo only allows you to set 32 bits of this seed.

Related Commands:
get-scheduler-random-seed scheduler switch-scheduler
Observer

setrandom-seed seed

Parameters:
seed Integer The new seed

Description:
Sets the random seed to seed. Integers allowed are in the range -(2^31) to (2^31 -1). Don't pick 0.

Examples:
set-random-seed 345612 sets the random-seed to 345612.

Notes:
StarLogo uses the random generator provided by Java, which, as of now, is a linear congruential formula (Knuth Art of Computer Programming, Vol 2, Section 3.2.1.), which uses a 48-bit seed. StarLogo only allows you to set the bottom 32 bits of this seed.

Related Commands:
get-random-seed random random-gaussian
Turtle, Observer, Patch

sin number

Parameters:
number Number angle

Description:
Trigonometry function. Returns the sine of the specified angle. All angles are in degrees.

Examples:
sin 30 returns .5.

Related Commands:
acos asin atan cos tan
Turtle, Observer, Patch

sqrt number

Parameters:
number Number

Description:
Finds the square root of number.

Examples:
sqrt 16 returns 4


Turtle, Observer, Patch

sum-of-list list

Parameters:
list List List of numbers

Description:
Returns the sum of the numbers in the list.

Examples:
sum-of-list [1 2 -3 4.5 5] returns 9.5.

Notes:
Note: If list contains no numbers, an error occurs. If some of the list, when evaluated, are not numbers, those values are ignored.

Related Commands:
average-of-list max-of-list median-of-list min-of-list mode-of-list sdev-of-list sort-num-list variance-of-list
Turtle, Observer, Patch

condition1 xor condition2

Parameters:
condition1 Number first condition
condition2 Number second condition

Description:
Reports the value of condition1 xor condition2

Examples:
(energy = 5) xor (size = 4) returns true if the turtle's energy is 5 or if the turtles size is 4, but not if both are true or neither are true.

Related Commands:
and not or