Newsgroups: comp.lang.fortran Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!cornell!uw-beaver!milton!djo7613 From: djo7613@milton.u.washington.edu (Dick O'Connor) Subject: What is zero, REALly?? Message-ID: <1991Jun11.143915.11722@milton.u.washington.edu> Summary: Why does zero act like a small number? Keywords: real numbers, old Fortran, zero comparison Organization: University of Washington Distribution: usa Date: Tue, 11 Jun 1991 14:39:15 GMT I'm trying to port an old Fortran program written to run on an IBM main- frame to something a bit smaller. Part of the "truth test" of the new code (which is Pascal, but that's neither HNT) is that I have a printout of an old run of input and output data that I have to be able to regenerate. Fine except for one set of readings, which end up being a little bit off in a way that's not DIRECTLY related to rounding. I believe it's indirectly related to rounding via The Law Of Small Numbers (a handy catch-all excuse we use around here!), and I'd like some feedback from people with experience in how Fortran handles very small numbers. The routine in question takes the arithmetic mean of N positive real numbers in the range, say 40.0 to 90.0, and uses subtraction to find the number that is the furthest away from that mean. It computes a "difference" from the mean for each number and determines the greatest difference using the DABS (double-precision absolute value) function. The problem case is a specific case where N equals 2, so both real numbers have the same difference. The original code acts differently depending on which of the N numbers is the furthest distant from the mean, and does it in the case N=2 with a IF ( DABS(A(1)) - DABS(A(2)) ) 800,900,900 where A is a double precision real array. In almost every case, the middle branch is taken, but there's one case in particular where the first branch is taken, meaning there is a measurable difference between two numbers which should be identical. I believe it's a case of reaching the limits to which a binary machine can express a decimal-based number, with the result that two "identical" numbers are in fact only "very close", and their subtraction yields a number detectably different from zero. Anyone have any experience to corroborate or refute this? Thanks!! "Moby" Dick O'Connor djo7613@u.washington.edu Washington Department of Fisheries *I brake for salmonids* -- "Moby" Dick O'Connor djo7613@u.washington.edu Washington Department of Fisheries *I brake for salmonids*