I've been looking at this thread with interest as I have a need for a single-precision FP format, preferably IEEE 754 to interface with a system where I have some libraries that use that format, but not any actual low-level code like add, multiply and so on ...
BigEd wrote:
I got some slightly surprising results from this test program, which does some divisions and multiplications and sums up the absolute errors:
Code:
10 E=0
20 FOR I = 15 TO 17 STEP 2
30 FOR J=1 TO I
40 A=J/I
50 F=A*A/A-A
60 E=E+ABS(F)
70 NEXT
80 NEXT
90 PRINT E
The oddity is that an older version of Acorn's BBC Basic gets a smaller result, and therefore seems to be more accurate than the newer:
Code:
1982 version 2 8.14907253E-10
1988 version 4r32 1.26601662E-9
I was curious about this as I want to use 32-bit IEEE 754 for a project (rather than Woz, etc. FP) so gave it a go on an ATmega which uses that format (or is supposed to) and it yielded
Code:
1.04308e-07
Just to compare, in double precision IEEE 754 using my desktop i3:
Code:
3.05311e-16
I can reproduce
Code:
1.26601662E-9
with BBC Basic 4, and
Code:
8.14907253E-10
using older BBC Basics.
Really no surprise that the 5-byte format that BBC Basic uses shows more precision than the 4-byre IEEE format I guess.
ehBasic (4-byte floats) yields:
Code:
1.04308E-07
and Applesoft (5-byte floats AIUI):
Code:
1.26601663E-09
Interesting observations here: ebHasic and IEEE 754 appear to be the same although I've just dome some superficial checks - and it appears that while Microsofts format (MBF) is similar in terms of bits used (1+8+23), the binary representation is different and IEEE 754 calls for more bits to be used when performing intermediate calculations. MBF preceded IEEE 754 and for 8-bit computers was probably good enough at the time. MSs 5-byte format wasn't generally used on the 6502 as they ran out of code space in typical 8K ROMs at the time - Applesoft having a 12K ROM being a notable exception. (What I've gained from wikipedia and a few other sites this afternoon)
However, Applesoft 5-byte format is virtually identical to BBC Basics 5-byte format in terms of precision with this trivial test (might actually be identical, masked by rounding in printing - I'd need to look at the actual binary values to check)
So - for me, I'm still after a native 6502 implementation of IEEE 754 for single precision numbers, but the above has been an interesting little investigation.
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/