MakeTable.cxx 627 B

12345678910111213141516171819202122232425
  1. // A simple program that builds a sqrt table
  2. #include <cmath>
  3. #include <fstream>
  4. #include <iostream>
  5. int main(int argc, char* argv[])
  6. {
  7. // make sure we have enough arguments
  8. if (argc < 2) {
  9. return 1;
  10. }
  11. std::ofstream fout(argv[1], std::ios_base::out);
  12. bool const fileOpen = fout.is_open();
  13. if (fileOpen) {
  14. fout << "double sqrtTable[] = {" << std::endl;
  15. for (int i = 0; i < 10; ++i) {
  16. fout << sqrt(static_cast<double>(i)) << "," << std::endl;
  17. }
  18. // close the table with a zero
  19. fout << "0};" << std::endl;
  20. fout.close();
  21. }
  22. return fileOpen ? 0 : 1; // return 0 if wrote the file
  23. }