MakeTable.cxx 620 B

1234567891011121314151617181920212223242526272829303132
  1. // A simple program that builds a sqrt table
  2. #include <math.h>
  3. #include <stdio.h>
  4. int main(int argc, char* argv[])
  5. {
  6. int i;
  7. double result;
  8. // make sure we have enough arguments
  9. if (argc < 2) {
  10. return 1;
  11. }
  12. // open the output file
  13. FILE* fout = fopen(argv[1], "w");
  14. if (!fout) {
  15. return 1;
  16. }
  17. // create a source file with a table of square roots
  18. fprintf(fout, "double sqrtTable[] = {\n");
  19. for (i = 0; i < 10; ++i) {
  20. result = sqrt(static_cast<double>(i));
  21. fprintf(fout, "%g,\n", result);
  22. }
  23. // close the table with a zero
  24. fprintf(fout, "0};\n");
  25. fclose(fout);
  26. return 0;
  27. }