Re: Precision issue?
beliavsky_at_aol.com
Date: 07/19/04
- Next message: Paul Van Delst: "Re: Precision issue?"
- Previous message: Richard Maine: "Re: AMD64 fortran and precision"
- In reply to: Paul Van Delst: "Re: Precision issue?"
- Next in thread: Paul Van Delst: "Re: Precision issue?"
- Reply: Paul Van Delst: "Re: Precision issue?"
- Reply: Richard Maine: "Re: Precision issue?"
- Reply: Tim Prince: "Re: Precision issue?"
- Reply: Arjen Markus: "Re: Precision issue?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 =---
- Next message: Paul Van Delst: "Re: Precision issue?"
- Previous message: Richard Maine: "Re: AMD64 fortran and precision"
- In reply to: Paul Van Delst: "Re: Precision issue?"
- Next in thread: Paul Van Delst: "Re: Precision issue?"
- Reply: Paul Van Delst: "Re: Precision issue?"
- Reply: Richard Maine: "Re: Precision issue?"
- Reply: Tim Prince: "Re: Precision issue?"
- Reply: Arjen Markus: "Re: Precision issue?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|