factorial_tables.cpp 999 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // (C) Copyright John Maddock 2007.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/limits.hpp>
  6. #include <vector>
  7. #include "mp_t.hpp"
  8. void write_table(unsigned max_exponent)
  9. {
  10. mp_t max = ldexp(mp_t(1), (int)max_exponent);
  11. std::vector<mp_t> factorials;
  12. factorials.push_back(1);
  13. mp_t f(1);
  14. unsigned i = 1;
  15. while(f < max)
  16. {
  17. factorials.push_back(f);
  18. ++i;
  19. f *= i;
  20. }
  21. //
  22. // now write out the results to cout:
  23. //
  24. std::cout << std::scientific << std::setprecision(40);
  25. std::cout << " static const boost::array<T, " << factorials.size() << "> factorials = {\n";
  26. for(unsigned j = 0; j < factorials.size(); ++j)
  27. std::cout << " " << factorials[j] << "L,\n";
  28. std::cout << " };\n\n";
  29. }
  30. int main()
  31. {
  32. write_table(16384/*std::numeric_limits<float>::max_exponent*/);
  33. }