index

(Copied from old typewritten and handwritten notes, formatted to HTML, with minor editorial changes and typo fixing.)

Math for NCS

[note: this is from the early 1980s, before I ever heard of IEEE floating point.]

No standard size of numbers are to be assumed. When the user wants to do math beyond 16-bit integers, the user shall specify how many decimal digits are desired. The number of digits to the left and to the right of the decimal point specify the size of the number. For example, number format "3.6" would mean numbers ranging from 0.000001 to 999.999999.

The notation in the NCS language could be something like:

	⬗  7  5  FFA  .

This way, numbers only as accurate as needed are used, without time wasted in calculations workign on unwanted digits. Always fixed-point format is used. In most applications, floating point numbers with their wide range aren't needed. When floating point numbers are needed, they may be defined as a new data type in NCS, defined in terms of fixed-point numbers and integers exponents. One reason BASIC is such a slow language is that it has to normalize mantissas and compare exponents just to add 2+3. Not so in Project Galaxy.

The math modules fall into three categories:

It would be nice if commonly used transcendental functions such as logarithm of Gamma, or the Jacobian elliptic functions, could be included. At the very least, Galaxy should include everything that BASIC offers.

Multiple Number Formats

In a large sophisticated program, more than one format of fixed-point number may be necessary. The user may want some variables to be format "1.8" and other variables to be "4.1". Clearly, if some variables need to be precise while others need to handle large values but not with high precision, it would be a waste of time and memory to try to include both number ranges in one larger format, "4.8" in this example.

Therefore, we allow several fixed-point formats to be defined in one program. All MBC for the math modules are given second-hand, following a special escape code, similar to the way user Dictionaries are accessed. Four escape codes would correspond to four differently specified number formats.

The keyword "FFA" would be replaced by "FFA1", "FFA2", ...

Naming Number Operations

There is a problem in what to name these math modules. Addition could be called "+" but that will be confused with regular 16-bit integer addition on the Data Stack. One possibility is to prepend a distinct word or symbol to the + symbol, "math+", or have a separate keyword "math" as in "12.34 56.78 math +". Another possibility is to hold down Shift or Control while typing the "+" symbol, causing the "+" to appear highlighted on the screen, black on white instead of the normal white on black. This indicates that the mathematical module for "+" will be called instead of the usual core "+" integer addition. On the other hand, we have been planning on using highlighting for other purposes. For now we leave this matter open.

Number Implementation

Fixed-point numbers are not themselves placed on the Data Stack, but rather pointers to them. Integer "+" will add the top two values on the stack and leave the result, as a 16-bit value, there. "Math+" will take the top two items to be pointers, use them to look at the actual values, add them, then leave the result at the location pointed to by the second item. The top item is popped off.

Binary or BCD?

[handwritten notes are too sketchy to make out anything meaningful. Apparently I though BCD would be a fine choice for fixed point math.]