Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!flaps From: flaps@utcsri.UUCP (Alan J Rosenthal) Newsgroups: comp.lang.c Subject: Re: C and Floating Point Message-ID: <4521@utcsri.UUCP> Date: Sat, 4-Apr-87 23:50:37 EST Article-I.D.: utcsri.4521 Posted: Sat Apr 4 23:50:37 1987 Date-Received: Sun, 5-Apr-87 12:54:23 EST References: <15958@sun.uucp> Reply-To: flaps@utcsri.UUCP (Alan J Rosenthal) Organization: University of Toronto Lines: 35 Keywords: C Fortran Floating Point Summary: In article <15958@sun.uucp> dgh@sun.UUCP writes: >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! Ahem. 1. Give any applied mathematician a calculator and the expression "(57382 * 23) + (57382 * 2)". They will ALL punch "57382 * 25" on the calculator. They know that parentheses can be rearranged. (obviously not disregarded, C doesn't do that.) 2. Kernighan and Plauger, in _The_Elements_of_Programming_Style_, note that the version of fortran at their local installation fails on an equality test when one number is on an input punch-card and the other, identically typed and also a constant, is in a program. This is because different scanning routines were used in the i/o library compiled with the fortran program and the i/o routines that were part of the fortran compiler! So much for floating-point equality in fortran. It's just a fact of life that you can't count on floating-point equality (although nothing in C parallels the idiocy of having two versions of a floating-point number scanning routine). -- Alan J Rosenthal flaps@csri.toronto.edu, {seismo!utai or utzoo}!utcsri!flaps, flaps@toronto on csnet, flaps at utorgpu on bitnet. "Probably the best operating system in the world is the [operating system] made for the PDP-11 by Bell Laboratories." - Ted Nelson, October 1977