Converting IEEE-754 floating point to Color BASIC floating point

I'm still playing around with floating point on the 6809 [1]—specifically, support for floating point for the Color Computer. The format for floating point for Color BASIC (Beginners' All-purpose Symbolic Instruction Code) (written by Microsoft) predates the IEEE (Institute of Electrical and Electronics Engineers)-754 Floating Point Standard [2] by a few years and thus, isn't quite compatible. It's close, though. It's defined as an 8-bit exponent, biased by 129, a single sign bit (after the exponent) and 31 bits for the mantissa (the leading one assumed). It also does not support ±∞ nor NaN (Not a Number). This differs from the IEEE-754 single precision that uses a single sign bit, an 8-bit exponent biased by 127 and 23 bits for the mantissa (which also assumes a leafing one) and support for infinities and NaN. The IEEE-754 double precision uses a single sign bit, an 11-bit exponent biased by 1023 and 52 bit for the mantissa (leading one assumed) plus support for infinities and NaN.

So the Color BASIC is about halfway between single precision and double precision. This lead me to use IEEE-754 double precision for the Color Computer backend (generating an error for inifinities and NaN) then massaging the resulting double into the proper format [3]. I double checked this by finding some floating point constants in the Color BASIC ROM (Read Only Memory) as shown in the book Color BASIC Unravelled II, (available on the Computer Computer Archives [4]), like this table:

Then using the byte values to populate a variable and printing it inside BASIC (this is the expression -2π^3/3!):

Then using that to create a floating point value:

Checking the resulting bytes that were generated:

And adjusting the floating point constant until I got bytes that matched:

I figure it's “close enough.” The parsing code in the Color BASIC ROM is old and predates the IEEE-754 floating point standard, so a few different digits at the end I think is okay.

As a final check, I wrote the following bit of code to calculate and display -2π^3/3!, display the pre-calculated result, as well as display the pre-calculated value of 2π:

The results were:

The calculation results in -41.3417023 and the direct result stored in answer also prints out -41.3417023, so that matches and it reinforces my approach to this nominally right.

But I think Microsoft had issues with either generating some of the floating point constants for the larger terms, or transcribing the byte values of the larger terms. Take for instance -2π^11/11!. The correct answer is -15.0946426, but the bytes in the ROM define the constant -14.3813907, a difference of .7. And it's not like Color BASIC can't calculate that correctly—when I typed in the expression by hand, it was able to come up with -15.0946426.

Or it could be that [DELETED-Walter K. Zydhek,-DELETED] the author of Color BASIC Unravelled II, is wrong in his interpretation of the expressions used to generate the values, or his interpretation of what the values are used for. I'm not sure who is at fault here.

Update on Friday, March 1^st, 2024

I was wrong about the authorship of Color BASIC Unravelled II. It was not Walter K. Zydhek, but some unknown author of Spectral Associates, a company that is no longer in business. All Zydhek did was to transcribe a physical copy of the book (which is no longer available for purchase anywhere) into a PDF (Portable Document Format) and make it available.

[1] /boston/2024/02/07.1

[2] https://codedocs.org/what-is/ieee-754

[3] https://github.com/spc476/a09/blob/8682748ac0f98d7f83bbdb0b6e772270cf3fc89f/frsdos.c#L292

[4] https://colorcomputerarchive.com/repo/Documents/Books/Unravelled%20Series/

Discussions about this entry

Two Stop Bits | Converting IEEE-754 floating point to Color BASIC floating point

Gemini Mention this post

Contact the author

Proxied content from gemini://gemini.conman.org/boston/2024/02/28.1 (external content)

Gemini request details:

Original URL
gemini://gemini.conman.org/boston/2024/02/28.1
Status code
Success
Meta
text/gemini
Proxied by
kineto
Reisub Server

Be advised that no attempt was made to verify the remote SSL certificate.