Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   when is 0.00..1==1 & 1.00..001==1 ? (http://www.go4expert.com/forums/when-is-00011-1000011-t2321/)

 aurnk 22Dec2006 14:38

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

//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
*/

 All times are GMT +5.5. The time now is 07:33.