Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!pitt!willett!ForthNet From: ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: A F P N , Amiga Forth Newsletter Message-ID: <2828.UUL1.3#5129@willett.pgh.pa.us> Date: 29 May 91 02:52:15 GMT Organization: (n.) to be organized. But that's not important right now. Lines: 117 Category 14, Topic 5 Message 4 Tue May 28, 1991 GARY-S at 06:19 EDT PORTED FROM the WELL => -------- From jax Tue May 21 22:19:23 1991 From: jax (Jack J. Woehr) Subject: Amiga Forth Programmers' Newsletter To: nobody (Jeremy Hillary Boob) Date: Tue, 21 May 91 22:18:59 PDT _ _ _ _ _ _ ___ _ __ ____ //\\ //\\//\\ ||//___ //\\ ||_ //\\ ||\\ || ||_|| PROGRAMMERS' //==\\// \\// \\||\\_////==\\ || \\// ||\\ || || || NEWSLETTER --------------------------------------------------------------------- Issue 91-05 : COMPLEX.F ( JForth); \ Submissions Eagerly Welcomed! Subscribe via {hplabs,pacbell,ucb}!well!jax jax@well.sf.ca.us with a Subject: header of AFPN SUBSCRIBE. \ Complex.F \ Complex Floating Point Routines by Randell Lawrence KG7GI \ Copyright 1991 Randell P. Lawrence \ Permission to freely use is herby granted. \ I can be contacted at: \ GENIE R.LAWRENCE10 \ CIS 72300,2606 \ Packet Radio KG7GI@WB7ULH.UT.USA.NA \ Complex numbers are entered as ordered floating point pairs with \ the real part second on the stack, and the imaginary part at the \ top. For magnitude and angle, the magnitude is second on the \ stack and the angle is at the top of the stack. INCLUDE? F* JU:FLOAT.FFP ANEW COMPLEX \ Usefull floating point words : F^2 ( r -- r^2) \ Square floating point number on stack FDUP F* ; \ Complex number stack manipulation : ZDROP ( z -- ) FDROP FDROP ; : ZDUP ( z -- z z ) FOVER FOVER ; : ZSWAP ( z1 z2 -- z2 z1 ) frot f>r frot fr> ; : ZNIP ( z1 z2 -- z2 ) ZSWAP ZDROP ; : Z! ( z addr --) DUP >R FCELL+ F! ( !j) R> F! ( !real) ; : Z@ ( addr -- z) DUP >R F@ ( @real) R> FCELL+ F@ ( @j) ; : ZVARIABLE CREATE 2 FCELLS ALLOT DOES> ; : ZCONSTANT CREATE HERE 2 FCELLS ALLOT Z! DOES> Z@ ; : Z>R ( z -- R: -- z) F>R F>R ; : ZR> ( -- z R: z --) FR> FR> ; : ZR@ ( -- z R: z -- z) ZR> ZDUP Z>R ; \ The simple version : ZOVER ( z1 z2 -- z1 z2 z1 ) ZSWAP ZDUP Z>R ZSWAP ZR> ; : ZROT ( z1 z2 z3 -- z2 z3 z1 ) Z>R ZSWAP ZR> ZSWAP ; 0.0 FCONSTANT F>Z ( r -- z) \ create a complex number 0.0 FCONSTANT J0 1.0 F>Z ZCONSTANT 1J0 \ return a complex '1' : ZNEGATE ( z -- -z ) FNEGATE FSWAP FNEGATE FSWAP ; : ZCONJUGATE ( z1 -- z2 ) FNEGATE ; : POLAR>RECT ( Zpolar -- Zrectangular ) \ x = R * cos(Angle), y = R * sin(Angle) DEG>RAD ZDUP FSIN F* F>R \ Imaginary (y) FCOS F* FR> ; \ Real (x) : RECT>POLAR ( Zrectangulr -- Zpolar ) \ Real = SQRT(X^2 + Y^2), Angle = ARCTAN(Y/X) fover f0< >r ZDUP FSWAP F/ FATAN RAD>DEG F>R \ Angle F^2 FSWAP F^2 F+ FSQRT FR> \ Magnitude fswap r> \ sign correction if ( real was a negative number,) fnegate ( result) then fswap ; \ Use Rectangular notation when using these words : Z+ ( z1 z2 -- z3) \ Add Complex numbers FROT F+ F>R F+ FR> ; : Z- ( z1 z2 -- z3) \ Subtrace complex numbers FROT FSWAP F- F>R F- FR> ; : Z* ( z1 z2 -- z3) \ Multiply complex numbers RECT>POLAR ZSWAP RECT>POLAR \ both numbers to polar. F>R FROT F* \ Multiply the magnitudes FSWAP FR> F+ \ Add the angles POLAR>RECT ; : Z/ ( z1 z2 -- z3) \ Divide complex numbers RECT>POLAR ZSWAP RECT>POLAR zswap F>R FROT fswap F/ \ divide the Magnitudes FSWAP FR> F- \ Subtract the Angles POLAR>RECT ; : 1/Z ( z1 -- 1/z1 ) \ Inverse of complex number 1J0 ZSWAP Z/ ; \ End of AFPN 91-05 ... Send in your Amiga Forth Examples! ----- 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