|
Mathematics
LibreLogo has some inbuilt mathematical functions. Some of them are
explained other places in this document, but here are an overview.
Mathematical operators
Here is a list over the mathematical operators I have found in LibreLogo:
Operator |
Use |
Explanation |
+ |
:a + :b |
Addition |
- |
:a - :b |
Subtraction |
* |
:a * :b |
Multiplication |
/ |
:a / :b |
Division |
= |
:x = :a |
Equal |
% |
:a % :b |
Remainder in division |
< |
:a < :b |
Less than |
> |
:a > :b |
More than |
<= |
:a <= :b |
Less than or equal |
>= |
:a >= :b |
Greater than or equal |
!= |
:a != :b |
Not equal |
& |
:a & :b |
Bit AND. (Binary AND) |
| |
:a | :b |
Bit OR. (Binary OR) |
^ |
:a ^ :b |
Bit NOT AND. (Binary NAND) |
Matematical functions
Name |
Use |
Explanation |
RANDOM |
RANDOM 100 |
Random number (16 digits) from 0 to a given number. |
INT |
INT 5,123 |
Return the integer part of a decimal number (here 5). |
SQRT |
SQRT 100 |
Return the square root of a number (here 10) |
SIN |
SIN 60 |
Sine of an angel. SIN 60 = -0.3048106211022167 |
COS |
COS 60 |
Cosine of an angle. COS 60 = -0.9524129804151563 |
ROUND |
ROUND 16,45 |
Rounds to the nearest integer. |
ABS |
ABS -30 |
The absolute valui, i.e. positive value (here: 30). |
MIN |
MIN 23, 2, 45 |
The smallest value in a list (here: 2). |
MAXS |
MAXS 23, 2, 45 |
The greatest value in a list (here: 45). |
RANGE |
RANGE 10 100 5 |
Range for a list. 1st num. is from, 2nd num. is to and 3rd num is step. |
PI |
:area = PI * :radius * :radius |
Number Pi as 3.14159265359 |
The functions are explained in the chapter “Functions”.
If your keyboard has both minus and dash keys you must use the minus key.
You can handle number values direct or from a variable or both.
PRINT 2 * 6 ; returns 12.
:a = 2 PRINT :a * 6 ; returns 12.
:a = 2 :b = 6 PRINT :a * :b ; returns 12.
LibreLogo use the common rules for mathematical notation and the use of parentheses.
PRINT 2 + 5 * 4 -8 returns 14 because it first calculate
5 * 4 (=20) and then 2 + 20 - 8. PRINT (2 + 5) * 4 - 8
returns 20.
|