Hello again,
I'm keeping to use the PCBasic with my pupils at school. Now we have studied the Floating Point standard (single precision-4 bytes) on the book, and I would be interesting to verify it on PC basic. I managed to get the location where is stored a variable but I'm not sure to understand. For sure the 4 byte i'm reading are changing if I change the variable, but this internal representation seems not clear to me.
What standard it follows? Is the same of original GWbasic (emulated) ...or not?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The floating-point format in PC-BASIC is the same format (MBF) as in GW-BASIC, but this is not the modern standard (IEEE754).
MBF is documented here http://robhagemans.github.io/pcbasic/doc/1.2/#mbf; you can find a more extensive description, background and history in the Wikipedia page which Marc links to. Note that GW-BASIC and PC-BASIC only have single- and double-precision floats and not extended-precision floats also described there.
You can also use MKS$ and MKD$ to convert from floats to character strings in MBF format and CVS and CVD for the reverse - see documentation for details.
a$=mks$(1.5e4)
for i = 1 to len(a$):print hex$(asc(mid$(a$,i,1))),:next
0 60 6A 8E
If you're teaching floating-point, it seems to me that would make sense to focus on IEEE 754 instead - except if this is a computer history course :) PC-BASIC or GW-BASIC won't be able to help with that as they don't support IEEE 754, but every modern language does. For example, in Python 3:
If you don't need infinity and NaN as possible values, using MBF for assignments might have the advantage that the students have it much harder to find solutions on the internet and are forced to actually do the assignment themselves. ;-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Exact! Thank you to both!
Yes I'm teaching F.P. at school, this days. IEEE754 is on the book and that's what we are studing, but i dont see any problem in observing some practical (storical?) application. Used bits are exactly the same, just in different position. Both formats use 8 bit for exponent, 1 for sign and 23 for the mantissa. The IEEE754 uses a 127 bias for the exponent while "basic" uses 128 (if i'm not wrong) The "bill gates" solution seems more smart because it alligns the exponent to first byte while IEEE754 spread it on first and second byte. In my mind they also place the sign at the start of the mantissa just because, then, you just need to overwrite the implicit 1 and the register is ready to operate.
I see on wikipedia there not support for infinite (as you can see in my demo, the variable will be set all to "1"'s, with sign, automatically becoming the biggest -or lowest- number possible). Anyway we are inside a programmig language, so overflow is an error, not a simbolic "+infinite" to carry in the next calculation!
Last edit: Alberto Donda 2019-05-08
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I guess when using dedicated floating point hardware the byte boundaries don't matter that much and placing the sign bit as MSB allows for this design gloal of IEEE754: “The single and double precision formats were designed to be easy to sort without using floating-point hardware. Their bits as a two's-complement integer already sort the positives correctly, and the negatives reversed. If that integer is negative, xor with its maximum positive, and the floats are sorted as integers.”
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello again,
I'm keeping to use the PCBasic with my pupils at school. Now we have studied the Floating Point standard (single precision-4 bytes) on the book, and I would be interesting to verify it on PC basic. I managed to get the location where is stored a variable but I'm not sure to understand. For sure the 4 byte i'm reading are changing if I change the variable, but this internal representation seems not clear to me.
What standard it follows? Is the same of original GWbasic (emulated) ...or not?
Hello, I made a small demo capable to show a fp variable in binary...
Wikipedia has a page for the floating point format used by Microsoft's early BASICs: https://en.wikipedia.org/wiki/Microsoft_Binary_Format
Hi Alberto,
The floating-point format in PC-BASIC is the same format (MBF) as in GW-BASIC, but this is not the modern standard (IEEE754).
MBF is documented here http://robhagemans.github.io/pcbasic/doc/1.2/#mbf; you can find a more extensive description, background and history in the Wikipedia page which Marc links to. Note that GW-BASIC and PC-BASIC only have single- and double-precision floats and not extended-precision floats also described there.
You can also use
MKS$
andMKD$
to convert from floats to character strings in MBF format andCVS
andCVD
for the reverse - see documentation for details.If you're teaching floating-point, it seems to me that would make sense to focus on IEEE 754 instead - except if this is a computer history course :) PC-BASIC or GW-BASIC won't be able to help with that as they don't support IEEE 754, but every modern language does. For example, in Python 3:
Rob
If you don't need infinity and NaN as possible values, using MBF for assignments might have the advantage that the students have it much harder to find solutions on the internet and are forced to actually do the assignment themselves. ;-)
Exact! Thank you to both!
Yes I'm teaching F.P. at school, this days. IEEE754 is on the book and that's what we are studing, but i dont see any problem in observing some practical (storical?) application. Used bits are exactly the same, just in different position. Both formats use 8 bit for exponent, 1 for sign and 23 for the mantissa. The IEEE754 uses a 127 bias for the exponent while "basic" uses 128 (if i'm not wrong) The "bill gates" solution seems more smart because it alligns the exponent to first byte while IEEE754 spread it on first and second byte. In my mind they also place the sign at the start of the mantissa just because, then, you just need to overwrite the implicit 1 and the register is ready to operate.
I see on wikipedia there not support for infinite (as you can see in my demo, the variable will be set all to "1"'s, with sign, automatically becoming the biggest -or lowest- number possible). Anyway we are inside a programmig language, so overflow is an error, not a simbolic "+infinite" to carry in the next calculation!
Last edit: Alberto Donda 2019-05-08
I guess when using dedicated floating point hardware the byte boundaries don't matter that much and placing the sign bit as MSB allows for this design gloal of IEEE754: “The single and double precision formats were designed to be easy to sort without using floating-point hardware. Their bits as a two's-complement integer already sort the positives correctly, and the negatives reversed. If that integer is negative, xor with its maximum positive, and the floats are sorted as integers.”