ForthNet@willett.UUCP (ForthNet articles from GEnie) (01/12/90)
Category 3, Topic 10 Message 30 Wed Jan 10, 1990 F.SERGEANT [Frank] at 21:04 CST Jim Matthews on Usenet writes: >I need to take the square root of a number ranging from 0 - >1,596,801,600. I am using MVP-FORTH (79-standard, no floating pt.) with >a few non-standard words that may apply (D*, D/MOD, M*/). I would >appreciate any input. Please reply by sending mail to >floyd@cscwam.umd.edu. Thanx!!! I don't know if this will get back to Usenet or not, but here are some quick thoughts. ( Newton's method for square root ) ( or at least my understanding of it) : ~SQRT ( ud - ud') ( "approximate square root") 32 FOR D2/ 2DUP OR WHILE NEXT THEN ( shift right while number is non-zero ) 2DROP 32 POP ( ie index) - ( power-of-2) 2/ ( power-of-2/2) 1 0 ( now we'll raise it back up to 1/2 the power of original number) ROT ?DUP IF 1- FOR D2* NEXT THEN ( ud') ; ( above gives us our first guess by halving the power of original number) : 2STEP ( ud-sq ud-last-root-guess - ud-sq ud-new-root-guess) 2OVER 2OVER ( sq guess sq guess) 2DUP D* ( sq guess sq guess^2) D- ( sq guess sq-sq') 2OVER D2* ( sq guess sq-sq' derivative) D/ D+ ( sq new-guess) ; ( given the original number and a guess as to its square root, 2STEP finds the difference between the original number and the square of our guess and divides that difference by the derivative dy/dx where y is our original number and x is the square root of y. For y = x^2 ; dy/dx = 2x. This quotient is added to our previous guess of x to get our new guess of x.) : DSQRT ( ud - ud^1/2) 2DUP D0= IF 2DROP 0 0 ( force result to zero if original number=0) ELSE 2DUP ~2ROOT ( original-number 1st-guess ) BEGIN 2DUP 2PUSH ( or >R >R ) ( save guess on return stack ) 2STEP ( improve guess ) 2DUP 2POP D= ( see if new guess is same as old ) UNTIL ( when guess stops changing, quit ) 2SWAP 2OVER ( guess number guess ) 2DUP D* ( guess number guess^2 ) D< IF 1 0 D- THEN ( guess ) ( Make sure that answer isn't too high by one. ) ( This gets around problem of D/ truncating toward zero. ) ( I don't think this would be needed if D/ is floored.) THEN ; I think 2STEP only needs to be done about 5 times at the most. It might be better to leave out the test for the new guess equaling the previous guess and just do 2STEP 5 or 6 times regardless of whether fewer times would be sufficient, e.g. : DSQRT ( ud - ud^1/2) 2DUP D0= IF 2DROP 0 0 ( force result to zero if original number=0) ELSE 2DUP ~2ROOT ( original-number 1st-guess ) 5 FOR 2STEP NEXT ( improve guess 6 times) 2SWAP 2OVER ( guess number guess ) 2DUP D* ( guess number guess^2 ) D< IF 1 0 D- THEN ( guess ) ( Make sure that answer isn't too high by one. ) ( This gets around problem of D/ truncating toward zero. ) ( I don't think this would be needed if D/ is floored.) THEN ; DSQRT gave the correct value for the few numbers I tested, but I'm not sure whether it goes crazy for certain numbers. D/ needs to be signed. You can replace 2PUSH with >R >R and 2POP with R> R>. You can replace 5 FOR ... NEXT with 6 0 DO ... LOOP. You can get the first guess ( ~SQRT) various ways. Actually, the first guess does not need to be very good, if you are willing to repeat 2STEP more times. It might be worth it to hard-code ~SQRT as 7 or 10000 and repeat 2STEP perhaps 20 times ( eg : ~SQRT ( - ud) 7 0 ; ) Good luck. -- Frank ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'
wmb@SUN.COM (Mitch Bradley) (01/12/90)
Here's a "brute force" square root using binary search. It probably
takes more iterations than Newton's method, but the inner loop is
pretty simple (only shifts and multiplies) and it might end up being
as fast or faster overall.
: dsqrt ( d -- n ) \ Note that the square root must fit in a single #
1 65535 ( d low high )
17 0 do
2over 2over + u2/ ( d d guess )
>r r@ r@ u* d< if ( d low high ) ( r: guess )
drop r> ( d low high' )
else ( d low high ) ( r: guess )
swap drop r> swap ( d low' high )
then ( d low' high' )
loop ( d low high )
2swap 2drop + u2/
;
The only catch is, the (ancient) version of MVP-FORTH that I have
doesn't have U2/ . It should be easy enough to implement; it's just
a right shift by 1. (My copy of MVP doesn't have SHIFT either, but
presumably your processor has a shift instruction).
By the way, here's a neat square root solution for single numbers which
is attributed to George Perry:
: sqrt ( n -- sqrt )
1 ( n 1 ) \ Initial guess
10 0 do ( n guess ) \ 20 is enough for 32 bits, 10 for 16 bits
2dup / ( n guess n/guess )
+ 2/ ( n newguess ) \ Average old guess and n/oldguess
loop ( n sqrt )
nip ( sqrt )
;
(No guarantees about either of these solutions)
Mitch
ForthNet@willett.UUCP (ForthNet articles from GEnie) (01/15/90)
Category 3, Topic 10 Message 31 Sun Jan 14, 1990 P.SNYDER1 at 04:24 PST Does anyone out there know how to do this: I want to compute s = a0 * b0 + a1 * b1 + ... + an * bn where n is to be determined at run time, and could be as large as 300, and the ai, bi are unsigned byte quantities, and s is to be scaled to an unsigned byte quantity. Also, I don't want to do it in floating point. It seems this should be pretty straight-forward, but I keep getting myself confused. I think Forth needs a word to detect when CARRY is set. Anyway, any input would be appreciated. Tx, .......paul ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'
wmb@SUN.COM (01/15/90)
>Does anyone out there know how to do this: I want to compute s = a0 * b0 + >a1 * b1 + ... + an * bn where n is to be determined at run time, and could be >as large as 300, and the ai, bi are unsigned byte quantities, and s is to be >scaled to an unsigned byte quantity. Also, I don't want to do it in floating >point. It seems this should be pretty straight-forward, but I keep getting >myself confused. I think Forth needs a word to detect when CARRY is set. 2 ways of detecting carry: 1) Perform the addition in double precision and look for a 1 in the high word. 2) : carry? ( a b -- flag ) negate u>= ; Flag is true if the unsigned addition of a and b would generate a carry. This only works for 2's complement machines. Mitch
ForthNet@willett.UUCP (ForthNet articles from GEnie) (02/22/90)
Category 3, Topic 10 Message 34 Tue Feb 20, 1990 D.RUFFER [Dennis] at 23:40 EST Gene, there is also a good random number generator in JFAR Vol 1 # 2 written by William T. Doyle that I've used many times. It also is slow, but has highly predictable behaviour (when desired) and duplicates the FORTRAN function IRN55. If your routine takes more than 3 blocks of code, you might want to check this one out. The one included with the PolyForth graphics package is merely fast and small. It was never intended to be "good". DaR ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'
ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/15/90)
Category 3, Topic 10 Message 37 Wed Mar 14, 1990 HARV at 03:27 MST Subject: Random Number Generators I am currently working on Monter Carlo simulation program. The literatue sources I have available stat that a linear and Gaussian random number generators are required. I have a shuffling random number generator alreay and think that it is a linear one. Any clarification of this matter would be greatly appreciated. I am especially interested if there is some way I can modify my existing random number generator to produce Gaussian random numbers. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'
BARTHO@CGEUGE54.BITNET (PAUL BARTHOLDI) (03/16/90)
>Category 3, Topic 10 >Message 37 Wed Mar 14, 1990 >HARV at 03:27 MST > > Subject: Random Number Generators > I am currently working on Monter Carlo simulation program. The literatue > sources I have available stat that a linear and Gaussian random number > generators are required. I have a shuffling random number generator alreay >and think that it is a linear one. Any clarification of this matter would > be greatly appreciated. I am especially interested if there is some way I > can modify my existing random number generator to produce Gaussian random >numbers. Two solutions : I assume that all your numbers are between 0 and 1. Then 1. sum 12 uniform random numbers, and substract 6. You get a ~gaussian number, with mean=0.0 and variance=1.0 . If you need gaussian with mean m and variance v, then multiply previous gaussian by v and add m . For realy most applications, this is a good gaussian generator. Only limitation : you will never get number above ou below 6 sigma ! 2. take 2 uniform random numbers x1 and x2, then calculate : n1 = sqrt( -2*log(x1) ) * cos( 2 * pi * x2) n2 = sqrt( -2*log(x1) ) * sin( 2 * pi * x2) then n1 and n2 are two independant gaussian random numbers, with mean=0 variance=1. See above for other means or variances. Ref: any book on Monte Carlo Methods, for example : J. M. Hammersley and D. C. Handscomb Monte Carlo Methods Methuen's Monographs on Applied Probability and statistics John Wiley and Sons Inc, London - New York 1964
ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/17/90)
Date: 03-15-90 (06:48) Number: 3031 (Echo) To: HARV Refer#: 2691 From: JACK WOEHR Read: NO Subj: MATHEMATICAL ROUTINES Status: PUBLIC MESSAGE > Subject: Random Number Generators > I am currently working on Monter Carlo simulation program. The literat > sources I have available stat that a linear and Gaussian random number > generators are required. I have a shuffling random number generator a >and think that it is a linear one. Any clarification of this matter wo > be greatly appreciated. I am especially interested if there is some w > can modify my existing random number generator to produce Gaussian ran >numbers. > Harv --- Download ISING.ARC from many of these fine ForthNet BBSes! (by Dr. Jeff Fox of NIST) =jax= NET/Mail : RCFB Golden, CO (303) 278-0364 VESTA & Denver FIG for Forth! ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'
ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/18/90)
Date: 03-15-90 (22:43) Number: 3033 (Echo) To: HARV Refer#: 3027 From: DOUG SCHIFFER Read: NO Subj: MATHEMATICAL ROUTINES Status: PUBLIC MESSAGE The following comes from the JPL C library. I had a use for this one myself once. I've included it in two parts. The rest of this letter is the credits. The next letter is the source code proper. Sorry to put it in C, but my knowledge of Forth is VERY scanty. Enjoy! /* 1.0 11-12-84 */ /********************************************************************* * Robert C. Tausworthe * * Jet Propulsion Laboratory * * Pasadena, CA 91009 1984 * ********************************************************************* * Normal-Distribution Random Number Generator. * * Computes a sample value from a normal distribution characterized by * zero mean and unit standard deviation. Uses "Box-Muller polar * method" for calculation of normal deviates, * * Box, G. E. P., and Muller, M. E., "A Note on the Generation of * Normal Deviates," ANNALS OF MATH. STAT., Vol. 29, pp. 610-611, * 1958. * * Refined in * * Knuth, D. E., FUNDAMENTAL ALGORITHMS, Vol II, "Seminumerical * Algorithms," Addison-Wesley Pub. Co., page 117. * */ --- * Via ProDoor 3.1R Of COURSE I'm egotistical - and DAMN PROUD of it, too! NET/Mail : Kadet PCB, Camden,NY, (315)245-3815 * MetroLink Regional Hub ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'
ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/18/90)
Date: 03-15-90 (22:47) Number: 3034 (Echo) To: HARV Refer#: 3027 From: DOUG SCHIFFER Read: NO Subj: MATHEMATICAL ROUTINES Status: PUBLIC MESSAGE #define LOCAL static #define BOOL int #define TRUE 1 #define FALSE 0 double random(); /* a function which returns a uniform random * number in the range [0.0 - 1.0] */ /****************************************************************/ double randnorm() /* Return a normally distributed random value with zero mean and unit standard deviation. */ /*--------------------------------------------------------------*/ { LOCAL BOOL first = 1; double d, v1, v2; if (first--) { do { v1 = 2.0 * random() - 1.0; v2 = 2.0 * random() - 1.0; /* v1 and v2 are each uniform on [-1, 1] */ d = v1 * v1 + v2 * v2; } while ((d <= 0.0) OR (d >= 1.0)); /* now, the point (v1, v2) is uniform inside the unit * circle, excluding the origin. */ d = sqrt(-2.0 * log(d) / d); v1 *= d; v2 *= d; return (v1); } else { first = TRUE; return (v2); } } --- * Via ProDoor 3.1R Of COURSE I'm egotistical - and DAMN PROUD of it, too! NET/Mail : Kadet PCB, Camden,NY, (315)245-3815 * MetroLink Regional Hub ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'
ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/21/90)
Date: 03-17-90 (13:50) Number: 80 (Echo) To: ALL Refer#: NONE From: DAVE MCMAHAN Read: (N/A) Subj: FFT'S, ANYBODY? Status: PUBLIC MESSAGE I have been trying to glean the inner workings of the FFT algorithm for about 3 years now. I have read several books (by Ramirez, Rabnier & Gould, etc) and am still confused as heck. Is there someone out there with enough working knowledge that I can ask questions of? I want to gain an intuitive feel for the process, not just be a number crunching monkey. I feel I understand the DFT pretty well, but the FFT is baffling. I also have other questions about processing signals in the time and frequency domains, but wel will get to those later. -dave NET/Mail : The Snake Pit - 408-287-2353 - San Jose, CA - Home of ProBBS ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'
ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/11/90)
Category 3, Topic 10 Message 43 Sun Jun 10, 1990 R.BERKEY [Robert] at 05:54 PDT Topic: integer division overflow Charlie Hitselberger writes, 900606: What does the standards committee think that "1000000. 3 UM/MOD" is supposed to leave on the stack? I'd leave a "1 65535" myself (the modulo and an overflow flag). Charlie, The committees haven't gotten involved with how overflow should behave. A nifty proposal showing that both programmers and implementors would benefit from such a requirement should get plenty of attention, though. Or, I'd welcome a call, where we could get into more details about such. I'm at 415 659-1334. What they have said up to now is that implementations must document the overflow behavior, BUT, such behavior might include playing Taps on the computer's speaker. Programs should assume the worst and hope that that is nothing more than that the program will be terminated, i.e., programs must prevent overflow. Onward to bits-and-bytes things, and values you'd return for an overflow, $FFFF is the largest possible quotient returned from UM/MOD , and it is also a Flag. I recall an instance where this result clued me in that I had some kind of range problem in a calculation. Yet, as for the "flag" aspect, check out that MU/MOD ( ud u -- u ud ) can be used as a UM/MOD with a "flag" result ( ud u -- u u flag ), a "flag" which if non-zero indicates an overflow(!!) Also, $FFFF is clearly not a correct result, just the closest real-number approximation under the limitations of a single-length quotient. Consider the following hypothesis, and I said almost as much to the X3.J14 committee in a proposal a couple of weeks ago: It is always a mistake to impose real-number concepts on the implementation of integer division. My preference is to return the low-order bits of the full-length quotient, along with the correct remainder as you suggest. Glen Haydon, for example, has a Julian date routine that needs such low-order bits of the quotient. Forth division implementations often go as far as determining that overflow is about to occur in a division, and from that point to getting these specific results is only a few Forth words further. (Um, at least that's true with unsigned division.) The resulting semantic/execution effect is that of implementing UM/MOD as MU/MOD DROP . Robert ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/11/90)
Category 3, Topic 10 Message 44 Sun Jun 10, 1990 R.BERKEY [Robert] at 05:57 PDT To: ALL Topic: division by zero and division overflow Knuth mentions returning the dividend as the remainder in a division by zero. The bit-by-bit division algorithms I've seen, if left to their own devices, do just that. As for the quotient, these algorithms usually return $FFFF or $7FFF, but I've not seen the program where it mattered specifically what the quotient was. As for the remainder, at least one language committee specifies this remainder for a division by zero--indeed, division by zero is the difference between APL's residue function and the Forth-83 MOD , i.e., APL gives a known result, and in Forth-83, 0 MOD is an error condition. On the Intel 80286 I can get at both the division overflow and division by zero cases without normal run-time overhead by installing a routine in the divide-by-zero interrupt. I'm uploading a file with such, DIV0.SEQ, although much of the detail there is 80286 specific. As the file shows, I still don't have the code to fix up the Intel IDIV opcode for overflow, other than for positive-operand cases. So I'll put out a request again for signed equivalents to the MU/MOD routine ( ud u -- u ud ) using the Intel (Forth-79) opcode. It may be that I could use an implementation of a Forth-79 M*/ ( d n n -- d ), preferably in 8086 assembler. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/16/90)
Category 18, Topic 17 Message 5 Sun Jul 15, 1990 NMORGENSTERN at 15:41 EDT Several FFT's in Forth. have been published. Dr. Dobbs Toolbox of Forth volume II has one by Joe Barnhart that should meet your criteria. It uses complex numbers consisting of two single-precision numnbers. Also, I remember that C. H. Ting has published one, but I can't find it in my notes. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/16/90)
Category 18, Topic 17 Message 6 Sun Jul 15, 1990 NMORGENSTERN at 16:27 EDT C. H. Ting published his continuous Fourier transform as "Fourier transform faster than fast Fourier transform" with Forth source code in his "Forth Notebook," published by Offete Enterprises, Inc. 1306 South "B" St, San Mateo CA 94402. The date is 1985, and you may wish to call him to see if he has improved it further. 415 574 8250. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
EM302723@VMTECMEX.BITNET ("Dr. Mangagoras 520-89-45", 5) (07/18/90)
> Several FFT's in Forth. have been published. Dr. Dobbs Toolbox of Forth volume >II has one... I had never heard of Dr. Dobb's Toolbox of Forth...anyone know where I can get it, prices, availability? Thank you very much,
ForthNet@willett.UUCP (ForthNet articles from GEnie) (08/03/90)
Date: 07-31-90 (07:08) Number: 1675 (Echo) To: ALL Refer#: NONE From: ZAFAR ESSAK Read: HAS REPLIES Subj: CATALOGUE NUMBERS Status: PUBLIC MESSAGE I am looking for any comments that might assist with the task of creating an index to an existing catalogue of items that are numbered. Reveiwing the existing numbering of catalogue items, which cannot be altered, it becomes apparant that the the following structure is in place. Each number can be 5 digits with the first 3 signifying a major division and the right 2 digits signifying more specificity. 078.1 781 781.0 Unfortunately, a blank to the right of the number is different than a zero. Thus, "781_" is different from "7810". Is there some way of approaching these numbers as integers, even double numbers, without resorting to floating point? --- * Via Qwikmail 2.01 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (08/03/90)
Date: 07-31-90 (16:52) Number: 1676 (Echo) To: ZAFAR ESSAK Refer#: 1798 From: ROGER BICKNELL Read: 07-31-90 (16:51) Subj: CATALOGUE NUMBERS Status: PUBLIC MESSAGE Hi Zafar, If I understood your message correctly, then you are looking for a good way to "key" on the given numbers. I assume that "781" is different from "781.0" If this is true, then floating point would not help you either. I assume that you want ONE type to represent the key ( ie. not a mix of single and double numbers, etc...) I can't see any other key format possible here other than : 1. ASCII string 2. Hashed binary ( possibly hashed from ASCII string ) RRRoger NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
colin@array.UUCP (Colin Plumb) (08/04/90)
Write the numbers in base 11, where you have the following translation: ASCII Value ' ' 0 '0' 1 '1' 2 '2' 3 '3' 4 '4' 5 '5' 6 '6' 7 '7' 8 '8' 9 '9' 10 Actually, you may only need to do this with the last two digits; the first three can be normal decimal numbers, multiplied by 121. -- -Colin
ForthNet@willett.UUCP (ForthNet articles from GEnie) (08/06/90)
Date: 08-01-90 (08:13) Number: 1678 (Echo) To: ROGER BICKNELL Refer#: 1676 From: ZAFAR ESSAK Read: 08-01-90 (16:23) Subj: CATALOGUE NUMBERS Status: PUBLIC MESSAGE RB> I assume that "781" is different from "781.0" Yes, Roger, that is one of the requirements. RB> I assume that you want ONE type to represent the key ( ie. not a RB> mix of single and double numbers, etc...) Preferably. RB> I can't see any other key format possible here other than : RB> 1. ASCII string RB> 2. Hashed binary ( possibly hashed from ASCII string ) Would you mind elaborating. Maybe with some example. Thanks. Zafar. --- * Via Qwikmail 2.01 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (08/06/90)
Category 3, Topic 10 Message 48 Sun Aug 05, 1990 R.BERKEY [Robert] at 04:47 PDT Zafar Essak writes 900731: I am...creating an index to an existing catalogue of items that are numbered...Each number can be 5 digits with the first 3 signifying a major division and the right 2 digits signifying more specificity. 078.1 781 781.0 Unfortunately, a blank to the right of the number is different than a zero. Thus, "781_" is different from "7810". Is there some way of approaching these numbers as integers, even double numbers, without resorting to floating point? Base 36 looks as if it should work: $20 CONSTANT #SP : UM+ ( wd u -- wd ) 0 D+ ; : UM* ( ud u -- ud ) DUP>R * ( lo hi*u) SWAP R> U*D ROT + ; : 36IT ( & # -- ud ) \ make the index 0, 2SWAP BOUNDS DO #36 UM* I C@ #SP - UM+ LOOP ; : .IT ( d -- ) \ display the index <# BEGIN #36 MU/MOD ROT ( d rem) #SP + HOLD ( d) 2DUP D0= UNTIL #> ( & #) 5 OVER - 0 MAX SPACES \ print leading spaces TYPE ; " 078.1" 36it .it 078.1 ok " 781 " 36it .it 781 ok " 781.0" 36it .it 781.0 ok " 78.1" 36it .it 78.1 ok " 99999" 36it .it 99999 ok Robert ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (08/06/90)
Date: 08-02-90 (16:19) Number: 1679 (Echo) To: ZAFAR ESSAK Refer#: 1678 From: ROGER BICKNELL Read: NO Subj: CATALOGUE NUMBERS Status: PUBLIC MESSAGE No. I wouldn't mind elaborating... AFTER I get back from a little vacation ( San Fran. :) I'm thinking here of some very straight forward methods of encoding simple database entries with the catalogue number providing the key. So one could keep the cat. # as a string and use a string comparison through a linked-list of records to search and insert/sort the records. Or one could keep an index array and use the cat. # as an index/offset into the array by hashing the string into a binary index value - and then reference the data via the index array. I'm still wondering, however, if this is what you were asking - as I'm sure that you're well-versed in database management. If you're interested in a discussion about same, then great... but I don't know if I could tell you anything that you don't already know ??? ...later NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/08/90)
Date: 08-06-90 (19:09) Number: 1680 (Echo)
To: ZAFAR ESSAK Refer#: NONE
From: MIKE NEMETH Read: NO
Subj: Count delimited convert Status: PUBLIC MESSAGE
Zafar, I could find the conference with your message so I put it here.
RE: dconvert
you ask how this would be handle in ANS forth?
Well, currently there is a word in ext-core set that does most of what
you want. It is :
>number ( ud1 addr1 u1 -- ud2 addr2 u2
where ud1 is a dnumber to "build" upon ( start it at 0 0)
addr1 is string addr
u1 is len
ud2 is the covert number ( maybe only the convertable part of string)
addr2 is the addr of 1st non converable or just passed the end of strig
u2 is the number not converted ( 0 if all coverted)
: dconvert 0 0 2swap >number 0= if drop true else drop 2drop 0 0 0 then;
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/13/90)
Date: 08-04-90 (14:55) Number: 1681 (Echo) To: ROGER BICKNELL Refer#: 1679 From: ZAFAR ESSAK Read: NO Subj: CATALOGUE NUMBERS Status: PUBLIC MESSAGE RB> So one could keep the cat. # as a string and use a string RB> comparison through a linked-list of records to search and RB> insert/sort the records. RB> Or one could keep an index array and use the cat. # as an RB> index/offset into the array by hashing the string into a RB> binary index value - and then reference the data via the RB> index array. I was hoping to avoid methods using multiple string comparisons, and am looking for some way to compress the catalogue ID that would provide unique keys for each ID that might be a double number. I think this would provide a smaller and faster Index. Your second suggestion might come close, especially if the hashing resulted in a single value for each catalogue ID. Zafar. --- * Via Qwikmail 2.01 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/16/90)
Date: 08-14-90 (20:27) Number: 3652 (Echo) To: R.BERKEY [ROBERT] Refer#: 3607 From: ZAFAR ESSAK Read: NO Subj: MATHEMATICAL ROUTINES Status: PUBLIC MESSAGE Thankyou Robert, and thanks to Colin Plumb for responding to my question about catalogue numbers where a following blank is significant and different from a 0. Robert's solution of using BASE 36 works fine but it surprised me in that it is not really using base 36 but rather treating everything from decimal 32 to 68 as valid "numeric" characters. This includes all kinds of punctuation. Whereas "36 BASE !" would include all numerals 0 to 9, and alphas from A to Z as valid "numeric" characters, but not include the punctuation. However, it does solve the problem of converting the strings to unique double numbers for purpose of an index. Furthermore, I noticed by your example that " 078.1" implies that in your system the Forth word " can be used in the interpretative mode, not just when compiling. Is this true? Zafar. --- * Via Qwikmail 2.01 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/18/90)
Date: 08-15-90 (14:37) Number: 3653 (Echo) To: ZAFAR ESSAK Refer#: 3652 From: NICK JANOW Read: NO Subj: INTERPRETED " Status: PUBLIC MESSAGE >Furthermore, I noticed by your example that " 078.1" implies that in >your system the Forth word " can be used in the interpretative mode, >not just when compiling. Is this true? I think MacFORTH allows " something" to be interpreted. Is it not allowed in other FORTHs? NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (09/12/90)
Date: 09-10-90 (10:19) Number: 3746 (Echo) To: ALL Refer#: NONE From: CHARLIE HITSELBERGER Read: (N/A) Subj: IS THIS COMMONLY DONE? Status: PUBLIC MESSAGE I recently had to write some code to roll dice in Forth, and here is what I wound up with. My question is, is the " 0 BEGIN DROP " a commonly used thing for loops that leave a value on the stack upon exit? CODE RANDU ( -- rnd ; leaves a random number 0-255 on the stack ) ... machine specific stuff to generate a random byte ... ENDCODE : DICE ( -- n1 n2 ) 2 0 DO 0 BEGIN DROP RANDU 7 AND DUP 6 < UNTIL 1+ LOOP ; Just wondering, that's all. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (09/13/90)
Category 3, Topic 10 Message 55 Wed Sep 12, 1990 D.RUFFER [Dennis] at 00:29 EDT Re: CHARLIE HITSELBERGER > My question is, is the " 0 BEGIN DROP " a commonly used thing for > loops that leave a value on the stack upon exit? That is one way to do it Charlie. Here is another: : DICE ( -- n1 n2 ) 2 0 DO BEGIN RANDU 7 AND DUP 6 < NOT WHILE DROP REPEAT 1+ LOOP ; However, this method costs one more jump every time the loop repeats in place of the literal you had that was executed once. Of course, if your machine does a */ with any reasonable speed, you might also try the following: : DICE ( -- n1 n2 ) 2 0 DO RANDU 6 256 */ LOOP ; Depending on how fast your random algorithm is and how often, on average, it doesn't satisfy your test, this may actually be faster. In fact, if you are out for absolute speed, get rid of the DO...LOOP in the above example and you've done just about as much as you can. That is unless you want to re-code RANDU to do the 8 bit MOD for you. Then you would have: : DICE ( -- n1 n2 ) 6 RANDU 6 RANDU ; Well, you asked. <grin> DaR ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (11/19/90)
To: RAY DUNCAN Refer#: 215 From: MICHAEL HAM Read: 11-15-90 (18:02) Subj: DOUBLE PRECISION * AND / Status: PUBLIC MESSAGE Conf: FORTH (58) Read Type: GENERAL (+) My knowledge of assembler is nil, and I would think that these would be assembler for speed. But I'll cheer like all get out if some other reader of the board contributes them. (In fact, Miller's approach of having a complete set of integer operators that run off a precision set by the user (programmer) is very attractive: you enter something like 4 EQU PRECISION and from then on these operators use four bytes of precision; 8 EQU PRECISION gives 8 bytes, and so on. So the usual (16-bit) operators are equivalent to 2 EQU PRECISION using the new operators. As I recall, the set included + - * / /MOD */ */MOD Just about all one could want. Current double precision operators in the LMI set are, I think, only + and - (that is, "native" double precision: operands and result all double-precision). If * and / are added, MOD and /MOD should be as well. (Presumably /MOD would be the primitive with MOD and / defined as that plus a DROP or NIP respectively. NET/Mail : LMI Forth Board, Los Angeles, CA (213) 306-3530 <<<>>> ----- This message came from GEnie via willett through a semi-automated process. Report problems to: dwp@willett.pgh.pa.us or uunet!willett!dwp
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (02/18/91)
Category 3, Topic 10 Message 60 Sun Feb 17, 1991 M.HAWLEY at 15:22 EST Anybody know of any F83 or F-PC routines using Chebyshev polynomials to generate transcende [D [D [D [D [D [D [D [D [D [Dfunction [D [D [D [D [D [D [D [Dlogs etc. ? I'd rather not reinvent this particular wheel. ----- This message came from GEnie via willett. You cannot Reply to the author using email. Please post a follow-up article, or use any instructions the author may have included (USMail addresses, telephone #, whatever). Report problems to: dwp@willett.pgh.pa.us or uunet!willett!dwp
wmb@MITCH.ENG.SUN.COM (Mitch Bradley) (02/21/91)
> Anybody know of any F83 or F-PC routines using Chebyshev polynomials to > generate transcendal functions, logs etc. ? Koopman, Phil, Jr., "Transcendental Functions", Forth Dimensions, Vol. IX, Number 4, Page 21. > I'd rather not reinvent this particular wheel. Right on! Down with reinventing wheels! Mitch
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (03/04/91)
Category 3, Topic 10
Message 63 Thu Feb 28, 1991
D.RUFFER [Dennis] at 21:29 EST
Re: cucmk@ux1.cts.eiu.edu (Chris Klaus)
> Is FSIN going to some other stack??
Chris, it sure looks like FSIN is using a floating point stack instead of the
parameter stack. I would suspect that you need to "push" the input parameter
onto the floating point stack before you call FSIN and "pop" the result back
off before you can use it in your DACA word. What Forth are you using?
Someone may be able to tell you how to make it work if we knew which one.
Otherwise, check your documentation to see what they say about the floating
point operators.
{B-{)> DaR
-----
This message came from GEnie via willett. You *cannot* reply to the author
using e-mail. Please post a follow-up article, or use any instructions
the author may have included (USMail addresses, telephone #, etc.).
Report problems to: dwp@willett.pgh.pa.us _or_ uunet!willett!dwp
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (03/04/91)
Date: 02-26-91 (11:21) Number: 1341 of 1349 (Echo) To: CROSBY STONE Refer#: NONE From: RAY DUNCAN Read: NO Subj: NUMBER? ETC. Status: PUBLIC MESSAGE Conf: FORTH (58) Read Type: GENERAL (+) Sorry about not getting back to you sooner. I didn't find your file NUMBER.TXT until a couple of days ago. Nobody stuffs the vectors for NUMBER? /NUMBER and NUMBER, *except* for the various floating point overlays during their installation (the BIN file is read into memory, relocated, and then the "top" word in the overlay is executed which pokes the vectors so that the Forth interpreter/compiler will know how to interpret or compile floating point numbers). If you load the SFP or I8087 overlay and *then* poke the vectors for NUMBER, /NUMBER and NUMBER? to point to your "own" versions of these words, the vectors will stay stable throughout the execution of your application. NUMBER? is the generalized ASCII-to-binary numeric conversion operation. It accepts the address of a counted string and returns a binary value and a flag (which indicates whether the string was a valid number or not, and if so which type of number) on the stack. NUMBER? is always called by the Forth interpreter/compiler regardless of STATE. NUMBER, is called by the Forth interpreter/compiler *after* NUMBER? if STATE is nonzero (i.e. the system is "compiling"). NUMBER, looks at the flag left by NUMBER? and decides how to compile the binary value beneath the flag as a literal. /NUMBER is called by the Forth interpreter/compiler *after* NUMBER? if STATE is zero (i.e. the system is "interpreting"). /NUMBER looks at the flag left by NUMBER? and discards the flag and any other debris, leaving only a single, double, or floating point value on the stack. Accordingly, the three words NUMBER? NUMBER, /NUMBER are a matched set and must all be replaced together (by poking the vectors for these three words) or not at all. NET/Mail : LMI Forth Board, Los Angeles, CA (213) 306-3530 <<<>>> ----- This message came from GEnie via willett. You *cannot* reply to the author using e-mail. Please post a follow-up article, or use any instructions the author may have included (USMail addresses, telephone #, etc.). Report problems to: dwp@willett.pgh.pa.us _or_ uunet!willett!dwp
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (05/08/91)
Date: 05-03-91 (12:56) Number: 2093 of 2105 (Echo) To: SHANNON VANCE Refer#: NONE From: RAY DUNCAN Read: 05-03-91 (16:29) Subj: SFPZ80 Status: PUBLIC MESSAGE Conf: FORTH (58) Read Type: GENERAL (+) The SFP works fine on my system exactly as it is supplied in the MC-Z80.ZIP file. The metacompiler knows how to handle \ comments in screen files. If you are getting error messages with this you must either be using an older metacompiler or you must have converted the file to a text file. The \ comment delimiter isn't supported in text files at the current time. If you compile the SFP file into the Z-80 kernel, it comes up in integer mode (COLD calls INTEGER which vectors NUMBER? NUMBER, and /NUMBER to the integer versions). To enable floating point you execute (or just type in) the word SFP which revectors NUMBER? NUMBER, and /NUMBER to their floating point equivalents. After that, floating point operations work fine (I just tried out the code in MC-Z80.SCR here once again to make sure the files hadn't gotten corrupted). For instance you can type in SFP <Enter> ( enable floating point) 2.0E0 FSQRT F. ( take square root of 2, displays 1.414...) NET/Mail : LMI Forth Board, Los Angeles, CA (213) 306-3530 <<<>>> ----- This message came from GEnie via willett. You *cannot* reply to the author using e-mail. Please post a follow-up article, or use any instructions the author may have included (USMail addresses, telephone #, etc.). Report problems to: dwp@willett.pgh.pa.us _or_ uunet!willett!dwp