[net.sources.bugs] A good checkbook acct. program

aburt@isis.UUCP (Andrew Burt) (02/06/86)

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

mjs@sfsup.UUCP (M.J.Shannon) (02/08/86)

> 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

rcj@burl.UUCP (Curtis Jackson) (02/08/86)

In article <310@isis.UUCP> aburt@isis.UUCP (Andrew Burt) writes:
>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

awk on SVR2 uses doubles -- from /usr/src/cmd/awk/awk.def:

typedef double awkfloat;

-- 

The MAD Programmer -- 919-228-3313 (Cornet 291)
alias: Curtis Jackson	...![ ihnp4 ulysses cbosgd mgnetp ]!burl!rcj
			...![ ihnp4 cbosgd akgua masscomp ]!clyde!rcj