diff README.txt @ 85:663d8e77b579

Implmement BCD floating point and update number parsing and printing Implements a BCD floating point system with 10 decimal digits of precistion and an exponent range of -63 to +63. Also include parsing integer and floating point values and printing them out.
author William Astle <lost@l-w.ca>
date Sun, 15 Oct 2023 22:15:36 -0600
parents fbb8f369ce76
children 1c1a0150fdda
line wrap: on
line diff
--- a/README.txt	Sun Oct 08 00:17:20 2023 -0600
+++ b/README.txt	Sun Oct 15 22:15:36 2023 -0600
@@ -43,3 +43,49 @@
 and, thus, will not autostart whatever Disk Basic you happen to have
 installed. This is most relevant on a Coco 3 where the upper 16K of the
 LWBasic ROM is internal instead of in a cartrige.
+
+
+Numbers
+=======
+
+LWBasic has three numeric types: a 32 bit signed integer, stored as two's
+complement, a decimal floating point type stored in packed BCD with
+10 digits of precision and a base 10 exponent range of -63 to +63, and a
+double precision decimal floating point type with 20 decimal digits of
+precision and a base 10 exponent range from -2047 to +2047.
+
+The BCD format using 48 bits is stored as follows:
+
+Offset	Size	Content
+0	1	Sign bit - 1 for negative
+1	7	Decimal exponent with a bias of 64; 0 indicates a value of 0
+8	40	10 BCD digits of the significand
+
+*** Planned but not implememted
+The BCD double format using 96 bits is stored as follows:
+
+Offset	Size	Content
+0	1	sign bit - 1 for negative
+1	3	<reserved>
+4	12	Decimal exponent with a bias of 2048; 0 indicates value of 0
+16	80	20 BCD digits of the significand
+
+It is worth noting the reason for using the BCD format instead of binary
+floating point. Because interactions with the computer are typically in base
+10, it makes sense to avoid the horrendous complications of attempting to
+maximize the accuracy of converting binary floating point to decimal and
+back again. While this is trivial for integers, it is non-trivial for
+floating point where the variations in accuracy and the need for rounding is
+unavoidable.
+
+At the expense of some extra CPU cycles for doing the calculations, base 10
+accuracy is preserved, at least to the precision limit of the data type.
+This also allows pre-parsing numbers and being able to display them again
+accurately when generating a program listing, even if extra nonsignificant
+digits like trailing decimal zeroes are not reproduced.
+
+It is, however, critical to note that despite the BCD representation, these
+values are still floating point and have the inherent inaccuracies of all
+limited precision data types. The simple difference is that it makes the
+numbers in the computer behave exactly like scientific notiation with no
+unexpected surprises.