( Zelefunt: Test complex square root File: zsqrt.fs Version: 0.9.3 Original Author: W. J. Cody [November 15, 1990] Ported by: David N. Williamss License: ACM noncommercial use Last revision: January 17, 2005 This is a port of W. J. Cody's CSQRT program in the celefunt package, from Fortran 77 to ANS Forth. As ACM Algorithm 714 [TOMS], celefunt is presumed to be under the ACM license for noncommercial use: http://www.acm.org/pubs/copyright_policy/softwareCRnotice.html Besides an ANS Forth environmental dependence on lower case, this code uses DEFER and IS. The code uses a complex number lexicon mostly compatible with that of Everett Carter in the Forth Scientific Library [FSL], with extensions by Julian Noble and myself [dnw]. In particular, a separate floating point stack is assumed, on which complex numbers like z=x+iy appear as [ x y], with y nearest the top. Quote from the original celefunt package: Program to test CSQRT Accuracy tests are based on the identity z = sqrt[z*z] Data required: None Subprograms required from this package: MACHAR - An environmental inquiry program providing information on the floating point arithmetic system. Note that the call to MACHAR can be deleted provided the following four parameters are assigned the values indicated: IBETA - the radix of the floating point system; IT - the number of base-IBETA digits in the significand of a floating-point number; XMIN - the smallest non-vanishing floating-point power of the radix; XMAX - the largest finite floating-point no. REN[K] - a function subprogram returning random real numbers uniformly distributed over [0,1] RESET, TABLAT, REPORT - programs to report results. Latest revision - November 15, 1990 Author - W. J. Cody Argonne National Laboratory Porting notes: Version 0.9.3 17Jan05 * Added summary output lines using .SHORT-ZSTATS from zfunstat.fs version 0.9.3. Version 0.9.2 8Apr03 * Adjusted to work with machar.fs 0.9.5 and later, which defines machine parameters as constants. Version 0.9.1 5Apr03 * Cosmetic changes to align with version 0.9.1 of zfunstat.fs. Version 0.9.0 11Mar03 * Start. 11Mar03 * Last revision. Our Forth port of MACHAR uses #DIGITS for IT, and also returns the floating point conversion of IBETA, called BETA. The port of REN does not take an argument. The argument K in the original Fortran has no effect on the value returned by REN. The port of RESET, TABLAT, and REPORT is contained in zfunstat.fs, which also loads the ports of MACHAR and REN. ) decimal s" FLOATING-EXT" environment? [IF] ( flag) drop s" FLOATING-STACK" environment? [IF] ( maxdepth) drop \ loadm complex \ pfe \ s" complex.fs" included \ be sure to make PRINCIPAL-ARG true s" complex-kahan.fs" included s" zfunstat.fs" included \ includes machar.fs 6 set-precision cr .( RANDOM ARGUMENT ACCURACY TESTS) cr cr .#fdigits cr cr .( Testing function z against gauge sqrt[z*z].) cr :noname ( -- ) zcurrent z@ fcurrent z! ; is function :noname ( -- ) zcurrent z@ z^2 zsqrt gcurrent z! ; is gauge 0e 0e corner1 z! 10e 10e corner2 z! get-zstats .zstats cr .( Summary:) .short-zstats cr cr .( NEW BOX) cr cr .( Testing function z against gauge -sqrt[z*z].) cr :noname ( -- ) zcurrent z@ z^2 zsqrt znegate gcurrent z! ; is gauge 0e 0e corner1 z! -100e 100e corner2 z! get-zstats .zstats cr .( Summary:) .short-zstats cr cr .( SPECIAL TESTS) cr cr .( Test of special argument:) cr .( SQRT 1.0+i0.0 = ) z=1 zsqrt zs. cr cr .( Tests near extreme arguments. These should not, but may) cr .( trigger error messages:) cr .( SQRT[ XMIN + i*XMIN ] = SQRT[ ) xmin fdup zdup zs. .( ]) cr 22 spaces .( = ) zsqrt zs. cr .( SQRT[ XMAX + i*XMAX ] = SQRT[ ) xmax fdup zdup zs. .( ]) cr 22 spaces .( = ) zsqrt zs. cr cr .( END OF TESTS) cr [ELSE] .( ***Separate floating point stack not available.) [THEN] [ELSE] .( ***Floating point not available.) [THEN]