next up previous contents index
Next: Operations on lists Up: List of primitives Previous: Writing in the text   Contents   Index

Arithmetical and logical operations

Primitives Arguments Utilisation
Primitives Parameters Usage
sum a b: numbers to add Adds the two numbers a and b and returns the result
Eg: sum 40 60 returns 100
difference a b: numbers Returns a-b.
Eg: difference 100 20 returns 80
minus a : number Returns the negative of a.
Eg: minus 5 returns -5. See the note at the end of this table.
product a b : numbers Returns the result of multiplying a by b.
div, divise a b: numbers Returns the result of dividing a by b
div 3 6 returns 0.5
quotient a b: numbers Returns quotient a by b
quotient 15 6 returns 2
mod, modulo a b: whole numbers Returns the remainder after dividing a by b.
round, rnd a: number Returns the nearest whole number to the number a.
round 6.4 returns 6
integer a: number returns the integer part of the number. integer 8.9 returns 8
integer 6.8 returns 6
power a b: numbers Returns a raised to the power of b.
power 3 2 returns 9
sqrt , sqrt n : number returns the square root.
log n : number Returns the logarithm of n
exp n : number Returns the exponential of n
log10 n : number Returns the decimal logarithm of n
sin, sine a: number Returns the sine of a. (a is expressed in degrees)
cos, cosine a: number Returns the cosine of a. (a is expressed in degrees)
tan, tangent a: number Returns the tangent of a. (a is expressed in degrees)
acos, arccosine a: number Returns the angle in range [0-180] which cosine is a.
asin, arcsine a: number Returns the angle which sine is a.
atan, arctangent a: number Returns the angle which tangent is a.
pi aucun Returns the number $ \pi$ (3.141592653589793)
random, ran n: whole number Returns a random number between 0 and $ n-1$.
absolute, abs n: nombre Returns the absolute value (its numerical value without regard to its sign) of a number.


Important : Be careful with those primitives which require two parameters!

Eg:

setxy a b If b is negative
For example, setxy 200 -10

The logo interpreter will carry out the operation 200-10 (ie it will subtract 10 from 200). It will therefore conclude that there is only one parameter (190) when it requires two, and will generate an error message. To avoid this type of problem, use the primitive ``minus'' to specify the negative number - setxy 200 minus 10.
This is a list of logical operators:

Primitives Parameters Usage
or b: booleans Returns true if a or b is true, otherwise returns false
and b: booleans Returns true if a and b is true, otherwise returns false
not a :boolean Returns the negation of a. If a is true, returns false. If a is false, returns true.


next up previous contents index
Next: Operations on lists Up: List of primitives Previous: Writing in the text   Contents   Index
Loïc 2008-06-08