fork(1) download
  1. #include <math.h>
  2. #include <stdio.h>
  3.  
  4. void print(double x);
  5.  
  6. int main(void) {
  7. printf("%f\n", -1234.5678);
  8. print(-1234.5678);
  9. printf("%f\n", 10000000000000.0);
  10. print(10000000000000.0);
  11. printf("%f\n", 99999999999999.0);
  12. print(99999999999999.0);
  13. printf("%f\n", 0.0000001);
  14. print(0.0000001);
  15. printf("%f\n", 0.000001);
  16. print(0.000001);
  17. printf("%f\n", 0.99999999999999);
  18. print(0.99999999999999);
  19. return 0;
  20. }
  21.  
  22. void print(double x) {
  23. double y, z;
  24. int d, ds[64];
  25. int i;
  26.  
  27. if (x < 0.0) {
  28. putchar('-');
  29. }
  30.  
  31. y = fabs(x);
  32. z = y;
  33. for (i = 0;; ++i) {
  34. ds[i] = (int)fmod(z, 10.0);
  35. z /= 10.0;
  36. if (z < 1.0) {
  37. break;
  38. }
  39. }
  40. for (; i >= 0; --i) {
  41. putchar('0' + ds[i]);
  42. }
  43.  
  44. putchar('.');
  45.  
  46. z = y;
  47. for (;;) {
  48. z *= 10.0;
  49. d = (int)fmod(z, 10.0);
  50. z = fmod(z, 1.0);
  51. putchar('0' + d);
  52. if (z < 0.00000000000001) {
  53. break;
  54. }
  55. }
  56.  
  57. putchar('\n');
  58. }
  59.  
Success #stdin #stdout 0s 2296KB
stdin
Standard input is empty
stdout
-1234.567800
-1234.567800000000033833202905952930450439453125
10000000000000.000000
10000000000000.0
99999999999999.000000
99999999999999.0
0.000000
0.0000001
0.000001
0.000001
1.000000
0.9999999999999900079927783735911361873149871826171875