BBC floating point formats
Posted: Tue Sep 24, 2024 4:30 pm
So I'm aware of this page, previously pointed out by Ed: https://beebwiki.mdfs.net/Floating_Point_number_format
But it's not completely clear to me. This portion:
It also appears to say that some versions have representations that allow the same integer to be represented in floating point in two different ways (which if true must lead to some interesting implementation details in the manipulation routines).
But it also says this:
Also that the 6502 BASICs represent zero not with an exponent of zero (again what Microsoft BASICs do) but with an exponent of $80 (which I suppose can work if zero is always checked for before doing any work on a floating point number - it's rather difficult to normalize a number which has no one bits, so that would have to come first).
My questions basically come down to, what is the real memory layout of floating point numbers in BBC BASICs, and second, are there any particular names for these layouts?
But it's not completely clear to me. This portion:
- So, for example on Acorn BASICs:
4 is exponent &83, sign 0, mantissa &80000000, stored as &83,&00000000
-8 is exponent &84, sign 1, mantissa &80000000, stored as &84,&00000000
12 is exponent &84, sign 0, mantissa &C0000000, stored as &84,&40000000
-0.5 is exponent &80, sign 1, mantissa &80000000, stored as &80,&80000000
Zero is a special case and is stored as five zero bytes. Some versions of BBC BASIC extend this and use a zero exponent to indicate that the real actually holds an integer value. For example:
&00, &00000000 is 0
&00, &00000080 is 128 (where implemented)
&00, &FFFFFFFE is -2 (where implemented)
It also appears to say that some versions have representations that allow the same integer to be represented in floating point in two different ways (which if true must lead to some interesting implementation details in the manipulation routines).
But it also says this:
- 6502
6502 BASIC stores reals in memory high-to-low as:
address+0 address+4
mantissa.hi, mantissa.middle, mantissa.middle, mantissa.lo, exponent
The only 32-bit integer that 6502 BASIC allows to be stored in a real is zero. 6502 BASIC uses excess-&80 for the exponent, so &80 represents an exponent of zero.
Non-6502 BASICs
All other versions of BBC BASIC store reals in memory low-to-high as:
address+0 address+4
mantissa.lo, mantissa.middle, mantissa.middle, mantissa.hi, exponent
Also that the 6502 BASICs represent zero not with an exponent of zero (again what Microsoft BASICs do) but with an exponent of $80 (which I suppose can work if zero is always checked for before doing any work on a floating point number - it's rather difficult to normalize a number which has no one bits, so that would have to come first).
My questions basically come down to, what is the real memory layout of floating point numbers in BBC BASICs, and second, are there any particular names for these layouts?