I put positive value into variable which type is double. And when I saw the contents of the memory, the sign bit was 1. I think it should be 0, but it may be wrong. Why the sign bit was 1?
#include<stdio.h>
int main(){
int num=116;
union {float x; int i;} u4;
union {double x; long long int i;} u8;
u4.x = (float) num/10000.0;
u8.x = (double) num/10000.0;
printf("%lx\n",u4.i);
printf("%lx\n",u8.i);
printf("%.30f\n",u4.x);
printf("%.30f\n",u8.x);
return 0;
}
Output:
3c3e0ded
a5119ce0
0.011599999852478504000000000000
0.011599999999999999000000000000
a5119ce0 is double type's output.
a5119ce0 means
1010 0101 0001 0001 1001 1100 1110 0000
and it's sign bit is 1 which means this is negative number.
3c3e0ded is float type's output.
3c3e0ded means
0011 1100 0011 1110 0000 1101 1110 1101
I'm also puzzled that the same length results were obtained with float and double.