Date: Fri, 22 Aug 2003 09:19:34 +0100
Reply-To: Roland <roland@RASHLEIGH-BERRY.FSNET.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Roland <roland@RASHLEIGH-BERRY.FSNET.CO.UK>
Organization: Universe Monitors
Subject: Re: Tiny Roundoff Errors in 8.2 for Windows
You might find this page of interest:
"Talbot Michael Katz" <topkatz@MSN.COM> wrote in message
> <<Sound of hand slapping forehead>> Of course! Thanks for the lucid
> explanation, Tim.
> On Fri, 22 Aug 2003 03:44:40 GMT, Tim Berryhill <tim@AARTWOLF.COM> wrote:
> >Dear TMK, It is a documented feature.
> >Most numbers which can be expressed as precise base 10 decimals cannot be
> >expressed as precise base 16 heximals. SAS numbers are floating point,
> >which means base 16 internally. The amounts the numbers are adjusted
> >you round them are not perfect, so that after you add or subtract rounded
> >numbers you need to round again to keep them pretty.
> >You might get more acceptable results by formatting your numbers 10.2 (or
> >one of the financial formats, as long as you specify 2 decimals) for
> >reporting, including formatting the tr_amount variable. If your customer
> >accepts any rounding, they should accept the rounding implicit in the
> >My SAS machine is 30 miles away, but I suspect
> >will also give you a tiny discrepancy because "twos complement" messed up
> >the last bit.
> >Tim Berryhill
> >"Talbot Michael Katz" <topkatz@MSN.COM> wrote in message
> >> Hi, gang.
> >> I seem to be experiencing very small arithmetic roundoff errors in SAS
> >> for Windows. Here is the code snippet :
> >> run_bal = round(run_bal+tr_amount,0.01);
> >> bal_dif = run_bal - prod_balance;
> >> tr_amount = -bal_dif;
> >> if tr_amount ne round(tr_amount,0.01) then do;
> >> put "prec_num = " prec_num " tr_amount not round 27";
> >> end ;
> >> Note that run_bal is rounded to 0.01 (i.e., dollars and cents) at the
> >> Prod_balance has also been rounded to 0.01, so bal_dif should be, too.
> >> But, somehow, tr_amount = -bal_dif is off by about 10**(-12).
> >> Has anyone else experienced something like this? Is it a documented
> >> problem?
> >> -- TMK --