Philip
So, REDDING does DOUBLE PRECISION, how? Probably by doing it the "hard way" -- implement using 9511
primitive operations. I will get to it, but kind of got into the TJ Dekker 71 paper. So, started fooling around.
Here is MBASIC code - it makes a double precision number 1/3, .3333333333333333 as printed by MBASIC.
We then break it into mh, mm and ml (mantissa high, medium, low) of 23 bits, 23 bits and 10 bits.
Notice the loss of dynamic range... if we ignore the last 10 bits, we still loose 2^23 -- very sucky.
But.. notice that we can put the number back together -- and it is still .3333333333333333 .
If we ignore the last 10 bits (531 GOTO 550)... .we get 3333333333333286 -- which is just fine.
So, converting to 8080 (Z80) assembler and testing... this is fun! Note that the x * 2^B stuff
is just a bit of bit-banging in assembler... MBASIC doesn't have a good way to do that..
And now off to implement a set of routines for add, subtract, multiply, divide using this RRD
(real-real-double) technique. Per Dekker! After this, will try coding up "proper" double
precision. But this shows that it is actually easy to make the RRD from a double (and back again).
I think that I will call this module RRD.REL The linkage will be L80 prog,AM9511,RRD,APU,prog/N/E
and then RRD is optional -- it can (almost) be a user library, except for the special names needed
to override FORLIB.REL.
This should be the fastest (almost) DOUBLE PRECISION possible with a 9511. And, I finally published
dekker1971.pdf to my apu github.
Anyway... I think that this is what Dekker was after...
Enjoy!
Fred
240 ' DOUBLE PRECISION (RRD)
250 ' GENERATE A DOUBLE PRECISION NUMBER, AND BREAK IT INTO SINGLE
260 ' PRECISION PARTS: 23 23 10
270 ' THE SUM OF THE NUMBERS IS THE DOUBLE PRECISION NUMBER. BUT...
280 ' MS REAL IS 24 BITS, AND DOUBLE PRECISION IS 56 BITS - SO WE
290 ' HAVE TO SPLIT INTO THREE PARTS. THE SUM OF THE FIRST TWO
300 ' PARTS WILL BE 46 BIT, AND WE WILL WORK WITH THAT. THIS WILL
310 ' IGNORE THE LOW 10 BITS. WE ALSO LOOSE DYNAMIC RANGE: INSTEAD
320 ' OF 2^-64..2^63, WE MUST LOP OFF 23 BITS FOR 2^41..2^40
330 A# = 1
340 B# = 3
350 X# = A# / B#
360 PRINT X#
370 ' B = BITS PER MANTISSA, BL = REMAINING
380 B = 23 : BL = 56 - B - B
390 ' E IS EXPONENT OF RRD NUMBER
400 E = INT(LOG(X#) / LOG(2#)) + 1
410 M# = X# * 2^(-E)
420 MH = INT(M# * 2^B)
430 M# = (M# * 2^B) - MH
440 MM = INT(M# * 2^B)
450 M# = (M# * 2^B) - MM
460 ML = INT(M# * 2^BL)
470 M# = (M# * 2^BL) - ML
480 ' M# SHOULD BE 0... WE HAVE 3 MANTISSA PARTS MH, MM, ML
490 EH = E - B
500 EM = EH - B
510 EL = EM - BL
520 P# = MH : F# = P# * 2#^EH
530 P# = MM : P# = P# * 2#^EM : F# = F# + P#
540 P# = ML : P# = P# * 2#^EL : F# = F# + P#
550 PRINT F#