6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 6:47 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: error in wozfp1.txt
PostPosted: Tue Mar 08, 2016 1:19 am 
Offline

Joined: Tue Mar 08, 2016 12:54 am
Posts: 2
There is an error in the reprint of the floating point routines from Roy Rankin and Steve Wozniak:

1DD1 80 5A 02 7A R22 DCM 1.4142136 SQRT(2)

should read:

1DD1 80 5A 82 7A R22 DCM 1.4142136 SQRT(2)


Top
 Profile  
Reply with quote  
 Post subject: Re: error in wozfp1.txt
PostPosted: Tue Mar 08, 2016 2:24 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Interesting find, zottel! The list file is all over the internet, but it took me several tries to find a version that corroborates your claim. I was curious, so I converted both to decimal and confirmed it for myself. As posted, the data 80 5A 02 7A converts to 1.406401, which is quite different from the correct data, which is indeed as you posted.

Here's one that gets it right:

http://www.easy68k.com/paulrsm/6502/WOZFPIA.TXT

This version is subtly different in a few ways from the others, but I'm not sure why. Did you discover this during an attempt to implement these routines for yourself?

Mike B.

[Edit: here's another:

http://www.manualslib.com/manual/448600 ... l?page=101

]


Top
 Profile  
Reply with quote  
 Post subject: Re: error in wozfp1.txt
PostPosted: Tue Mar 08, 2016 8:40 am 
Offline

Joined: Sun Apr 10, 2011 8:29 am
Posts: 597
Location: Norway/Japan
The manualslib page is a copy from a disappeared web page (partly in archive.org now) which has been fully preserved on the easy68k.com site, so both links are to the same original source. Fortunately some people started earlier than e.g. myself to archive information before it disappeared forever..
Edit: Unfortunately the owner of the disappeared web page, which has been conserved on easy68k.com, passed in 2010, much too young. :(
(and he was a member on this forum, too)


Top
 Profile  
Reply with quote  
 Post subject: Re: error in wozfp1.txt
PostPosted: Tue Mar 08, 2016 12:03 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
I think, the assembler used at the time got the DCM directive wrong. There is two more DCM statements with an error.

According to wozfp1a.txt there is also a programming error in the original listing:
Quote:
Readers of Dr. Dobbs's journal should note that when
these routines were published in that journal the math
function LOG contained an error which prevented the
correct result from being given if the argument was less
than 1. This error has been correted in the present list-
ing and marked with "MOD 9/76."

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
 Post subject: Re: error in wozfp1.txt
PostPosted: Tue Mar 08, 2016 4:14 pm 
Offline

Joined: Tue Mar 08, 2016 12:54 am
Posts: 2
barrym95838 wrote:
... Did you discover this during an attempt to implement these routines for yourself?

I try to learn FPGAs and implemented part of a 6502 core/instruction set. Then I used these routines to test my implementation.
When I found the error, I first calculated what floating point number the sequence represented. Then I figured out what bytes would represent the correct value. I wondered how it could be that nobody had found the error in a piece of code that at the time of it's publication might have been of great interest. Then I downloaded Dr.Dobb's Journal vol 01 from this site. The original listing is on the page numbered 210 by Acrobat Reader and there is the correct value. I guess someone copied the text, either manually or by means of OCR, and mistook the 8 for a 0.


Top
 Profile  
Reply with quote  
 Post subject: Re: error in wozfp1.txt
PostPosted: Sat Oct 31, 2020 1:19 pm 
Offline

Joined: Sat Oct 31, 2020 1:07 pm
Posts: 3
I know this is reviving an ancient thread, I only created an account to search/mention the same mistake, but also the fact that A1 is wrong too:

A1: 80 52 80 40 = 1.289077759

it should be:

A1: 80 52 B0 40 = 1.2920074 as required.

Again, the version at http://www.easy68k.com/paulrsm/6502/WOZFPIA.TXT is correct.

I found this because I wanted to get my head around how to convert numbers to FP representation, and I'm a maths geek so always check other people's working :)

