why is the limits different ?

Discussion in 'C' started by aurnk, Dec 22, 2006.

Thread Status:
Not open for further replies.
  1. aurnk

    aurnk New Member

    Joined:
    Dec 13, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    why is the output1 different from output2 ?
    why is the output3 different from output4 ?
    /*my doubt is
    why is the limit of float (note 1) different from the limit of float1 (note 2)?*/
    Code:
    #include"fx.h"
    #define limit(t) (1*(pow(10,(-(t)))))//1*10^-t
    void floatlimit()//this checks when 0.00000000...1==1 for float
    {
          float i=1.0;int j=1;
          for(;i!=0;i/=10,j++);
          printf("\nthe limit of float is %d",j);//note 1
    }
    void doublelimit()//this checks when 0.00000000...1==1 for double
    {
          double i=1.0;int j=1;
          for(;i!=0;i/=10,j++);
          printf("\nthe limit of double is %d",j);//note 3
    }
    void floatlimit1()//this checks when 1.000...1==1 for float
    {
         float a;int i;
         for(a=1.1,i=1;a!=1;++i)
         {
                                a=1+limit(i);
         }
         printf("\nthe limit of float1 is %d",(i-1));//note 2
    }
    void doublelimit1()//this checks when 1.000...1==1 for double
    {
         double a;int i;
         for(a=1.1,i=1;a!=1;++i)
         {
                                a=1+limit(i);
         }
         printf("\nthe limit of double1 is %d",(i-1));//note 4
    }
    main()
    {
          void floatlimit();
          void floatlimit1();
          void doublelimit();
          void doublelimit1();
          floatlimit();
          floatlimit1();
          doublelimit();
          doublelimit1();
          getch();
    }
    /*
    bloodshed dev C++
    pentium 4 processor
    */
     
    Last edited by a moderator: Dec 22, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,341
    Likes Received:
    378
    Trophy Points:
    83
    Duplicate of [thread=2321]when is 0.00..1==1 & 1.00..001==1 ?[/thread]. Thread closed.
     
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice