Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!ames!oliveb!sun!dgh From: dgh@sun.UUCP Newsgroups: comp.lang.c Subject: C and Floating Point Message-ID: <15958@sun.uucp> Date: Tue, 31-Mar-87 17:01:06 EST Article-I.D.: sun.15958 Posted: Tue Mar 31 17:01:06 1987 Date-Received: Fri, 3-Apr-87 01:01:49 EST Organization: Sun Microsystems, Inc. - Mtn View, CA Lines: 113 Keywords: C Fortran Floating Point Summary: Study IEEE Standard and Fortran to understand floating point I regret that it's time for some flaming on this newgroup. After reading part way through too many postings which turn out to be another instance of the blind arguing with the ignorant, I have given up on individual mail responses which usually bounce anyway. Fortran was created before the phrase "computer science" was imagined, by people who were trained as applied mathematicians. Consequently they had some familiarity with what was needed and what had been done by mathematicians over the past several centuries. It would never have occurred to them, for instance, to disregard parentheses while evaluating expressions or to disallow equality comparison of numbers! Numerical difficulties are inherent in the nature of the problems to be solved and can't be legislated away by language design, but poor language design can exacerbate those problems, just as poor design makes Fortran I/O gratuitously more difficult than I/O problems inherently need to be. C was originally created and developed by people who knew and cared little for the issues of floating-point computation. This was tolerable while C was primarily used for implementing kernels and compilers, but now other people are building large numerical applications entirely in C. Version 3 of Spice is a relatively familiar and readily available example. Large numerical applications are written in C primarily for portability and because, in some non-numerical respects, the C environment is far more powerful than that of many older languages, particularly Fortran. Consequently persons who are expert in the way C has been are not always fully qualified to prescribe what C should become (particularly in the context of ANSI standardization). (The same statement applies to Fortran standardization, by the way). The energy spent arguing rationalizations for old or new mistakes in language design for C might be better spent thinking about why every other widely-used algebraic expression language requires (for instance) that parentheses be honored and allows numbers to be compared for equality. Studying Fortran as a model of language design is confusing since it requires much varied experience to be able to separate the good ideas from the bad. In the area of floating-point computation, there are later and better sources of inspiration, particularly in the expositions and explanations of the IEEE Standard, some of which are listed below. However, the committee which drafted that Standard, wanting to finish its work in timely fashion, declined to prescribe for specific programming languages. The perhaps naive thought was that the necessary ideas, once enumerated, would eventually be understood and incorporated in language standards in "correct" ways. Consequently the Standard does not mention the requirement, obvious to its drafters, that parentheses in algebraic expressions must be honored. It is worth observing that none of the numerical analysts who participated in its deliberations suggested that exact floating-point equality comparisons were undesirable or that fuzzy comparisons were. People who make dubious pronouncements outside their areas of expertise - by no means limited to this newsgroup or to the C language - undermine their credibility when speaking on subjects in which they are knowledgeable. As always - "better to remain silent and be thought a fool than to hit ^D and confirm it". Here are some ways to become knowledgeable about floating point: IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Std 754-1985, IEEE, New York, 1985. Coonen, Contributions to a Proposed Standard for Binary Floating-Point Arithmetic, Ph. D. thesis, University of California, Berkeley, 1984. Cody et al., "A Proposed Radix- and Word-length-independent Standard for Floating-Point Arithmetic," IEEE Computer, August 1984. Stevenson et al., Cody, Hough, Coonen, various papers proposing and analyzing a draft standard for binary floating-point arithmetic, IEEE Computer, March 1981. Coonen, "An Implementation Guide to a Proposed Standard for Floating-Point Arithmetic," IEEE Computer, January 1980. The Proposed IEEE Floating-Point Standard, special issue of the ACM SIGNUM Newsletter, October 1979. Apple Numerics Manual, Addison-Wesley, 1986. "Appendix: Accuracy of Numerical Calculations," in HP-15C Advanced Functions Handbook, 00015-90011, Hewlett-Packard, 1982. Cody and Waite, Software Manual for the Elementary Functions, Prentice-Hall, 1980. Bunch, Dongarra, Moler, Stewart, Linpack Users' Guide, SIAM, Philadelphia, 1979. Sterbenz, Floating-Point Computation, Prentice-Hall, 1974. Kahan, Implementation of Algorithms, 1973, NTIS # DDC AD-769 124. Kahan, "A Survey of Error Analysis," in Proceedings of 1971 IFIP Conference, IFIP, 1971.