Re: Computer Statement Usage
From: Chuck Stevens (charles.stevens_at_unisys.com)
Date: 10/07/04
- Next message: Chuck Stevens: "Re: Computer Statement Usage"
- Previous message: Rick Smith: "Re: Computer Statement Usage"
- In reply to: JerryMouse: "Re: Computer Statement Usage"
- Next in thread: William M. Klein: "Re: Computer Statement Usage"
- Reply: William M. Klein: "Re: Computer Statement Usage"
- Reply: Rick Smith: "Re: Computer Statement Usage"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 7 Oct 2004 10:12:07 -0700
"JerryMouse" <nospam@bisusa.com> wrote in message
news:R7Gdner4pp05ovjcRVn-jA@giganews.com...
> Richard wrote:
> > Robert Wagner <robert@wagner.net.yourmammaharvests> wrote
> >
> >>> compute percentage = amount-one / (this + that) * 100.
> >>
> >> That's incorrect. It should be compute percentage = (100*
> >> amount-one)/(this + that). Your way loses precision.
> >
> > It is the assignment to percentage will most likely 'lose precision'
> > rather than the calculation. Donald's would only be 'incorrect' if
> > there was a loss in the precision that was specified, as indicated by
> > the number of decimal digits in 'percentage'.
> >
> > It requires proper numeric analysis to show which is incorrect. For
> > example if 'amount-one' is large enough then your way could exceed the
> > value allowable in the intermediate result leading to the completely
> > wrong answer, while Donald's may give a correct result always if
> > 'percentage' is, say, PIC S9(m)V99.
>
> Intermediate results matter for accuracy, they don't count for significant
> digits of precision. Division always loses precision.
>
> N x M / P is always more precise than N/P x M
>
>
So far as I know, nothing in the standards prevents the implementor from
rearranging the components of an arithmetic expression to cause it to
produce the most precise intermediate results '85 or prior standards, or in
2002 COBOL when Native Arithmetic is in effect.
-Chuck Stevens
- Next message: Chuck Stevens: "Re: Computer Statement Usage"
- Previous message: Rick Smith: "Re: Computer Statement Usage"
- In reply to: JerryMouse: "Re: Computer Statement Usage"
- Next in thread: William M. Klein: "Re: Computer Statement Usage"
- Reply: William M. Klein: "Re: Computer Statement Usage"
- Reply: Rick Smith: "Re: Computer Statement Usage"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]