You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.4 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. /*
  2. * The following program was used to compute the first 100,000,000 decimal
  3. * digits of e = exp(1), on December 18-20, 1998.
  4. * Timings on a Sun UltraSparc-II (296 MHz), running Solaris 2.6, equipped
  5. * with 512 MB RAM and 2 GB swap:
  6. *
  7. * 100 digits:
  8. * computation of e: real time: 0.002 s, run time: 0.000 s
  9. * conversion to decimal: real time: 0.003 s, run time: 0.000 s
  10. * 1000 digits:
  11. * computation of e: real time: 0.018 s, run time: 0.020 s
  12. * conversion to decimal: real time: 0.028 s, run time: 0.020 s
  13. * 10000 digits:
  14. * computation of e: real time: 0.488 s, run time: 0.480 s
  15. * conversion to decimal: real time: 1.059 s, run time: 1.060 s
  16. * 100000 digits:
  17. * computation of e: real time: 8.139 s, run time: 8.010 s
  18. * conversion to decimal: real time: 16.593 s, run time: 16.540 s
  19. * 1000000 digits:
  20. * computation of e: real time: 122.383 s, run time: 121.020 s
  21. * conversion to decimal: real time: 252.524 s, run time: 250.760 s
  22. * 10000000 digits:
  23. * computation of e: real time: 2152.061 s, run time: 2056.430 s
  24. * conversion to decimal: real time: 3579.670 s, run time: 3388.990 s
  25. * 100000000 digits:
  26. * computation of e: real time: 40061.367 s, run time: 30449.630 s
  27. * conversion to decimal: real time: 54507.003 s, run time: 40063.510 s
  28. */
  29. #include <cln/number.h>
  30. #include <cln/io.h>
  31. #include <cln/integer.h>
  32. #include <cln/integer_io.h>
  33. #include <cln/float.h>
  34. #include <cln/float_io.h>
  35. #include <cln/real.h>
  36. #include <cln/complex.h>
  37. #include <cstring>
  38. #include <cln/timing.h>
  39. #include <cmath>
  40. using namespace std;
  41. using namespace cln;
  42. void
  43. sum_exp1 (uintC a, uintC b, cl_I & first, cl_I & second)
  44. {
  45. switch (b - a)
  46. {
  47. case 1:
  48. first = second = b;
  49. break;
  50. case 2:
  51. {
  52. cl_I s = (a + b) >> 1;
  53. second = s * b;
  54. first = second + b;
  55. }
  56. break;
  57. default:
  58. {
  59. cl_I lp, lq, rp, rq, tmp;
  60. uintC mid = (a + b) >> 1;
  61. sum_exp1 (a, mid, lp, lq);
  62. sum_exp1 (mid, b, rp, rq);
  63. tmp = lp * rq;
  64. first = tmp + rp;
  65. second = lq * rq;
  66. }
  67. break;
  68. }
  69. }
  70. namespace cln {
  71. extern cl_LF cl_I_to_LF(const cl_I&, uintC);
  72. }
  73. void
  74. const_exp1 (cl_LF & result, uintC dec)
  75. {
  76. uintC c = (uintC) (dec * ::log (10));
  77. uintC n = dec;
  78. uintC actuallen = (uintC)(3.321928094 * dec / intDsize);
  79. n = (uintC) ((n + c) / ::log ((double)n));
  80. n = (uintC) ((n + c) / ::log ((double)n));
  81. n = (uintC) ((n + c) / ::log ((double)n));
  82. n += 2;
  83. actuallen += 2;
  84. cout << "n = " << n << endl;
  85. cout << "actuallen = " << actuallen << endl;
  86. cl_I p, q;
  87. sum_exp1 (0, n, p, q);
  88. cout << "sum_exp1 ends ok" << endl;
  89. result = The(cl_LF)(cl_I_to_LF (p, actuallen) / cl_I_to_LF (q, actuallen));
  90. cout << "const_exp1 returns ok" << endl;
  91. }
  92. int
  93. main (int argc, char *argv[])
  94. {
  95. long digits = 100;
  96. while (argc >= 3) {
  97. if (!strcmp(argv[1],"-n")) {
  98. digits = atol(argv[2]);
  99. argc -= 2; argv += 2;
  100. continue;
  101. }
  102. break;
  103. }
  104. if (argc < 1)
  105. return(1);
  106. cl_LF c1;
  107. long l = digits;
  108. cout << "\nCalculating exp1 to " << l << " decimals" << endl;
  109. { CL_TIMING;
  110. const_exp1 (c1, l);
  111. }
  112. { CL_TIMING;
  113. cout << "@" << endl;
  114. cout << c1 << endl;
  115. cout << "@" << endl;
  116. }
  117. return(0);
  118. }