strange "eq" behaviour [message #69770] |
Mon, 15 February 2010 07:27  |
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  |
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
|
|
|
|