why is the limits different ?

aurnk's Avatar, Join Date: Dec 2006
Light Poster
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 shabbir; 22Dec2006 at 22:30.. Reason: Code formating.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Duplicate of when is 0.00..1==1 & 1.00..001==1 ?. Thread closed.