Math additions #1 - eekee/pygmy64 GitHub Wiki

I suggest adding the following two sectons at the ends of the Numbers and Strings sections, respectively.

I've intentionally omitted describing how the integer division words behave with floating-point inputs because it seems complex and outside my field of experience.

Numbers

The four basic arithmetic operations have the usual names, + - * / . These work on integer and floating point numbers, automatically typecasting as needed. / always produces a floating-point result. Other words do integer division:

17 3 I/ .       --> 5
17 3 MOD .      --> 2
17 3 /MOD . .   --> 5 2

PI is a constant, pushing the value of π in floating-point format. Power and square root words are POW and SQRT respectively.

PI .        --> 3.141592653589793
2 8 POW .   --> 256
2 SQRT .    --> 1.4142135623730951

INT FLOOR and CEIL convert float to int. INT rounds toward zero, FLOOR rounds down, and CEIL rounds up. FLOAT converts int to float.

 4.5 INT .     -->  4
-4.5 INT .     --> -4
 4.5 FLOOR .   -->  4
-4.5 FLOOR .   --> -5
 4.5 CEIL .    -->  5
-4.5 CEIL .    --> -4
19 FLOAT .     --> 19.0

Pygmy Forth will operate on integers of any length, so there is no need for double-precision integer words.

2 90 POW .  --> 1237940039285380274899124224

Strings

INT and FLOAT will also convert strings to numbers. Note: INT will not convert a string and round at the same time, it will raise an error if the string looks like a float.

" 42" FLOAT .   --> 42.0
" 17" INT .     --> 17