/* float_sig.c find small, big and eps */ #include int main(int argc, char * argv[]) { double xx, xxp, xxeps; float x, xp, eps; int i; printf("float_sig.c running, may die \n"); printf("type float has about six significant digits \n"); printf("eps is the smallest positive number added to 1.0f that changes 1.0f\n"); eps=1.0; for(i=1; i<26; i++) /* we know about 24 bits */ { eps=eps/2.0; if(1.0f-eps == 1.0f) break; } eps=2.0*eps; printf("type float eps=%16.9E \n", eps); x=1.0; for(i=1; i<256; i++) /* we know about 8 bits */ { xp=x; x=x/2.0; if(x == 0.0f) break; } printf("type float small=%16.9E \n", xp); printf("this could be about 1.0E-38, above shows good IEEE floating point\n"); x=1.0; for(i=1; i<256; i++) /* we know about 8 bits */ { xp=x; x=x*2.0; if(x/2.0!=xp) break; } printf("type float large=%16.9E \n\n", xp); printf("type double has about fifteen significant digits \n"); xxeps=1.0; for(i=1; i<55; i++) /* we know about 52 bits */ { xxeps=xxeps/2.0; if(1.0-xxeps == 1.0) break; } xxeps=2.0*xxeps; printf("type double eps=%24.17E \n", xxeps); xx=1.0; for(i=1; i<4096; i++) /* we know about 11 bits */ { xxp=xx; xx=xx/2.0; if(xx == 0.0) break; } printf("type double small=%16.9E \n", xxp); printf("this could be about 1.0E-304, above shows good IEEE floating point\n"); xx=1.0; for(i=1; i<4096; i++) /* we know about 11 bits */ { xxp=xx; xx=xx*2.0; if(xx/2.0!=xxp) break; } printf("type double large=%16.9E \n", xxp); return 0; }