i trying figure out how big number can use floating point number , double. not store way expected except integer value. double should hold 8 bytes of information enough hold variable a, not hold right. shows 1234567890123456768 in last 2 digits different. , when stored 214783648 or digit in last digit in float variable b, shows same value 214783648. supposed limit. what's going on?
double a; float b; int c; = 1234567890123456789; b = 2147483648; c = 2147483647; printf("bytes of double: %d\n", sizeof(double)); printf("bytes of integer: %d\n", sizeof(int)); printf("bytes of float: %d\n", sizeof(float)); printf("\n"); printf("you can count %.0f in 4 bytes\n", pow(2,32)); printf("you can count %.0f + or - sign in 4 bytes\n", pow(2,31)); printf("you can count %.0f in 4 bytes\n", pow(2,64)); printf("you can count %.0f + or - sign in in 8 bytes\n", pow(2,63)); printf("\n"); printf("double number: %.0f\n", a); printf("floating point: %.0f\n", b); printf("integer: %d\n", c); return 0;
sizeof(double) 8, true, double needs bits store exponent part well.
assuming ieee-754 used, double can represent integers @ 253 precisely, less 1234567890123456789.
Comments
Post a Comment