Re: Precision issue?

beliavsky_at_aol.com
Date: 07/19/04


Date: 19 Jul 2004 12:27:06 -0500


Paul Van Delst <paul.vandelst@noaa.gov> wrote:

>Others have replied why the answer isn't what you think it should be. The
way the code
>you
>posted is accumulating is simply a bad way of adding numbers because it
doesn't take
>the
>imprecision of floating point calculations into account.
>
>I realise your example was probably oversimplified for posting to clf, but
can you do
>
>something like:
>
> y = real(i)*yy
>
>and avoid the summation altogether?
>
>If you are adding a set of numbers, e.g.
>
> y = 0.0
> do j = 1, 1000000
> y = y + x(j)
> end do
>
>you may want to look into some sort of compensated summation algorithm.
Kahan's method
>is
>a commonly known one, but there are plenty of others (most of them with
their own caveats.)

In Fortran 90/95 one can write y = SUM(x). I wonder how sophisticated the
implementation of SUM is in Fortran compilers. Do they just use the loop
above, perhaps with loop unrolling?

To reduce roundoff error, one should sum the numbers in order of increasing
size if they are all positive. Sometimes one has information about the magnitudes
and ordering of data. I wonder if it would make sense to add optional arguments
to the SUM function and other intrinsic functions, so that one could write

y = SUM(x,order="descending",sign="positive")

and have the compiler use the optimal summation algorithm.

Optional arguments could also help a compiler optimize. If one had a statement

if (sum(x,sign="positive") > y) do_something

The compiler could stop evaluating the recursive sum as soon as it exceeded
y.

Can someone suggest some easily generated sequences of floating point numbers
for which the difference between the true sum and that generated by naive
recursive summation is large? I want to see what compilers do.

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---



Relevant Pages

  • Re: Precision issue?
    ... >>you may want to look into some sort of compensated summation algorithm. ... > implementation of SUM is in Fortran compilers. ... the sorting of data to improve some summation algorithms was pretty much what I ...
    (comp.lang.fortran)
  • Re: gnu make problem
    ... Our education class concludes that amongst us, we have some candidates who ... probem on the microware compiler which provided the source code for the ... int add ... sum = a + b; ...
    (comp.lang.misc)
  • Re: canonical forms
    ... given n input variables there are two raised to two raised to n ... and sum of product form. ... which are lookup-table based; a LUT can directly map ... If you were writing a compiler, ...
    (sci.electronics.basics)
  • Re: Higher Order Byte-Code Instructions
    ... framework at all to an optimising ... C compiler -- how can the compiler optimise code that is unknown until ... You keep talking about the type system, but (while I understand that it is ... return sum; ...
    (comp.lang.java.machine)
  • Re: ambigious call to overloaded function?
    ... message ambigious call to overloaded function? ... Giving the compiler version information, compiler command line, actual ... Variance is the mean of the sum of the squares ... Calculating variance as the mean of the sum of the squares of the ...
    (comp.lang.c.moderated)

Loading