X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 28 May 2013 04:23 AM by  anon
a problem with relational operators
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
28 May 2013 04:23 AM
    Hi, I have compared two similar variables which were computed separately (je and je1). But after comparison, IDL knows them as non-similar. could you help me out? IDL> help, je JE DOUBLE = 6.7142891 IDL> help, je1 JE1 DOUBLE = 6.7142891 IDL> if (je ne je1) then print, "not equal" not equal

    Deleted User



    New Member


    Posts:
    New Member


    --
    28 May 2013 02:31 PM
    Hi there, If I do the following: IDL>JE=6.7142891D IDL>JE1=6.7142891D IDL>if (je ne je1) then print, "not equal" IDL> It works correctly. So, the question is, how did you defined those two variables? Remember that the type double contains many more decimal places than that. What you see when you say "help, je" is just the first 7 decimal places. so it is possible that both variables are not "exactly" the same. Cheers, fernando

    Deleted User



    New Member


    Posts:
    New Member


    --
    28 May 2013 02:32 PM
    Ah, welcome to the realm of computer science! You are about to learn how numbers are represented on computers. (Not to give anything away, but the answer is "not too well".) Here is an article that is well-thumbed by many a scientist before you: http://www.idlcoyote.com/math_tips/sk... Be sure you follow all the links. I can assure you, it will be worth your time. :-) Here are some other articles that may also be of interest to you: http://www.idlcoyote.com/..._tips/razoredge.html http://www.idlcoyote.com/math_tips/double.html http://www.idlcoyote.com/...h_tips/storenum.html http://www.idlcoyote.com/math_tips/oneplus.html

    Deleted User



    New Member


    Posts:
    New Member


    --
    28 May 2013 02:34 PM
    You might also be interested in the Coyote Library routine, Floats_Equal: http://www.idlcoyote.com/...ams/floats_equal.pro
    You are not authorized to post a reply.