7811105@TWNCTU01.BITNET (11/30/89)
I am not to rise a dispute on the subject. But would someone has the experience in building a floating number system on forth or other language? Is using floating number necessary to a program? I know there are forth on remote-scopes, how did it master the data? Besides, can someone tell me how can I devide two real number eff- iciently? I only know to subtract repeatedly. Is this the best way? I've try to trace the generated code of other language, but using assembly language is a heavy task. I still can't realize the processes of it. Thanks. Joanna 7811105@Twnctu01.BITNET
A-PIRARD@BLIULG11.BITNET (Andr'e PIRARD) (11/30/89)
>Besides, can someone tell me how can I devide two real number eff- >iciently? I only know to subtract repeatedly. Is this the best Developing the arithmetic of mantissas held in double words in Taylor series shows that floating point division is a matter of 3 UM/MOD and 1 UM*. Plus a couple of shifts and exponent handling. This makes for a not-unreasonable, all-high-level, poor-man floating point package found in Comforth as a start for something more efficient. It hurts me exhibit pieces of gibberish like this, but I'll still do it to just give an idea of the arithmetics involved. \ TOS WORD: 2'S COMPLEMENT EXPONENT \ BOS 2 WORDS: MANTISSA ABSOLUTE VALUE \ SIGN IN HIGH ORDER BIT : F>I ( -- M / F -- : CONVERT TO INTERNAL FORMAT FTOP DUP 2@ EXP0 2! \ EXP & SIGN 2+ 2@ HEXA 7FFF AND \ MANTISSA FDROP ; : I>F ( M -- / -- F : CONVERT TO EXTERNAL FORMAT FPROD EXP0 2+ @ HEXA 8000 AND OR \ APPLY SIGN FTOP EXP0 @ OVER ! \ EXPONENT 2+ 2! ; \ MANTISSA \ ..... : AEXP ( -- EXP1 EXP0-ADDR / F0 F1 -- : ADJUST MULT/DIV SIGN+EXPONENT F>I EXP0>1 F>I 2SWAP SIGN0 SIGN1 C@ TOGGLE EXP1 @ EXP0 ; : F* ( / F0 F1 -- F0*F1 AEXP +! \ ADJUST SIGN+EXPONENT ROT >R >R >R \ M0L / M1L M1H M0H 1 RPICK UM* \ M0L*M1H / IDEM R> 1 RPICK UM* \ M0L*M1H M1L*M0H / M1H M0H D+ SWAP DROP 0 \ ALIGN DECIMAL POINT R> R> UM* D+ \ MN0*MN1 D2* \ ALIGN DECIMAL POINT LNORM I>F ; : F/ ( / F0 F1 -- F0/F1 AEXP -! \ ADJUST SIGN+EXPONENT D2* >R >R \ M0 / scaled M1L M1H 1 RPICK UM/MOD >R 0 SWAP \ DR / [M0/M1H]H M1L M1H 2 RPICK UM/MOD SWAP DROP R> \ M0/M1H /M1L M1H DUP R> -1 SHIFT UM* \ M0/M1H M0/M1H*M1L/2 / M1H R> UM/MOD SWAP DROP 0 D2* \ M0/M1H M0/M1H*M1L/M1H D- RNORM I>F ;
koopman@a.gp.cs.cmu.edu (Philip Koopman) (12/01/89)
There are several public domain Forth floating point packages available. One is my floating point book from Mountain View Press. It is highly portable, but designed for Forth-79 and not extremely efficient in the published form. There are other floating point packages available elsewhere, notably from the Forth Interest Group. Be sure to get one that does *not* rely on an 80x87 coprocessor if you want to understand the guts of the operations. At a more fundamental level, go to an academic library and look up books on "computer arithmetic". Phil Koopman koopman@greyhound.ece.cmu.edu Arpanet 2525A Wexford Run Rd. Wexford, PA 15090 Senior Scientist at Harris Semiconductor. I don't speak for them, and they don't speak for me.
housel@en.ecn.purdue.edu (Peter S. Housel) (12/02/89)
In article <7164@pt.cs.cmu.edu>, koopman@a.gp (Philip Koopman) writes: >At a more fundamental level, go to an academic library and >look up books on "computer arithmetic". Here is the bibliography for the Minix-PC Floating point package documentation. Hopefully someone will find some of these references of some use. There aren't any FORTH-specific references and some of them apply only to C or the Minix compiler. Anyone who wants to see the code (in 8086 unix-style assembler) and the full implementation notes can write and ask. -Peter S. Housel- housel@ecn.purdue.edu ...!pur-ee!housel REFERENCES 1. ANSI/IEEE, IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Std. 754-1985. New York, N.Y.: The Institute of Electrical and Electronics Engineers, Inc., 1985. 2. ANSI/IEEE, IEEE Standard for Radix-Independent Floating-Point Arithmetic, ANSI/IEEE Std. 854-1987. New York, N.Y.: The Institute of Eletrical and Electronics Engineers, Inc., 1987. 3. Cody, William J., and William Waite. Software Manual for the Elementary Functions, Englewood Cliffs, NJ: Prentice-Hall, 1980. 4. Grehan, Rick. "Some Assembly Required: Floating-Point Without a Coprocessor, Part 1," Byte 13(9): pp. 313-319, Sep. 1988. 5. Grehan, Rick. "Some Assembly Required: Floating-Point Without a Coprocessor, Part 2," Byte 13(10): pp. 293-298, Oct. 1988. 6. Hart, John F., E.W. Cheney, et al. Computer Approximations, New York: Robert E. Krieger Publishing Company, 1978. 7. Kernighan, Brian W., Dennis M. Richie. The C Programming Language, Second Edition. Englewood Cliffs, NJ: Prentice-Hall, 1988. 7. Knuth, Donald E. The Art of Computer Programming, Second Ed., Vol. 2, Chapter 4. Reading, Mass.: Addison-Wesley, 1981. 8. Motorola, Inc. MC68881/MC68882 Floating-Point Coprocessor User's Manual, Englewood Cliffs, NJ: Prentice-Hall, 1987. 9. Ochs, Tom. "Theory and Practice," Computer Language, 6(3): pp. 67-81, March 1989. 10. Plaugher, P.J. "Computer Arithmetic," Programming on Purpose, Computer Language, 5(2): pp. 17-23, Feb. 1988. 11. Plaugher, P.J. "Properties of Floating-point Arithmetic," Programming on Purpose, Computer Language, 5(3): pp. 17-22, Mar. 1988. 12. Plaugher, P.J. "Safe Math," Programming on Purpose, Computer Language, 5(5): pp. 17-21, May 1988. 13. Plaugher, P.J. "Do-it-yourself Math Functions," Programming on Purpose, Computer Language, 5(6): pp. 17-22, Jun. 1988. 14. Sterbenz, Pat. Floating Point Computation, Englewood Cliffs, NJ: Prentice-Hall, 1972. 15. Tanenbaum, Andrew, et al. "A Practical Tool Kit for Making Portable Compilers," Communications of the ACM 26(9): pp. 654-660, September 1983. 16. Wilson, Pete. "Floating-Point Survival Kit," Byte 13(3): pp. 217-226, Mar. 1988. 17. Young, David M., Robert Todd Gregory. A Survey of Mumerical Mathematics, Volume I, Reading, Mass: Addison-Wesley, 1972.