Comparison of Double values - Page 2-VBForums
Page 2 of 2 FirstFirst 12
Results 41 to 51 of 51

Thread: Comparison of Double values

  1. #41
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    bump because kayjay and I crossed posts

  2. #42
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    Originally posted by phinds
    ................anyone has any further quesitons on this subject ... fugeddaboudit !!! I'm sick of the whole thing. I first encounted this problem in about 1963 and I've explained the whole thing .............
    1963 Don't think even my mother born then!

    Thanx for the time and effort. Though I still don not completely understand I'll make an effort.

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  3. #43
    Banned plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    phinds, take a look at this page :

    http://hankfiles.pcvsconsole.com/answer.php?file=454


    I dont see any round for converting 5.375

  4. #44
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,039
    Originally posted by nemaroller
    These are all good explanations, but still, this code raises questions.... the binary equivalents are still equal..
    [/Highlight]
    Actually the only way to test Phinds theory (which I am in agreement with) would be to do the conversion in the other direction. You will probably find that you can come up with two different binary numbers that both convert to 1.4.

    Thanks for the explanation phinds .. but please dont be hard on someone for questioning 1.4<>1.4 = True

  5. #45
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    I dont see any round for converting 5.375
    which is EXACTLY in agreement with my statement.

    5.375 is rational in binary, so as I explained, it will not suffer any rounding error.

    You keep setting up strawmen to avoid a conclusion that you apparently don't like.

    Do the math on 1.4

  6. #46
    Banned plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    If you do the math on 1.4 yes you do end up with that trailing 1100.
    So then the value gets rounded. Right.

    The fact remains though that you're still comparing two numbers that would have been rounded the same.
    1.4 v 1.4

  7. #47
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,705
    Well, obviously Phinds must know what he's talking about...

    Its basically the fact that numbers you would think would have an absolute finite value in decimal, like .04, does not mean it is so in binary, because of the way that number system is set up... in fact, 0.4 seems to go on forever in binary when trying to convert that decimal fraction to binary... you just wont get an ending...

    The same applies for 1.36..... In my limited runs, it appears only decimal fractional numbers ending with 5, can have a finite representation in binary (.375,.5,.15)

  8. #48
    Member
    Join Date
    Aug 2001
    Location
    Washington DC
    Posts
    63
    Here is an example of what's going on. I had to write the program in C to demonstrate. Check out the subtle difference when I dumped the memory where the variables were stored. Then when I print the variables again, they appear equal. In memory, however they are not. The comparison operation checks that all bits are identical. Clearly, these variables appear to hold the same value...and for math calculations it would work fine. But for comparison they are definitely not equal.

    f1 = 1.360000
    f2 = 0.040000
    f3 = 1.400000
    f1 + f2 = 1.400000
    f1 dump = 0x600000003ff5c28f
    f2 dump = 0x400000003fa47ae1
    f3 dump = 0x600000003ff66666
    f4 dump = 0x6a0000003ff66666
    f1 = 1.360000
    f2 = 0.040000
    f3 = 1.400000
    f1 + f2 = 1.400000


    Here is the code I ran (for all you C buffs...it's a quick cloodge for a demo.)

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        void *temp;
        double f1 = 1.36f, f2 = 0.04f;
        double f3 = 1.4f;
        double f4;
        
        printf("f1 = %f\n", f1);
        printf("f2 = %f\n", f2);
        printf("f3 = %f\n", f3);
        f4 = f1 + f2;
        printf("f1 + f2 = %f\n", f4);
        
        temp = &f1;
        printf("f1 dump = 0x%x%x\n", *(int*)temp, *(int*)((int)temp + 4));
        temp = &f2;
        printf("f2 dump = 0x%x%x\n", *(int*)temp, *(int*)((int)temp + 4));
        temp = &f3;
        printf("f3 dump = 0x%x%x\n", *(int*)temp, *(int*)((int)temp + 4));
        temp = &f4;
        printf("f4 dump = 0x%x%x\n", *(int*)temp, *(int*)((int)temp + 4));
        
        printf("f1 = %f\n", f1);
        printf("f2 = %f\n", f2);
        printf("f3 = %f\n", f3);
        printf("f1 + f2 = %f\n", f4);
        
        return 0;
    }

  9. #49
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,705
    Actually, it appears only decimal fractions that are all odd and end with 5, will have a finite representation in binary....

    http://www.cs.nmsu.edu/~pfeiffer/cla...otes/base.html
    Last edited by nemaroller; Nov 6th, 2002 at 11:14 AM.

  10. #50
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,705
    Hell, thats not even true.... I don't know, guess there just isn't a solid rule here....

  11. #51
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,705
    But just to cool off this thread... the binary system was initially developed by Gottfried Wilhelm von Leibniz in 1623, but it was discovered the Chineese had actually developed it 700 years earlier.... solid lines are 1's, broken lines are 0's...

    http://www.albany.net/~cybernet/Iching.jpg

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.