A.3 Arithmetical and logical operations

This is a list of number-related commands:





sum x y



Adds the two numbers x and y, and returns the result

Eg: sum  40 60 returns 100



difference x y



Returns x − y.

Eg: difference  100 20 returns 80



minus x



Returns the negative of x.

Eg: minus  5 returns -5. See the note at the end of this table.



product x y



Returns the result of multiplying x by y.



div, divide x y



Returns the result of dividing x by y

div  3 6 returns 0.5



quotient x y



Returns quotient x by y

quotient  15 6 returns 2



rem, remainder x y



Returns the remainder after dividing x by y.



mod modulo x y



Returns x modulo y.
x
y
remainder x y
modulo x y
14
5
4
4
−14
5
−4
1
14
−5
4
−1
−14
−5
−4
−4

This table shows the différence between modulo x y and remainder x y.



round, rnd x



Returns the nearest whole number to the number x.

round  6.4 returns 6



integer, int x



Returns the integer part of the number x. integer 8.9 returns 8

integer 6.8 returns 6



power x n



Returns x raised to the power of n.

power  3 2 returns 9



squareroot, sqrt x



Returns the square root.



log x



Returns the logarithm of x.



exp x



Returns the exponential of x.



log10 x



Returns the decimal logarithm of x.



sine, sin x



Returns the sine of x. (x is expressed in degrees)



cosine, cos x



Returns the cosine of x. (x is expressed in degrees)



tangent, tan x



Returns the tangent of x. (x is expressed in degrees)



arccosine, acos x



Returns the angle in range [0-180] which cosine is x.



arcsine, asin x



Returns the angle which sine is x.



arctangent, atan x



Returns the angle which tangent is x.



pi



Returns the number π (3.141592653589793)



random, ran n



Returns a random integer between 0 and n − 1.



alea



Returns a random number between 0 and 1.



absolute, abs x



Returns the absolute value (its numerical value without regard to its sign) of a number.



setdigits n



Sets the number of digits, it sets the precision while calculating. Some more informations:

This primitive is useful when you want to calculate with a high precision. Have a look at the example with number π p.85.



digits



Returns the number of digits allowed while calculating. By default, this value is -1.

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:





or b1 b2



Returns true if b1 or b2 is true, otherwise returns false



and b1 b2



Returns true if b1 and b2 is true, otherwise returns false



not b1



Returns the negation of b1.