It looks like this is because the printed version was a bit difficult to read
(taken from https://archive.org/details/dr_dobbs_jo ... 9/mode/2up)

Image


Top
 Profile  
Reply with quote  
 Post subject: Re: error in wozfp1.txt
PostPosted: Sat Oct 31, 2020 1:51 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Thanks for the note! I've fixed both typos, and added a mention of the Errata document too.

http://www.6502.org/source/floats/wozfp1.txt now has:

Code:
1DCD  7E 6F     LN10   DCM 0.4342945
      2D ED
1DD1  80 5A     R22    DCM 1.4142136   SQRT(2)
      82 7A
1DD5  7F 58     LE2    DCM 0.69314718  LOG BASE E OF 2
      B9 0C
1DD9  80 52     A1     DCM 1.2920074
      B0 40
1DDD  81 AB     MB     DCM -2.6398577
      86 49
1DE1  80 6A     C      DCM 1.6567626
      08 66
1DE5  7F 40     MHLF   DCM 0.5
      00 00


Top
 Profile  
Reply with quote  
 Post subject: Re: error in wozfp1.txt
PostPosted: Sat Oct 31, 2020 3:12 pm 
Offline

Joined: Sat Oct 31, 2020 1:07 pm
Posts: 3
If you're fixing that file, you may want to apply the errata from Dr. Dobb's Journal, November/December 1976, page 57
http://www.classiccmp.org/cini/pdf/DrDo ... -v1n10.pdf

Quote:
ERRATA FOR RANKIN'S 6502
FLOATING POINT ROUTINES
Dear Jim, Sept. 22, 1976
Subsequent to the publication of "Floating Point Routines for the 6502" (Vol. 1, No. 7) an error which I made in the LOG routine came to light whicll causes improper results
if the argument is less than 1. The following changes will correct the error.

1. After: CONT JSR SWAP (1D07)
Add: A2 00 LDX #0 ; LOAD X FOR HIGH BYTE OF EXPONENT

2. After: STA M1+1 (1D12)
Delete: LDA #0
STA M1
Add: 10 01 BPL *+3 ; IS EXPONENT NEGATIVE
CA DEX ; YES, SET X TO $FF
86 09 STX M1 ; SET UPPER BYTE OF EXPONENT

3. Changes 1 and 2 shift the code by 3 bytes so add 3 to the addresses of the constants LN10 through MHLF wherever they are referenced. For example the address of LN1O changes from 1DCD to 1DD0. Note also that the entry point for LOG10 becomes 1DBF. The routine stays within the page and hence the following routines (EXP etc.) are not affected.


The changes are already in the alternate text at http://www.easy68k.com/paulrsm/6502/WOZFPIA.TXT


Top
 Profile  
Reply with quote  
 Post subject: Re: error in wozfp1.txt
PostPosted: Sat Oct 31, 2020 3:18 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Mike's already got the errata at
http://www.6502.org/source/floats/wozfp2.txt
and I've already added a note to the head of wozfp1.txt
so I think that's covered, although I do need to check with Mike.

But there's another one-byte discrepancy with the paulsrm version - any idea what's right?

Code:
1EE4  7B 46     C2     DCM .03465735903
      FA 70
vs
Code:
 283  1EE4  7B 46      C2     DCM  .03465735903
            4A 70


In this case paulsrm is at variance with the scan on the Internet Archive.


Top
 Profile  
Reply with quote  
 Post subject: Re: error in wozfp1.txt
PostPosted: Sat Oct 31, 2020 4:13 pm 
Offline

Joined: Sat Oct 31, 2020 1:07 pm
Posts: 3
I hadn't got that far translating the code yet, so missed those additional constant.

The value is calculated as 2^(x80 - high byte) * (3 lower bytes) / 2^22

Or reversed, take value .03465735903 * $400000 x 2^5
and you get: 46 FA 70

so correct version is 7B 46 FA 70


For negative values, the calculation is: 2^(x80 - high byte) * ($1000000 - 3 lower bytes) / 2^22
as it's 2s complement value.


Top
 Profile  
Reply with quote  
 Post subject: Re: error in wozfp1.txt
PostPosted: Sat Oct 31, 2020 6:36 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Great - so at least that's OK in the version on this site and the scanned Dr Dobbs.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron