comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Comparing 2 arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Comparing 2 arrays [message #55676 is a reply to message #55540] Mon, 27 August 2007 10:52 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Fanning wrote:
> Conor writes:
>
>> Hmm... I think Jean might be on to something. After all, the error in
>> question hear is the rounding error of the computer, and that rounding
>> error is always an error on the last 'bit' of a floating point
>> number. So for instance if you had two floating point numbers:
>>
>> 1.1123453e15
>> and
>> 1.1123454e15
>>
>> These might be the same number (to within the rounding error) but the
>> difference between them is about 6.7e07. That's assuming of course
>> that I'm properly understanding floating point representation (I'm an
>> astronomer, not a computer engineer).
>
> I guess I'm thinking more about how a number got INTO
> the array in the first place. If it got there as a result
> of some kind of calculation, accumulative rounding errors
> could be a great deal larger than machine precision. And
> yet, you might still want these numbers to be "equal" for
> analysis purposes.

Jean H. is absolutely correct. The magnitude of the numbers in question must enter into
the computation of the value that corresponds to "close enough to zero".

E.g. If elements of the array that you are comparing are 1.23456789e+64 and
1.23456783e+64, then comparing to an absolute value that assumes the values are near 1.0
(such as 1.0e-06) will alway fail even if they are considered equal for the application in
question.

In Fortran95-speak, the equivalent is:

ABS(x - y) < (ulp * SPACING(MAX(ABS(x),ABS(y))))

where if the result is .TRUE., the numbers are considered equal.

The intrinsic function SPACING(x) returns the absolute spacing of numbers
near the value of x,

{ EXPONENT(x)-DIGITS(x)
{ 2.0 for x /= 0
SPACING(x) = {
{
{ TINY(x) for x == 0

The "ulp" factor scales the comparison.

So, Jean H's "epsilon * data1.A" is a way of computing the absolute spacing between two
numbers in IDL-space.

cheers,

paulv
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Is there somebody familiar with nurbs or b-Spline?
Next Topic: File Output in IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 00:13:54 PDT 2025

Total time taken to generate the page: 1.03832 seconds