Slevin wrote: ↑Mon Mar 25, 2024 2:11 pm
ahenry3068 wrote: ↑Mon Mar 25, 2024 2:00 pm
Floats take 5 bytes per element.
Is this a proprietary floating point representation, or is the 5th byte reserved for some kind of meta data? At least according to the birth date of the IEEE 754 standard I assume that it must be proprietary in some kind, but 5 byte must have a requirement. Can someone eplain?
The floating point numbers share the same basic concept as IEEE-754, but the layout is different.
CBM has the exponent first, followed by the sign and mantissa.
CBM Float
Exponent S Mantissa
0111 1111 0 0000 0000 0000 0000 0000 0000 0000 000
IEEE-754 Float
S Exponent Mantissa
1 0111 1111 0000 0000 0000 0000 0000 000
With 31 bits available for the Mantissa, a CBM float can encode a full 32-bit signed value (approx. +/-2.4 billion) with no loss of precision.
Aside from that, the two systems use mostly the same basic logic for encoding values: The value in the mantissa is actually 1.0 to 1.9999999995343387126922607421875, although the 1 bit is implied. To get value other than fractions of 1, the mantissa is multiplied by the exponent, which is a power of 2.
Some examples:
2.0 = 1.0 * 2
3.0 = 1.5 * 2
5.0 = 1.25 * 4
2024 = 1.9765625 * 1024
The special cases are also slightly different:
$00 in the exponent is interpreted as 0, and the mantissa is ignored. (IEEE requires all 32 bits to be 0 to encode a 0.)
IEEE interprets an exponent of $FF as Infinity, and $FF + any mantissa as NaN (Not a Number). CBM floats do not have either encoding.
So other than the special cases, it's fairly easy to convert CBM floats to IEEE floats:
Copy CBM bit 8 (sign) to IEEE bit 0.
Copy CBM bits 0-7 to IEEE bits 1-8
Copy CBM bits 9-31 to IEEE bits 9-31
To copy an IEEE float to a CBM float, just reverse the above process, then clear the rightmost 8 bits.