[Coco] VARPTR and floating point representation

William Astle lost at l-w.ca
Sat Mar 24 15:50:32 EDT 2012


On 12-03-24 07:55 AM, Robert Gault wrote:
> The format depends on the type of variable.
> Numeric - points to 5 byte floating point
> byte1 exponent, byte2-5 mantissa
> byte2 bit7 (0-7) = 0 number negative, = 1 number positive

Actually, you have the sign bit reversed - it's 1 for negative and 0 for 
positive.

The exponent byte is a bit weird. It's an 8 bit signed number from -127 
to +127 stored with a bias of 128 (means you add 128 to the exponent and 
store that in the byte). That means a real exponent of 0 is stored as 
128. To further complicate matters, if the stored exponent value is 0, 
the number is 0.

The mantissa is stored with the binary point immediate to the right of 
the most significant bit of the number, which means that for any number 
other than zero, the most significant bit of the mantissa is going to be 
a 1. That is what allows storing the sign in the most significant bit of 
the mantissa (and is also why there is a special representation for zero).

> String - points to 5 byte descriptor
> byte1 - length
> bytes 2&5 - reserved
> bytes 3&4 - address if 1st character
>
> Array - description in "Going Ahead with ECB" short and not very clear.

Arrays are simpler than they look, actually. Each entry in an array has 
exactly the same format as a simple variable of the same type. VARPTR 
itself does not return the base address of an array but rather the 
address of an element in the array so the value can be treated 
identically to a simple variable.



More information about the Coco mailing list