Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!hao!nbires!isis!aburt From: aburt@isis.UUCP (Andrew Burt) Newsgroups: net.sources.bugs Subject: Re: A good checkbook acct. program Message-ID: <310@isis.UUCP> Date: Thu, 6-Feb-86 09:43:02 EST Article-I.D.: isis.310 Posted: Thu Feb 6 09:43:02 1986 Date-Received: Sun, 9-Feb-86 06:37:19 EST References: <440@drutx.UUCP> Reply-To: aburt@isis.UUCP (Andrew Burt) Distribution: net Organization: University of Denver Math and Computer Science Lines: 28 Keywords: awk & floats I was using this checkbook program as an example in a course, plugged in some realistic numbers, and found it was coming up off by a cent, then two cents a bit later... What I found was that 'awk' on this system, a Pyramid 90x with OSx 2.5, and on a pure 4.2 system also, were using floats for all the real values, rather than doubles. With balances like $12345.67 we were hitting the limits of float representation, and getting 1/100 cent errors or so which eventually turned into 1 cent errors... I recompiled awk with doubles in awk.def, and not only did this of course go away, but awk ran faster at it. For instance: % awk 'BEGIN {printf "%f\n", 12345.67 ; exit}' 12345.669922 As this is off by .008 of a cent, after 125 of these you get close to losing a penny. Of course some representations will be over, and some under, but do you really want to trust your balance to fate? This showed up when a bank balance and a current balance disagreed by a cent. Though it shouldn't be a problem over a month, unless you write hundreds of checks, it makes it useless to keep entire years in one book. Anyone have any clues why floats are still used in awk rather than doubles? Now, are you SURE your bank was wrong...? Andrew -- Andrew Burt isis!aburt or aburt@udenver.csnet