Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site sfsup.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!mhuxm!sftig!sfsup!mjs From: mjs@sfsup.UUCP (M.J.Shannon) Newsgroups: net.sources.bugs Subject: Re: A good checkbook acct. program Message-ID: <122@sfsup.UUCP> Date: Sat, 8-Feb-86 01:11:11 EST Article-I.D.: sfsup.122 Posted: Sat Feb 8 01:11:11 1986 Date-Received: Tue, 11-Feb-86 05:39:54 EST References: <440@drutx.UUCP> <310@isis.UUCP> Distribution: net Organization: AT&T Information Systems, Summit N.J. Lines: 24 > 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 was using floats > for all the real values, rather than doubles. > > 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? > > Andrew Burt > isis!aburt or aburt@udenver.csnet But all banks use fixed point arithmetic. This has the advantage of being almost as fast as integer arithmetic, as well as preventing representation/roundoff errors. If you change the semantics of your program to store cents (rather than dollars), you can probably eliminate such errors (unless awk uses float/double for all numeric ops). Marty Shannon AT&T-IS Computer Systems (201)-522-6063