BBC floating point formats

Programming the 6502 microprocessor and its relatives in assembly and other languages.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: BBC floating point formats

Post by BigEd »

Ah, thanks for those. So it seems RTR decided to support this idea of four-byte integers with an exponent of zero, in his Z80 BBC Basics.

From the first link:
Quote:
An exponent of zero is taken to mean that the mantissa is an integer - this allows integers which will fit in four bytes to be manipulated differently, avoiding irritating features such as 10 becoming 9.999998, whilst retaining the ability to cope with the large ranges which come with the floating point representation.
From the second link:
Quote:
;BINARY INTEGER REPRESENTATION:
; 32 BIT 2'S-COMPLEMENT SIGNED INTEGER
; "EXPONENT" BYTE = 0 (WHEN PRESENT)
So we see, I think, RTR supporting integer values, and integer-valued floats, and general floats.
teamtempest
Posts: 443
Joined: 08 Nov 2009
Location: Minnesota
Contact:

Re: BBC floating point formats

Post by teamtempest »

It nagged me that I thought of verifying right away that the z80 was an LSB-first machine, which makes the LSB-first nature of that z80 floating point format pretty much a natural fit if you want to put a four-byte integer in the mantissa portion. Probably makes it easier to write math routines which can handle both integer and floating point formats. The mantissa is always an integer value whatever it's representing, after all.

But I didn't do that until now. The advantages seem pretty apparent at first glance, though offhand I imagine the placement of the exponent byte at the high or low end doesn't matter much. Except that on a 6502 machine, putting it at the lowest address would be easiest to check. And putting it at the highest address would make it easiest to handle the actual value. I'd have to study them more to see how they work, but it's pretty clever either way.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: BBC floating point formats

Post by BigEd »

I've got my Agon running so in principle I could explore the Z80 BBC Basic on that (heavily derived from RTR's)

I think the business of storing integer values in floats in a special way has two aspects
- it might sometimes allow for quicker calculations
- it might allow for the ! operator to access such values in a convenient way
Oh, and the third aspect
- very slightly more expensive to check for a zero value
And of course a fourth
- the code must be a little bit more complicated to handle two cases, especially as values might be promoted or demoted to or from integers

As you say though, it's an interesting idea.
rudla.kudla
Posts: 41
Joined: 20 Apr 2010

Re: BBC floating point formats

Post by rudla.kudla »

Loops will probably benefit the most from this feature.
Post Reply