Command List
Here are a list of commands that affect math. Note that all math commands can also be executed by patches.
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.
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
abs
number
Parameters:
number |
Number |
the number whose absolute value is to be determined |
Description:
Reports the absolute value of number.
acos
number
Parameters:
Description:
Trigonometric function. Returns the arccosine of number. All angles returned are in degrees.
Related Commands:
asin
atan
cos
sin
tan
condition1
and
condition2
Parameters:
condition1 |
Boolean |
|
condition2 |
Boolean |
|
Description:
Reports true if condition1 and condition2 report true.
Related Commands:
not
or
xor
asin
number
Parameters:
Description:
Trigonometric function. Returns the arcsine of number. All angles returned are in degrees.
Related Commands:
acos
sin
tan
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
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
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
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
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
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
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
e
Description:
Reports the value of e (approximately 2.718281828).
Related Commands:
exp
ln
pi
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
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
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
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
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
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
maxnum
Description:
Returns the largest number possible without going into positive infinity.
Related Commands:
maximum
minimum
minnum
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
minnum
Description:
Returns the lowest number possible without going into negative infinity.
Related Commands:
maximum
maxnum
minimum
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
not
condition1
Parameters:
Description:
Reports true if condition1 reports false.
Related Commands:
and
or
xor
number?
thing
Parameters:
Description:
Returns true
if thing is a number.
Examples:
number? 5.3
returns true
.
number?
[3] returns false
.
Related Commands:
list?
word?
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
pi
Description:
Returns the value of pi (approximately 3.14159).
Related Commands:
e
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
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
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
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
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
sin
number
Parameters:
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
sqrt
number
Parameters:
Description:
Finds the square root of number.
Examples:
sqrt 16
returns 4
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
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