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. char s[32];
  30. float a, b;
  31.  
  32. printf("a = 1970.199707\n");
  33. a = (float)1970.199707;
  34. dispf(a);
  35. sprintf(s, "%E", a);
  36. printf("b = %s\n", s);
  37. sscanf(s, "%E", &b);
  38. dispf(b);
  39. sprintf(s, "%.8E", a);
  40. printf("b = %s\n", s);
  41. sscanf(s, "%E", &b);
  42. dispf(b);
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 1676KB
stdin
Standard input is empty
stdout
a = 1970.199707
0 10001001 11101100100011001100100
1.97019971E+03
1970.199707
b = 1.970200E+03
0 10001001 11101100100011001100110
1.97019995E+03
1970.199951
b = 1.97019971E+03
0 10001001 11101100100011001100100
1.97019971E+03
1970.199707