fork download
  1. #include <stdio.h>
  2. #include <float.h>
  3.  
  4. union hoge {
  5. double d;
  6. char c[8];
  7. };
  8.  
  9. void printB(void) {
  10. int i;
  11. int e = sizeof(double) * 8 - DBL_MANT_DIG - 1 + 1;
  12. int f = DBL_MANT_DIG - 1;
  13. printf("D S");
  14. for (i = 0; i < e; i++) {
  15. putchar('E');
  16. }
  17. for (i = 0; i < f; i++) {
  18. putchar('F');
  19. }
  20. puts("");
  21. }
  22.  
  23. void printC(char c) {
  24. int n = 0xFF & (int)c;
  25. char s[9] = {0};
  26. int i;
  27. for (i = 0; i < 8; i++) {
  28. s[7 - i] = '0' + (char)(n & 0x1);
  29. n >>= 1;
  30. }
  31. printf("%s", s);
  32. }
  33.  
  34. void print(union hoge h) {
  35. int i;
  36. printf("F %50.47lf\nH ", h.d);
  37. for (i = 0; i < 8; i++)
  38. printf("%02X", 0xFF & (int)h.c[7 - i]);
  39. printf("\nB ");
  40. for (i = 0; i < 8; i++)
  41. printC(h.c[7 - i]);
  42. puts("");
  43. printB();
  44. puts("\n");
  45. }
  46.  
  47. int main(void) {
  48. union hoge h;
  49. int i;
  50.  
  51. printf("%d\n", DBL_MANT_DIG);
  52. printf("%d\n", sizeof(double) * 8);
  53. puts("");
  54.  
  55. h.d = 0.0; print(h);
  56. h.d = 0.25; print(h);
  57. h.d = 0.5; print(h);
  58. h.d = 0.2; print(h);
  59. h.d = 0.1; print(h);
  60. puts("");
  61. h.d = 1.0; print(h);
  62. h.d = 2.0; print(h);
  63. h.d = 3.0; print(h);
  64. h.d = 4.0; print(h);
  65. h.d = 8.0; print(h);
  66. puts("");
  67. h.d =-1.0; print(h);
  68. h.d =-2.0; print(h);
  69. h.d =-3.0; print(h);
  70. h.d =-4.0; print(h);
  71. h.d =-8.0; print(h);
  72.  
  73.  
  74. return 0;
  75. }
  76.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
53
64

F  0.00000000000000000000000000000000000000000000000
H 0000000000000000
B 0000000000000000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F  0.25000000000000000000000000000000000000000000000
H 3FD0000000000000
B 0011111111010000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F  0.50000000000000000000000000000000000000000000000
H 3FE0000000000000
B 0011111111100000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F  0.20000000000000001110223024625156540423631668091
H 3FC999999999999A
B 0011111111001001100110011001100110011001100110011001100110011010
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F  0.10000000000000000555111512312578270211815834045
H 3FB999999999999A
B 0011111110111001100110011001100110011001100110011001100110011010
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF



F  1.00000000000000000000000000000000000000000000000
H 3FF0000000000000
B 0011111111110000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F  2.00000000000000000000000000000000000000000000000
H 4000000000000000
B 0100000000000000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F  3.00000000000000000000000000000000000000000000000
H 4008000000000000
B 0100000000001000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F  4.00000000000000000000000000000000000000000000000
H 4010000000000000
B 0100000000010000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F  8.00000000000000000000000000000000000000000000000
H 4020000000000000
B 0100000000100000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF



F -1.00000000000000000000000000000000000000000000000
H BFF0000000000000
B 1011111111110000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F -2.00000000000000000000000000000000000000000000000
H C000000000000000
B 1100000000000000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F -3.00000000000000000000000000000000000000000000000
H C008000000000000
B 1100000000001000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F -4.00000000000000000000000000000000000000000000000
H C010000000000000
B 1100000000010000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


F -8.00000000000000000000000000000000000000000000000
H C020000000000000
B 1100000000100000000000000000000000000000000000000000000000000000
D SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF