Re: Precision issue?
From: Paul Van Delst (paul.vandelst_at_noaa.gov)
Date: 07/19/04
- Next message: Richard Maine: "Re: Precision issue?"
- Previous message: beliavsky_at_aol.com: "Re: Precision issue?"
- In reply to: beliavsky_at_aol.com: "Re: Precision issue?"
- Next in thread: Richard Maine: "Re: Precision issue?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 19 Jul 2004 13:44:07 -0400
beliavsky@aol.com wrote:
> 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?
If a loop is generated, unrolling it appropriately would be seemly I would think.
>
> To reduce roundoff error, one should sum the numbers in order of increasing
> size if they are all positive.
Yeah, the sorting of data to improve some summation algorithms was pretty much what I
meant by "caveat". The sorts of data I typically sum (1000000's of points of spectral
atmospheric transmittances) are always 0<x<1 so sorting doesn't provide a big enough
improvement to balance the actual sorting (in both time and code complexity). Have I
mentioned previously that I do pretty simple stuff? :o)
> 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.
Hmm. I don't know about that. I sort of like having to think about that sort of stuff
myself. Not because I'm a masochist, but it makes me appreciate and cogitate about
numerical precision/problems for subsequent problems.
cheers,
paulv
- Next message: Richard Maine: "Re: Precision issue?"
- Previous message: beliavsky_at_aol.com: "Re: Precision issue?"
- In reply to: beliavsky_at_aol.com: "Re: Precision issue?"
- Next in thread: Richard Maine: "Re: Precision issue?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|