Writing a BASIC interpreter, with floating point, is much harder. Gates, Allen and other collaborators BASIC was pretty damned good.
Writing a BASIC interpreter, with floating point, is much harder. Gates, Allen and other collaborators BASIC was pretty damned good.
[1] Bill & Steve (Jobs!) reminisce about floating point BASIC:
https://devblogs.microsoft.com/vbteam/bill-steve-jobs-remini...
What is hard is skipping the high level language step, and trying to do it in assembler in one step.
However, crafting an algorithm that uses IEEE arithmetic and avoids the limitations of IEEE is hard.
With fixed point numbers, you write the digits into the memory and have a convention that the decimal point is always after N-th digit. For example, if we agree that the point is always after 2-nd digit then a string 000123 is interpreted as 00.0123 and 123000 means 1230. Using this system with 6 digits we can represent numbers from 0 to 9999 to precision of 0.01.
With floating point, you write both decimal point position (which we call "exponent") and digits (called "mantissa"). Let's agree that the first two digits are the exponent (point position) and the rest four is mantissa. Then this number:
020123
means 01.23 or 1.23 (exponent is 2 meaning the decimal point is after 2nd digit in mantissa). Now using same 6 digits we can represent numbers from 0 to 9999·10⁹⁶ with relative precision of 1/10000.That's all you need to know, and the rest should be easy to figure out.
Looking backwards, writing an integer basic is a trivial exercise. But back in the 70s, I had no idea how to write such a thing.
Around 1978, Hal Finney (yes, that guy) wrote an integer basic for the Mattel Intellivision (with its wacky 10 bit microprocessor) that fit in a 2K EPROM. Of course, Hal was (a lot) smarter than the average bear.
1. the digits
2. the exponent
3. a sign bit
If you're familiar with scientific notation, yes, it's the same thing.
https://en.wikipedia.org/wiki/Scientific_notation
The rest is just the inevitable consequences of that.
Floating point at it's simplest just makes that a variable. So the (.) position is stored as a separate number. Now instead of being fixed - it floats around.
This way you can put more in the integer or more in the fraction.
The Microsoft Basic here used 23 bits for the number, 1 sign bit and 8 bits to say where the floating point should be placed.
Of course in practice you have to deal with a lot of details depending on how robust you want your system. This Basic was not as robost as modern IEEE754 but it did the job.
Reading more about IEE754 is a fascinating way to learn about modern floating point. I also recommend Bruce Dawson's observations on his Random ASCII blog.
And by the way engineering notation (where exponent must divide by 3) is so much better. I hate converting things like 2.234·10¹¹ into billions in my head.
And by the way (unrelated to floating point) mathematicians could make better names for things, for example instead of "numerator" and "denominator" they could use "upper" and "lower number". So much easier!
What I was trying to express—perhaps poorly—is that maybe floating-point support would have been more effort than the entire Integer BASIC. (Incidentally, as I understand it, nobody has found a bug in Apple Integer BASIC yet, which makes it a nontrivial achievement from my point of view.)
http://retro.hansotten.nl/uploads/mag6502/Apples%20Hidden%20...
Chapter 16, pages 8-10, gives a very concise description of the process.