🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by UMFORTH%WEIZMANN.BITNET Mon, 02 Sep 1985 14:30
FIGIL DIGEST
#233
Author: UMFORTH%WEIZMANN.BITNET
Date: Mon, 02 Sep 1985 14:30
77 lines
4623 bytes
Date: 15 Aug 85 08:23:00 EST
From: CPT.GREG.ELDER <elder@wpafb-info1>
Subject: Square Root Forth routine Wanted

I'm new to Forth and am writing a Forth program where I need to
calculate square root.  Does any one have a Forth routine which does
such a calculation, preferably written in fig-Forth but I'll take
any implmentation if one is available.  Please reply to me at
ELDER@WPAFB-INFO1 on ARPANET as I'm not on this mailing list.  Thanks.

Greg Elder
------------------------
To: ELDER@WPAFB-INFO1

Greg: regarding your inquiry on Forth solutions to square roots...

I checked out my rather limited material on FORTH to find a square
root routine.  As the saying goes, there's good news, and their's bad
news.  The good news is that I found one....  The bad news is that
1. It's copyrighted
2. It's machine dependent!

I have Micro-Motion's Forth-79 package which is fairly close to
Fig-Forth and can be used to write portable code which is Fig-Forth
compatible.  In addition to the straightforward standard Forth Word
set, their package includes extensions for Hi-resolution Graphics
and Floating Point Calculations.  These are implemented to remain
an option, separate from the Forth fixed point standard, and to be
as efficient as possible to fit in with the host machine, an Apple II.

What would interest you is the floating point package, since this is
where the Square Root routine resides.  Unfortunately, after reviewing
the source code, several things become apparent.  First of all, although
the actual definition of a square root is simple and short -- only 10
lines of code!!,  this code is actually based upon other definitions
in the floating point package.  The whole package is 37 blocks (1 K each)
which I couldn't send you even if I was willing to type in 37 screens
worth of code into my mainframe system.... these routines are copyrighted
and legally cannot be transferred (especially electronically).
I doubt that they'd do you much good, as much of it is coded into 6502
machine in order to maximize the use of the CPU of the Apple.  I figure
there are around 10-15 screens of prior definitions which are used in
the Square root routine.  Most is low level machine, rather than hi-level
Forth too!  (in the whole package around 2/3 of the code is low level for
the sake of speed).

Where does that leave you?  If you have floating point already
implemented in your installation, then developing a square root
definition shouldn't be all too crazy to attempt.  I suggest you check
out some standard algorithims for square roots, but you'll probably need
a good Comp. Science text for this, the algorithim I found for
square root is too intuitive to translate to a computer (unless you're
into Artificial Intelligence.... the algorithim had the solver of the
square root function picking the closest square of two digits figures,
then subtracting, etc.  The technique was a standard one you learn in
junior high school math, however although it's good for 7th graders
who are pretty reasonably well equiped to deal with intuitive tricks,
it didn't seem a good algothim to translate into a computer language.
But......if you already have floating point this may not apply anyway
since most floating point extensions would have a square root function
built in.

I'll assume you only have a standardized fixed point integer
implementation of Forth.  If that is the case, there should be some
radically different approach one could take in Fixed point to solve for
a square root using only integer calculations.  I 'm sorry to be only
able to turn you back to a search in the literature.  Perhaps you have
a better library than I and can turn up something.

My guess is that a solution relying on the strengths of Forth would be
better and more efficient than finding something of a hi-level solution
in an alternative language and  then translating to Forth.

Good luck.
Tamir Weiner
UMFORTH@WEIZMANN.BITNET
Acknowledge-To:  <UMFORTH@WEIZMANN>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads