In developing the demonstration program, an important part of handling collisions among objects is determining the relative position and velocity. This is an easy enough calculation to put in the show system function, for now. The next step will be to examine the move object functions to handle collisions better. I want to divide up the “Mechanics” section into areas; some of these will become more important as I increase the size of systems. I am also adding the possibility of using multiple commands for the thermodynamics, electromagnetism, and structure of matter functions. I am also starting to use multiple commands for chemical substances and introducing sub-areas for personal studies.
I have also included a “Graphics Object” class which lends itself to some fairly complicated operations and manipulations. So far, it consists of one pixel, set on or off. As with physical systems, I will be expanding this one element at a time, but it should be simpler than the physical system and go faster.
One of my mathematical idiosyncrasies is the handling of errors in arithmetic. Since computers typically represent numbers with finite and fixed combination of digits, which are not easily expandable, and have a hard time reporting both results and errors, I have decided to represent numbers as classes including a set of error flags and a value, and have the relations and operations on the numbers both return the error flags and set the values. I am working on the TinyWholeNumbers class as an exercise in how this is to be done. This class includes three flags: Undefined, which is used in the case for things such as division by zero, and results of illegitimate or doubtful comparisons and operations; underflow, for numbers less than zero, and overflow, for numbers greater than zero. Values are in the range 0-255.
I have experimented with two different ways of reading and setting the flags: one won’t compile, and the other works but is wasteful of space. I am going to try a third way, typically used in Windows programming, (using an unsigned character to represent a bit and using masks and logical operations to clear and set bits). It’s easy enough to create a TinyWholeNumber constructor to clear all the flags and set the value to zero. An integer data type as used in C and C++ typically uses 4 bytes: which is much too large for the tiny version, and includes negative values. To do the conversion, I need to throw away all negative values and set the underflow flag; or throw away all values larger than 255 and set the overflow flag.
Writing the assignment operator is also tricky. I regard trying to set a number to an illegitimate value (one that has an underflow, or overflow flag set) as a questionable operation, and so it sets the “undefined” flag.
When I output a number, I append a character corresponding to one of these flags so that I can tell whether it came from a good calculation or a questionable one. This will be important in higher orders of mathematics, when errors can propagate, proliferate, and corrupt a calculation. I need to let most calculations proceed, since the results will be good in most cases, but I also need to be able to trace errors to their source.