fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <float.h>
  3. #include <math.h>
  4. #include <stdio.h>
  5.  
  6. #define max(a,b) (((a)>(b))?(a):(b))
  7.  
  8. void dispf(float f)
  9. {
  10. char str[32];
  11. char* pc;
  12. unsigned char* pf;
  13. int i, b;
  14.  
  15. pf = (unsigned char*)&f;
  16. pc = str;
  17. for (i = 0; i < 4; i++) {
  18. for (b = 0; b < 8; b++) {
  19. *pc++ = '0'+((pf[3-i]>>(7-b))&1);
  20. }
  21. }
  22. printf("%.1s %.8s %.23s\n", str, str + 1, str + 9);
  23. printf("%.8E\n", f);
  24. printf("%f\n", f);
  25. }
  26.  
  27. int main()
  28. {
  29. float a, b;
  30.  
  31. printf("a = 1970.199707\n");
  32. a = (float)1970.199707;
  33. dispf(a);
  34. printf("b = 1970.2\n");
  35. b = (float)1970.2;
  36. dispf(b);
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 1676KB
stdin
Standard input is empty
stdout
a = 1970.199707
0 10001001 11101100100011001100100
1.97019971E+03
1970.199707
b = 1970.2
0 10001001 11101100100011001100110
1.97019995E+03
1970.199951