Comparison of the different floating point formats.
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Comparison of the different floating point formats.
Hi all. qus brought up the question here, and it occurred to me that I haven't seen a comprehensive comparison of the different single-precision floating point formats which have been coded and used for the 65xx family over the last 40+ years. Off the top of my head, there's Woz 32-bit, Microsoft 32-bit, Microsoft 40-bit and Acorn 40-bit. I'm certain that there are more. I even have my own unique 32-bit (and related 36-bit) formats that are stalled on the back-burner with my many other unfinished projects, but that's another story ...
There are forum members here with experience using more than one of these formats, and it would interest me to know what they feel about the detailed pros and cons of each. I'm talking about the storage format and the (code) size and speed of the elementary functions + - * / ... the implementations of the more advanced functions are interesting as well, but of secondary importance for this particular discussion.
Would anyone like to share?
There are forum members here with experience using more than one of these formats, and it would interest me to know what they feel about the detailed pros and cons of each. I'm talking about the storage format and the (code) size and speed of the elementary functions + - * / ... the implementations of the more advanced functions are interesting as well, but of secondary importance for this particular discussion.
Would anyone like to share?
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!
Mike B. (about me) (learning how to github)
Mike B. (about me) (learning how to github)
Re: Comparison of the different floating point formats.
Good idea! There are also Atari's 6 byte BCD floats. (Edit: try also here)
Michael's universal build of MS Basic describes the 4 byte floats as 6 digit and the 5 byte floats as 9 digit. That's an approximation, of course, but a user-friendly indication of the difference. Matching an 8-digit calculator would have become a good thing to do.
This post and thread might be a useful reference too.
Michael's universal build of MS Basic describes the 4 byte floats as 6 digit and the 5 byte floats as 9 digit. That's an approximation, of course, but a user-friendly indication of the difference. Matching an 8-digit calculator would have become a good thing to do.
This post and thread might be a useful reference too.
Last edited by BigEd on Sat May 15, 2021 4:23 pm, edited 1 time in total.
Re: Comparison of the different floating point formats.
Notably, although Acorn's 6502 Basics all use the same floating point format, they have varying performance, either due to algorithmic improvements or due to having a 'C02 with a bigger instruction set. See
There were minor advances in accuracy too, and one bug in the final fastest version, subsequently found and fixed.
- A disassembly of BBC Basic 4r32 (github, by hoglet)
BBC Micro Compendium by Jeremy Ruston (stardot thread)
Last edited by BigEd on Sat May 25, 2019 12:08 pm, edited 1 time in total.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Comparison of the different floating point formats.
BigEd wrote:
There were minor advances in accuracy too
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Comparison of the different floating point formats.
Quite so! You can find some interesting reading by searching for 6502 "guard byte".
(Edit: in the BBC Micro Compendium's disassembly of an early Acorn Basic, "rounding byte" is used. The two floating point accumulators have an extra byte of mantissa. See for example the multiplication routine here starting at $A613.)
(Edit: in the BBC Micro Compendium's disassembly of an early Acorn Basic, "rounding byte" is used. The two floating point accumulators have an extra byte of mantissa. See for example the multiplication routine here starting at $A613.)
Re: Comparison of the different floating point formats.
Oh, and this previous thread has some relevant commentary:
Re: Comparison of the different floating point formats.
There's a hybrid format called Dec64 that uses a signed binary mantissa along with a base10 exponent. There are some disadvantages to this (e.g, you cannot compare values as integers, as you can for the IEEE-754 formats), but there are some interesting advantages, too. It might be possible to adapt this to 32 bits?
Re: Comparison of the different floating point formats.
Funnily enough I've had a tab open on that page for ages, but I'm not sure what led me to it. The commentary on HN is generally negative about the proposal: it's not a proposal from an expert, and it's probably not as good as it would need to be to become a standard.
https://news.ycombinator.com/item?id=16513717
Edit: from within that commentary, a page all about decimal arithmetic:
http://speleotrove.com/decimal/
https://news.ycombinator.com/item?id=16513717
Edit: from within that commentary, a page all about decimal arithmetic:
http://speleotrove.com/decimal/
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: Comparison of the different floating point formats.
Yeah, a wide divten on a 65xx can be somewhat "expensive", relatively speaking. Of the four implementations I mentioned in my original post, there seems to be little doubt that the Acorn floats have received the most care and attention to performance, but I'm the most intrigued by the Woz floats. Studying his code is a bit entertaining ... he worked some Woz magic to make it as compact as possible, and the result is wound up tighter than an eight-day clock. He is clearly burning a lot of cycles to reduce the code footprint ... nothing inherently wrong with that, but ... I am not sure if the performance hit from that strategy is significant or not, so I am unrolling his x-loops and combing out some of the spaghetti to attempt a timed comparison.
More to come, but in the meantime can any of you think up a good torture test that burns some measurable time and checks typical accuracy but uses only + - * / ? Something like pi/(1/(1/(1/(1/pi))))*pi-pi ?
More to come, but in the meantime can any of you think up a good torture test that burns some measurable time and checks typical accuracy but uses only + - * / ? Something like pi/(1/(1/(1/(1/pi))))*pi-pi ?
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!
Mike B. (about me) (learning how to github)
Mike B. (about me) (learning how to github)
Re: Comparison of the different floating point formats.
Maybe cook up a loop or a nested expression based on something like the following?
(Edit: P. is an abbreviation for PRINT)
Code: Select all
BBC Computer 32K
BASIC
>A=22/7:P.A*A/A-A
0
>A=355/113:P.A*A/A-A
9.31322575E-10
>A=1/81:P.A*A/A-A
0
>A=1/.81:P.A*A/A-A
0
>A=1/127:P.A*A/A-A
0
>A=1/129:P.A*A/A-A
-1.8189894E-12- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: Comparison of the different floating point formats.
While combing through Woz' brilliant little ball of twine, I was inspired to briefly revisit my own 32-bit format which uses $80000000 for its only NaN, $00000000 for its only 0.0, $40000000 for +1.0, $c0000000 for -1.0, etc. (1.0 is about halfway between zero and infinity, right?) The advantage of this format is that integer negation and signed-integer comparison (after special-casing NaN) work perfectly on the floats as well. Briefly, I was also excited that I could get reciprocals very quickly by subtracting from $80000000, but it turns out that it only seems to work for integer powers of two, which is of limited usefulness. Oh well, experimentation proceeds ...
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!
Mike B. (about me) (learning how to github)
Mike B. (about me) (learning how to github)
Re: Comparison of the different floating point formats.
> (1.0 is about halfway between zero and infinity, right?)
Sounds about right to me!
> combing through Woz' brilliant little ball of twine
It would be great to hear about what you've learned. It's very little code, but I don't doubt there's a lot to learn from it!
Sounds about right to me!
> combing through Woz' brilliant little ball of twine
It would be great to hear about what you've learned. It's very little code, but I don't doubt there's a lot to learn from it!
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: Comparison of the different floating point formats.
Oh, I'm still trying to steal a few moments here and there to study and fully dissect the Woz routines. As many of you may already know, his programs have an eccentric and intricate style (which some might frankly and explicitly call an unstructured mess) involving multiple subroutine entry- and exit-points, zp wraparound, subtle register and flag side-effects, extreme code re-use ... seemingly all in the interest of minimizing the code footprint, which was a legitimate incentive at that time. It's certainly an acquired taste, but one that I admire and attempt to understand, although I haven't the skilz to operate creatively at that high level. I definitely think it's a form of art, but I'm not yet prepared to share my critique.
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!
Mike B. (about me) (learning how to github)
Mike B. (about me) (learning how to github)
Re: Comparison of the different floating point formats.
Fair enough - hopefully one day!
Re: Comparison of the different floating point formats.
I got some slightly surprising results from this test program, which does some divisions and multiplications and sums up the absolute errors:
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: Select all
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 ECode: Select all
1982 version 2 8.14907253E-10
1988 version 4r32 1.26601662E-9