notes on forth programming in collapse os

part 02: manipulating numbers

types of numbers

in collapse os, an integer can have any value between -32768 and 32767 signed, or 0 and 65535 unsigned. if you want to work with larger numbers, there are probably ways to get around it, but the os doesn't seem to have much built-in support for things like double-length integers.

collapse os has several words that treat numbers as unsigned, where most other forths would treat them as signed. from a practical standpoint, this means that / [slash, for division] and many of the comparison operators may not work as you expect when handling negative numbers. in the arithmetic and comparison sections below, we'll show you our attempts at making words that work around this.

the aforementioned maximum integer, 65535, is equivalent to FFFF in hexadecimal. collapse os doesn't have a distinct "hex mode" like many forths do, but you can work with hex numbers fairly easily. when typing a hex number, precede it with a dollar sign so it won't be confused for either a decimal number or a word, like so: $FFFF. if you want to print a number off the stack, use . [dot] to print it in decimal, or .X [dot x] to print it in hexadecimal.

arithmetic operators

in addition to the usual plus, minus, slash, and star operators, here are some other ones collapse os has: