←back to thread

617 points EvgeniyZh | 4 comments | | HN request time: 0s | source
Show context
zabzonk ◴[] No.43576999[source]
I've written an Intel 8080 emulator that was portable between Dec10/VAX/IBM VM CMS. That was easy - the 8080 can be done quite simply with a 256 value switch - I did mine in FORTRAN77.

Writing a BASIC interpreter, with floating point, is much harder. Gates, Allen and other collaborators BASIC was pretty damned good.

replies(4): >>43577257 #>>43577890 #>>43579471 #>>43580146 #
teleforce ◴[] No.43580146[source]
Fun facts, according to Jobs for some unknown reasons Wozniak refused to add floating point support to Apple Basic thus they had to license BASIC with floating point numbers from Microsoft [1].

[1] Bill & Steve (Jobs!) reminisce about floating point BASIC:

https://devblogs.microsoft.com/vbteam/bill-steve-jobs-remini...

replies(2): >>43580215 #>>43585252 #
WalterBright ◴[] No.43585252[source]
Writing a floating point emulator (I've done it) is not too hard. First, write it in a high level language, and debug the algorithm. Then hand-assembling it is not hard.

What is hard is skipping the high level language step, and trying to do it in assembler in one step.

replies(3): >>43585361 #>>43586743 #>>43589235 #
zabzonk ◴[] No.43585361{3}[source]
I've never understood floating point :-)
replies(5): >>43585716 #>>43585892 #>>43587144 #>>43587391 #>>43590143 #
1. codedokode ◴[] No.43587144{4}[source]
Let's say we want to store numbers in computer memory but we are not allowed to use decimal point or any characters except for digits. We need to make some system to encode and decode real numbers as a sequence containing only digits.

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.

replies(1): >>43587196 #
2. WalterBright ◴[] No.43587196[source]
In other words, a floating point number consists of 2 numbers and a sign bit:

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.

replies(1): >>43587645 #
3. codedokode ◴[] No.43587645[source]
I like "decimal point position" more than "exponent". Also, if I remember correctly, "mantissa" is the significand (the digits of the number).

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!

replies(1): >>43588725 #
4. WalterBright ◴[] No.43588725{3}[source]
I do get significand and mantissa mixed up. I solved that by just removing them!