Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.ARPA Path: utzoo!watmath!clyde!cbosgd!ihnp4!ucbvax!wiscvm.arpa!UMFORTH%WEIZMANN.BITNET From: UMFORTH%WEIZMANN.BITNET@WISCVM.ARPA Newsgroups: net.lang.forth Subject: FIGIL DIGEST Message-ID: <8509021430.AA09471@UCB-VAX.ARPA> Date: Mon, 2-Sep-85 10:30:00 EDT Article-I.D.: UCB-VAX.8509021430.AA09471 Posted: Mon Sep 2 10:30:00 1985 Date-Received: Wed, 4-Sep-85 04:46:58 EDT Sender: daemon@ucbvax.ARPA Organization: The ARPA Internet Lines: 77 Date: 15 Aug 85 08:23:00 EST From: CPT.GREG.ELDER 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: