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

Home » Public Forums » archive » strange "eq" behaviour
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
strange "eq" behaviour [message #69770] Mon, 15 February 2010 07:27 Go to next message
rogass is currently offline  rogass
Messages: 200
Registered: April 2008
Senior Member
Hi folks,
sometimes it's hard to understand IDL interprets, e.g.:

IDL> print,maxx
1.00000
IDL> help,maxx
MAXX FLOAT = 1.00000
IDL> if maxx eq 1. then print, 'true' else print,'wrong'
wrong
IDL> if maxx eq 1 then print, 'true' else print,'wrong'
wrong
IDL> if maxx eq float(1) then print, 'true' else print,'wrong'
wrong
IDL> if maxx eq maxx then print, 'true' else print,'wrong'
true
IDL> if maxx[0] eq 1 then print, 'true' else print,'wrong'
wrong
IDL> if maxx[0] eq 1. then print, 'true' else print,'wrong'
wrong
IDL> if 5 eq 5. then print, 'true' else print,'wrong'
true


What's going wrong here? Has somebody an idea? Is this a bug or a
feature ;)
I use IDL 6.4.1 within Windows 7 x64 Pro

Thanks and regards

Chris
Re: strange "eq" behaviour [message #69862 is a reply to message #69770] Mon, 15 February 2010 09:21 Go to previous message
rogass is currently offline  rogass
Messages: 200
Registered: April 2008
Senior Member
On 15 Feb., 17:18, Spon <christoph.b...@gmail.com> wrote:
> On Feb 15, 3:54 pm, chris <rog...@googlemail.com> wrote:
>
>> Hi David,
>> maxx is the correlation coefficient of some data series. It should be
>> exactly 1 if two data vectors are equal - but it isn't - so now I run
>> into bigger problems with the inbuilt correlate function . Anyway,
>> thanks for your hint.
>
>> CR
>
> Hi David,
>
> 'It should be exactly one' is a tricky statement in floating point
> arithmetic.
> Looks like a good time to trot out this old line again:http://www.dfanning.com/math_tips/sky_is_falling.html
>
> Your specific problem (or something very similar) is dealt with this
> article:http://www.dfanning.com/code_tips/comparearray.html
>
> You might have more success comparing floats using this program:http://www.dfanning.com/programs/floats_equal.pro
>
> Regards,
> Chris

Thank you for enlightening me. MAybe I have to do it in this way:
round(value1*(10^(((pp=precision<lowest_precision_of_both_types)))))
operator round(value1*pp) or I have to use the floats_equal.pro

Thanks and regards

CR
Re: strange "eq" behaviour [message #69866 is a reply to message #69770] Mon, 15 February 2010 08:18 Go to previous message
Spon is currently offline  Spon
Messages: 178
Registered: September 2007
Senior Member
On Feb 15, 3:54 pm, chris <rog...@googlemail.com> wrote:
> Hi David,
> maxx is the correlation coefficient of some data series. It should be
> exactly 1 if two data vectors are equal - but it isn't - so now I run
> into bigger problems with the inbuilt correlate function . Anyway,
> thanks for your hint.
>
> CR

Hi David,

'It should be exactly one' is a tricky statement in floating point
arithmetic.
Looks like a good time to trot out this old line again:
http://www.dfanning.com/math_tips/sky_is_falling.html

Your specific problem (or something very similar) is dealt with this
article:
http://www.dfanning.com/code_tips/comparearray.html

You might have more success comparing floats using this program:
http://www.dfanning.com/programs/floats_equal.pro

Regards,
Chris
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: strange "eq" behaviour
Next Topic: Re: Segfault when smoothing image

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

Current Time: Wed Oct 08 15:17:05 PDT 2025

Total time taken to generate the page: 0.00460 seconds