fork download
  1. #include <limits.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <float.h>
  6.  
  7. void PrintDoubleAsCBytes(double d, FILE* f)
  8. {
  9. unsigned char a[sizeof(d)];
  10. unsigned i;
  11. memcpy(a, &d, sizeof(d));
  12. for (i = 0; i < sizeof(a); i++)
  13. fprintf(f, "%0*X ", (CHAR_BIT + 3) / 4, a[i]);
  14. }
  15.  
  16. int main(void)
  17. {
  18. PrintDoubleAsCBytes(0.0, stdout); puts("");
  19. PrintDoubleAsCBytes(0.5, stdout); puts("");
  20. PrintDoubleAsCBytes(1.0, stdout); puts("");
  21. PrintDoubleAsCBytes(2.0, stdout); puts("");
  22. PrintDoubleAsCBytes(-2.0, stdout); puts("");
  23. PrintDoubleAsCBytes(DBL_MIN, stdout); puts("");
  24. PrintDoubleAsCBytes(DBL_MAX, stdout); puts("");
  25. PrintDoubleAsCBytes(INFINITY, stdout); puts("");
  26. #ifdef NAN
  27. PrintDoubleAsCBytes(NAN, stdout); puts("");
  28. #endif
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 E0 3F 
00 00 00 00 00 00 F0 3F 
00 00 00 00 00 00 00 40 
00 00 00 00 00 00 00 C0 
00 00 00 00 00 00 10 00 
FF FF FF FF FF FF EF 7F 
00 00 00 00 00 00 F0 7F 
00 00 00 00 00 00 F8 7F