6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon May 20, 2024 11:53 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri Aug 31, 2018 6:52 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
I was pondering today if the HP implantation of forth for the HP-41 and HP-71 provided floating point support. From what I could locate it looks like the HP-41 did. I thought maybe some of our Forth and HP aficionados (GARTHWILSON) might know.


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 31, 2018 7:55 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
Yes; the 71 puts floating-point numbers on a separate HP-41-style floating-point stack.  The Forth word  ITOF  ( n -- )  (integer to floating-point) converts n into a floating-point number and puts it in the X register, lifting the floating-point stack.  FTOI  ( -- n )  (floating-point to integer) converts the contents of the X register to an integer and puts it on the regular Forth data stack.  If |x|>$FFFFF, an overflow error condition occurs.  FTOI takes the absolute value of X, rounds it to the nearest integer, and converts it to a five-nybble value.  If X was positive, FTOI returns this result.  If X was negative, FTOI returns the twos complement of this result.

The 71's Forth's floating-point included function set includes:  1/X  10^X  ACOS  ASIN  ATAN  CHS  COS  E^X  F*  F+  F-  F/  FABS  FP  (ie, fractional part)  IP  (ie, integer part)  ITOF  LGT  (log, base ten)  LN  (log, natural)  SIN  SQRT  TAN  X^2  and  Y^X.

In the input stream, FP numbers are identified by the presence of a decimal point.  If you want a double-precision integer instead, use , or : or / .  If  NUMBER  sees the decimal point, it passes the sequence to the routine used by BASIC's keyword  VAL  (value) for evaluation.  FP numbers are stored the same way the 71's BASIC does it, adhering to the IEEE floating-point standard, with a 12-digit mantissa and 3-digit exponent, also able to indicate "infinite" (which may be positive or negative) or NaN ("not a number").  Since the BASIC OS already has the routines to handle the floating-point operations, the Forth module uses those rather than repeating them.

I should mention that there were two different Forth modules I'm aware of.  I have not studied the differences.  I have the HP82441A Forth/Assembler module.

Since this is a 6502 forum and topics should have at least some application to the 65xx's, I'll comment that a separate floating-point stack can of course be implemented on these.  I think it makes more sense than trying to put FP numbers on the standard data stack.  Since the (ZP,X) addressing mode is not needed in a floating-point stack, this third stack could be in non-ZP memory.  There would only be a small penalty in efficiency, not function.  The 71 uses 16 nibbles (8 bytes) for each number.  Having X, Y, Z, T, and L then means 40 bytes.  If you don't need to stick to the IEEE floating-point standard, you could go with less.

The HP-41's Forth, although now rather well documented thanks to Ángel Martin's very clear MCode guide done in Apr 2014, is not something I have looked into much.  The 41's architecture, memory size (for holding source-code files), and the slowness and limitations of its text editor (which is only available on the 41cx which I have, and not on the 41c or 41cv), make it, IMO, not a serious platform for Forth.  I still use my 41cx nearly every day (and you can see the wide array of modules and accessories I have for it), but I'm not very interested in pursuing Forth on it.  Having a 65xx workbench computer in smallish, hand-held, portable package however is a different matter, and you can see how the 41 and 71 inspired my early efforts of such a workbench computer at http://wilsonminesco.com/BenchCPU/ .

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 01, 2018 2:11 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
Thanks Garth. I was thinking again about building a 6502 based pocket computer and wondering how floats were implemented on the HP's as a reference. I could not find a lot of information out there on the HP Forth implementation thanks for the link to the HP-41 Forth. I only found one video on YouTube for example which was a guy running HP-41 Forth on a 71 with the crossover cartridge.

A separate float stack, very interesting...


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 01, 2018 7:54 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10802
Location: England
Like almost all calculators, and unlike most computers, HP's use a BCD representation for floats. (Having a nibble-based CPU makes for some different costs and benefits: 6502's BCD format is byte-based and you'll find your code needing to do four-bit shifts.) According to this thread on the old hpmuseum forum, the earlier HP calculators used a 14 nibble format, whereas later ones used a 16 nibble format.

You might be interested in Charles Bond's floating point library for 6502, which also uses BCD, in this case an 8 byte format, supporting 12 mantissa and 3 exponent digits. We had a thread:


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 01, 2018 8:41 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
Jeff_Birt wrote:
Thanks Garth. I was thinking again about building a 6502 based pocket computer and wondering how floats were implemented on the HP's as a reference. I could not find a lot of information out there on the HP Forth implementation thanks for the link to the HP-41 Forth. I only found one video on YouTube for example which was a guy running HP-41 Forth on a 71 with the crossover cartridge.

A separate float stack, very interesting...

I think the separate stack solves a lot of stack-juggling problems, especially if the floating-point precision requires more than two cells.

The idea of the 65xx-based pocket computer always interests me.  I have come to prefer scaled-integer for most things, but of course floating-point is nearly imperative in a few things, especially for something like a calculator where the range and domain of inputs is cannot be known ahead of time like they can in embedded systems.  I was going to recommend Marco Granati's 128-bit 65816 floating-point routines, but the link has gone dead, so I have PM'ed him to ask for an updated link.  If he has no way to host them at the moment, I hope we can put them on this site, at http://6502.org/source/ .  (See the other resources there anyway.)

There is Valentín Albillo's book on floating-point, What Every Computer Scientist Should Know About Floating Point Arithmetic (.pdf)  Valentín is active on the MoHPC forum.

You might also be interested in this video:  Stanford Seminar: Beyond Floating Point: Next Generation Computer Arithmetic

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 01, 2018 8:58 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
GARTHWILSON wrote:
I was going to recommend Marco Granati's 128-bit 65816 floating-point routines, but the link has gone dead, so I have PM'ed him to ask for an updated link. If he has no way to host them at the moment, I hope we can put them on this site, at http://6502.org/source/ . (See the other resources there anyway.)

Thanks to Ed the document specialist, I can now post a link to the archived version:
https://web.archive.org/web/20170304155 ... bz/fpu.txt
See also my related links on my links page, at http://wilsonminesco.com/links.html#soft .  (I just now fixed my link there to Granati's work.)

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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: