More Math Words
Here are some useful built-in words for common mathematical functions. You may skip this section, but use it as a reference later.
Word | Action |
---|---|
FLOOR |
Displays the floor of a number, which is the closest integer lower than the given number. |
CEIL |
Displays the ceiling of a number, which is the closest integer higher than the given number. |
ROUND |
Rounds off a real. |
MIN |
Minimum of a two numbers. |
MAX |
Maximum of a two numbers. |
^ |
Exponentiation 2 3 ^becomes 8 |
TAN |
Usual trigonometric functions. |
ATAN2 |
The special arctangent, very useful for computing directions from vectors. A definition may be found here: Wikipedia: Atan2 |
#e |
Constant values of e and π. |
EXP |
Natural exponentiation and natural logarithms. |
LOG10 |
Logarithms base 10. |
TO-DEG |
Converts angles to degrees or radians. |
MOD |
Integer modulus and real modulus. Use FMOD if either operand is a real number. |
ABS |
The absolute value. |
Logical Operators
Word | Action |
---|---|
TRUE |
Puts the logical value trueon the stack. |
FALSE |
Puts the logical value falseon the stack. |
OR |
Logical or. For example, true 1 2 = ORbecomes true. |
AND |
Logical and. For example, true 1 2 = ANDbecomes false. |
Quiz
Question 1
Use words you learnt to find the truncation part of a number. For example,5.25 your code here .should display
5.0.
Question 2
There is a built-in wordDUPthat duplicates the top of the stack. For example,
5.25 DUPends up with
5.25 5.25on the stack.
Use
DUPand words you learnt to find the fractional part of a number. For example,
5.25 your code here .should display
0.25.
Question 3
Do your solutions work for negative numbers?5.25 abs floor . 5.0 ok 5.25 abs dup floor -. . 0.25 ok -5.25 abs floor . 5.0 ok -5.25 abs dup floor -. . 0.25 ok