Re: Question about precision
From: Paul Van Delst (paul.vandelst_at_noaa.gov)
Date: 08/25/04
- Next message: Paul Van Delst: "Re: Question about precision"
- Previous message: James Giles: "Re: What do you prefer: real(8) or double precision and why?"
- In reply to: Keith Refson - real email address in signature: "Re: Question about precision"
- Next in thread: Mike Walters: "Re: Question about precision"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 25 Aug 2004 16:31:55 -0400
Keith Refson - real email address in signature wrote:
> Paul Van Delst <paul.vandelst@noaa.gov> writes:
>
>
>>I have code where I need to interpolate several instrument response
>>functions to the same frequency grid and begin and end
>>frequencies. The data I read in from file is at a set spacing,
>>0.1cm^-1, but after computing that value from the begin and end
>>frequency and the number of points, the value is always something like
>>0.1000000000000002cm^-1. This has caused problems since the extra
>>0.0000000000000002 makes a test that I use to ensure the interpolation
>>is alway within the actual data (extrapolation is a no-no here),
>>fail.
>
>
> Might I suggest a different approach. Your problem arises because
> your grid spacing of 0.1 cm^-1 has no exact representation in binary
> floating point. But the numerical value depends on the units
> and can be changed to suit. If your program used internal units of
> 0.1cm^-1 then the grid spacing would be 1.0 which *is* exactly representable.
> In fact you could use integers which would eliminate representation
> and rounding errors entirely.
Hello,
Yeah, I've thought about that, but the frequency interval can be anything. 0.1cm^-1 is an
"easy" one. I could get data at a spacing of 0.135cm-1 or 0.0025cm-1 spacing. I don't
necessarily know what the value is in advance so I have to compute it (I compute the
average of all the intervals, rather than the difference of just two points). So to take
into account a variable frequency interval, I'd still have to do something similar to the
dF_Exponent = INT( ABS( LOG10( Max_Delta_Frequency(l) ) ) ) + 2
dF_Multiplier = TEN**dF_Exponent
dF_Scaled = INT( Max_Delta_Frequency(l) * dF_Multiplier )
Max_Delta_Frequency(l) = REAL( dF_Scaled, fp_Kind ) / dF_Multiplier
stuff I mentioned before so I can determine what a unit grid spacing actually means.
And, besides, the calculations themselves (interpolation and integration) are performed
correctly. The little left over bits I mentioned don't affect those (since they are so
small), they just affect the < and > tests I use to QC the inputs.
cheers,
paulv
- Next message: Paul Van Delst: "Re: Question about precision"
- Previous message: James Giles: "Re: What do you prefer: real(8) or double precision and why?"
- In reply to: Keith Refson - real email address in signature: "Re: Question about precision"
- Next in thread: Mike Walters: "Re: Question about precision"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|