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;
  24. int ds[64];
  25. int i, j;
  26.  
  27. if (x < 0.0) {
  28. putchar('-');
  29. }
  30.  
  31. y = fabs(x) * 1000000.0;
  32. i = 0;
  33. while (y >= 1.0) {
  34. ds[i++] = (int)fmod(y, 10.0);
  35. y /= 10.0;
  36. }
  37. while (i < 7) {
  38. ds[i++] = 0;
  39. }
  40. while (i > 0) {
  41. if (i == 6) {
  42. putchar('.');
  43. }
  44. putchar('0' + ds[--i]);
  45. }
  46.  
  47. putchar('\n');
  48. }
  49.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
-1234.567800
-1234.567800
10000000000000.000000
10000000000000.000000
99999999999999.000000
99999999999999.000586
0.000000
0.000000
0.000001
0.000001
1.000000
0.999999