Page 1 of 1

Floating point math on 6502, Commodore style

Posted: Tue Feb 06, 2007 11:03 am
by Mats
On

http://6502.org/source/

the Wozniak software for floating point computations in Apple format (?)can be found. I have coded alternative subroutines for the Commodore format. I think the Commodore version with 32 bits for the mantissa instead of the 23 bits used by Wozniak (24 bits including the "sign bit") is more praxis oriented. The same can be said by the FLOAT and the FIX subroutines that for the Wozniak software transform to/from 16 bits signed integer while I base this on 32 bit unsigned integers. An explication of the floating point concept and my code can be found on the "free-site"

http://www.geocities.com/matsr2007/

I hope Mike will include this later in http://6502.org/source/! When (if ever) he has done so I will close the "geocities" site as I do not normally maintain any "home page".

Does anybody have access to the original Commodore source code for corresponding tasks? It would be interesting to compare how this originally was coded by Microsoft (that provided the BASIC software for the PET).

Posted: Tue Feb 06, 2007 4:49 pm
by kc5tja
Somewhere on my box at home, I have the Commodore 64 version of BASIC 2.0 source listing, generated from a ROM dump and disassembler. But this can also be found online too (it's where I got it from). Try http://www.tkk.fi/Misc/cbm/docs/c64-diss.html

Posted: Thu Feb 08, 2007 12:18 pm
by Mats
Do get a ROM dump is the easy start, this one indeed finds in the Internet. The hard part is to extract some sensible portable code out of this dump!

I just udated

http://geocities.com/matsr2007/

to include a PET ROM dump in a format that is directly useable by an Assembler (".DB statements") + a desassembly of the part of the ROM where the code for these "Microsoft-computations" is positioned. I invite all "CBM hackers" to extract portable subroutines out of this!

Posted: Mon Feb 26, 2007 7:59 pm
by ptorric
6502 float commodore is the same also in amiga version? (but larger, of course) i mean same format and same algorithms?

Posted: Tue Feb 27, 2007 2:59 am
by kc5tja
No; the Amiga version conforms to IEEE 754 (mathieee.library and mathieeedoub.library) and is not related, as far as I know, to the format used by the PET kernels (of which the VIC-20/C64/C128 kernels belong).

Posted: Tue Feb 27, 2007 3:05 am
by faybs
ptorric wrote:
6502 float commodore is the same also in amiga version? (but larger, of course) i mean same format and same algorithms?
Nope, I'm afraid. The mathieee#?.library use the ieee single and double precision formats, which are not the same as Commodore's. The FFP versions of the math libraries use the following format, which is also different from the 6 byte CBM format (cut'n'paste from the RKM):

Code: Select all

FFP floating-point variables are defined within C by the float or FLOAT
directive. In assembly language they are simply defined by a DC.L/DS.L
statement. All FFP floating-point variables are defined as 32-bit entities
(longwords) with the following format:
 
         _____________________________________________
        |                                             |
        | MMMMMMMM    MMMMMMMM    MMMMMMMM    EEEEEEE |
        | 31          23          15          7       |
        |_____________________________________________|
 
 
The mantissa is considered to be a binary fixed-point fraction; except for
0, it is always normalized (the mantissa is shifted over and the exponent
adjusted, so that the mantissa has a 1 bit in its highest position).
Thus, it represents a value of less than 1 but greater than or equal to
1/2.
 
The sign bit is reset (0) for a positive value and set (1) for a negative
value.
 
The exponent is the power of two needed to correctly position the mantissa
to reflect the number's true arithmetic value.  It is held in excess-64
notation, which means that the two's-complement values are adjusted upward
by 64, thus changing $40 (-64) through $3F (+63) to $00 through $7F.  This
facilitates comparisons among floating-point values.

Posted: Mon Mar 19, 2007 7:23 pm
by Mats
Actually ,scrolling through "http://www.woz.org/" I saw a statement of Mr Wozniak himself saying that Apple decided to go for the Microsoft floating point BASIC instead of for the system Wozniak was working at. This then means that my heading should have been "Commodore and Apple style, in fact Microsoft style". And considering that Wozniak only was using 32 bits I am convinced Apple was right. There are a lot of applications that need higher accuracy. Then 40 bits are better!

Re:

Posted: Wed Dec 24, 2014 10:04 pm
by GARTHWILSON
Mats wrote:
Do get a ROM dump is the easy start, this one indeed finds in the Internet. The hard part is to extract some sensible portable code out of this dump!

I just udated

http://geocities.com/matsr2007/

to include a PET ROM dump in a format that is directly useable by an Assembler (".DB statements") + a desassembly of the part of the ROM where the code for these "Microsoft-computations" is positioned. I invite all "CBM hackers" to extract portable subroutines out of this!
Mats, when I click on the link now, I just get a message that Geocities closed in 2009. Have you moved your material to another site?

Re: Floating point math on 6502, Commodore style

Posted: Thu Dec 25, 2014 5:43 am
by BigEd

Re: Floating point math on 6502, Commodore style

Posted: Thu Dec 25, 2014 8:19 am
by GARTHWILSON
Thanks Ed. So the same thing is in several different places. We have not heard from Mats in six years.

Re: Floating point math on 6502, Commodore style

Posted: Fri Dec 26, 2014 11:24 pm
by BigDumbDinosaur
From his article:
  • The COMMODORE floating point format used for the PET computer deviates from the IEEE standard...
One could incorrectly deduce from this statement that the IEEE-754 standard predated Commodore's (actually, Microsoft's) excess-128 notation. Although seminal work on IEEE-754 began in 1977, the standard wasn't ratified until 1985, some seven years after excess-128 notation was introduced with PET BASIC 1.0.

Also:
  • Any application using at least a rudimentary amount of mathematics should use floating point.
I disagree. A surprisingly large amount of computation can be accomplished with integer arithmetic, especially at the operating system level. Even procedures such as converting between UNIX time_t format and Gregorian notation can be accomplished with integer arithmetic. In developing the software that models my 816NIX filesystem, I used 64 bit integer arithmetic, with final results rounded to 32 bits, since the filesystem architecture itself is 32 bit.

Otherwise, it's a good posting that tries to explain a complicated topic. Unfortunately, the embedded links are broken.

Re: Floating point math on 6502, Commodore style

Posted: Sat Dec 27, 2014 8:46 am
by BigEd
BigDumbDinosaur wrote:
Unfortunately, the embedded links are broken.
They all seem fine for me. If you find a broken link, try the usual tactics to resolve it to an archived or relocated copy. If it's still problematic, ask for help with the usual tactics: describe your problem and what you've tried to do.

Cheers
Ed