Re: Computer Statement Usage
From: Robert Wagner (robert_at_wagner.net.yourmammaharvests)
Date: 10/07/04
- Next message: Rick Smith: "Re: Computer Statement Usage"
- Previous message: Robert Wagner: "Re: String Functions in MF"
- In reply to: Richard: "Re: Computer Statement Usage"
- Next in thread: Chuck Stevens: "Re: Computer Statement Usage"
- Reply: Chuck Stevens: "Re: Computer Statement Usage"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 07 Oct 2004 16:54:08 GMT
On 7 Oct 2004 00:01:35 -0700, riplin@Azonic.co.nz (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.
Assuming intermediates are fixed-point ..
The number of digits left of decimal is easy for the compiler to
determine, but the number of digits to the right is indeterminate. It
is often infinite. For this reason, it is better to multiply first and
divide second.
- Next message: Rick Smith: "Re: Computer Statement Usage"
- Previous message: Robert Wagner: "Re: String Functions in MF"
- In reply to: Richard: "Re: Computer Statement Usage"
- Next in thread: Chuck Stevens: "Re: Computer Statement Usage"
- Reply: Chuck Stevens: "Re: Computer Statement Usage"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|