fork download
  1. #include <stdio.h>
  2.  
  3. static const char* format = "%7.0e";
  4.  
  5. int main() {
  6. double a[] = {1, -0.60937, 0.60937, 0.009371, -0.009371,
  7. -1, -1.2e8, 1e-4, 1e-5, -1.5e-321, 0/.0, 1/0.};
  8. for (unsigned i = 0; i < sizeof(a) / sizeof(*a); ++i) {
  9. printf(format, a[i]);
  10. puts("");
  11. if (snprintf(0,0, format, a[i]) != 7)
  12. return 1;
  13. }
  14. }
  15.  
Success #stdin #stdout 0s 2828KB
stdin
Standard input is empty
stdout
  1e+00
 -6e-01
  6e-01
  9e-03
 -9e-03
 -1e+00
 -1e+08
  1e-04
  1e-05
-2e-321
   -nan
    inf