fork(2) 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("%E\n", f);
  24. printf("%f\n", f);
  25. }
  26.  
  27. int main()
  28. {
  29. float a, b, c, d;
  30.  
  31. printf("a = 1970.2\n");
  32. a = (float)1970.2;
  33. dispf(a);
  34. printf("a = 1970.199707\n");
  35. a = (float)1970.199707;
  36. dispf(a);
  37. printf("b = 1.970200E+03\n");
  38. sscanf("1.970200E+03", "%E", &b);
  39. dispf(b);
  40. printf("c = fabsf(a - b)\n");
  41. c = fabsf(a - b);
  42. dispf(c);
  43. printf("d = FLT_EPSILON\n");
  44. d = FLT_EPSILON;
  45. dispf(d);
  46. printf("d = max(fabsf(a), fabsf(b))\n");
  47. d = max(fabsf(a), fabsf(b));
  48. dispf(d);
  49. printf("d = FLT_EPSILON * max(fabsf(a), fabsf(b))\n");
  50. d = FLT_EPSILON * max(fabsf(a), fabsf(b));
  51. dispf(d);
  52. printf("%s\n", (c<=d)?"true":"false");
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
a = 1970.2
0 10001001 11101100100011001100110
1.970200E+03
1970.199951
a = 1970.199707
0 10001001 11101100100011001100100
1.970200E+03
1970.199707
b = 1.970200E+03
0 10001001 11101100100011001100110
1.970200E+03
1970.199951
c = fabsf(a - b)
0 01110011 00000000000000000000000
2.441406E-04
0.000244
d = FLT_EPSILON
0 01101000 00000000000000000000000
1.192093E-07
0.000000
d = max(fabsf(a), fabsf(b))
0 10001001 11101100100011001100110
1.970200E+03
1970.199951
d = FLT_EPSILON * max(fabsf(a), fabsf(b))
0 01110010 11101100100011001100110
2.348661E-04
0.000235
false