1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

when is 0.00..1==1 & 1.00..001==1 ?

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

  1. aurnk

    aurnk New Member

    Joined:
    Dec 13, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    //why is 1st line output different from 2nd line output ?
    /*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

Share This Page