Re: Avoiding Overflow



Igor,

I can see what you are trying to accomplish. How about this formula:

average of first 2:
avg2 = (x1+x2)/2

average of first 3, using the above:
avg3 = (avg2 + x3/2) * 2 / 3
the divide by 2 is required to give x3 the same weight as x1 and x2, but
this leaves the result: (x1+x2+x3)/2, and we wish to divide this by 3, not
2, thus multiple by 2, then divide by 3.

average of first 4 (same logic):
avg4 = (avg3 + x4/3) * 3 / 4

average of first 5:
avg5 = (avg4 + x5/4) * 4 / 5

etc.

Thus:

((((((x1+x2)/2) + x3/2) * 2/3) + x4/3) * 3/4) + ... + xn/(n-1)) * (n-1)/n

Charles, you could use this, which helps keep the total down during the
calculations, but note that you are still doing x1+x2, which could result in
an overflow. Some people will do this instead: x1/2 + x2/2 to get the
average without having the chance of overflow. The above formula could be
modified to include this precaution, as well.

--

Jason Doucette / Xona.com
www.jasondoucette.com / www.xona.com


.



Relevant Pages

  • How do i use multiple IF statements in word 2000?
    ... I have searched high and low for this, ... What I am trying to accomplish is have an if..then...else check 2 conditions ... does not give me the option to use multiple IF... ... Prev by Date: ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Use lagg(4) or Use Layer-4 Load Balancing?
    ... actually accomplished with layer-4 load balancing. ... articles and reviews that indicate that laggwill accomplish the ... teaming of multiple internet access sorces into a single logical pipe, ... You need to have multiple IP flows in order to ...
    (freebsd-net)
  • Re: Publishing Web Sites
    ... screenshots and break the single page into multiple pages ... since for various situations I'm pointing people to parts ... Tony Su ... >Either method will accomplish the same goal. ...
    (microsoft.public.windows.server.sbs)
  • Activex Export Multiple files
    ... i would like to accomplish this within an sql dts package using an ... activex script. ... Prev by Date: ...
    (microsoft.public.sqlserver.dts)
  • Copying 2 or more txt files into one.
    ... But I can't figure out how to accomplish that in Opal. ... The execute method keeps giving me an ... Jerry ... Prev by Date: ...
    (comp.databases.paradox)