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.

121 lines
3.3 KiB

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 <cl_number.h>
  30. #include <cl_io.h>
  31. #include <cl_integer.h>
  32. #include <cl_integer_io.h>
  33. #include <cl_float.h>
  34. #include <cl_float_io.h>
  35. #include <cl_real.h>
  36. #include <cl_complex.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <cl_timing.h>
  40. #include <math.h>
  41. void
  42. sum_exp1 (uintL a, uintL b, cl_I & first, cl_I & second)
  43. {
  44. switch (b - a)
  45. {
  46. case 1:
  47. first = second = b;
  48. break;
  49. case 2:
  50. {
  51. cl_I s = (a + b) >> 1;
  52. second = s * b;
  53. first = second + b;
  54. }
  55. break;
  56. default:
  57. {
  58. cl_I lp, lq, rp, rq, tmp;
  59. uintL mid = (a + b) >> 1;
  60. sum_exp1 (a, mid, lp, lq);
  61. sum_exp1 (mid, b, rp, rq);
  62. tmp = lp * rq;
  63. first = tmp + rp;
  64. second = lq * rq;
  65. }
  66. break;
  67. }
  68. }
  69. void
  70. const_exp1 (cl_LF & result, uintL dec)
  71. {
  72. uintL c = (uintL) (dec * log (10));
  73. uintL n = dec;
  74. uintC actuallen = (uintC)(3.321928094 * dec / intDsize);
  75. n = (uintL) ((n + c) / log ((double)n));
  76. n = (uintL) ((n + c) / log ((double)n));
  77. n = (uintL) ((n + c) / log ((double)n));
  78. n += 2;
  79. actuallen += 2;
  80. cout << "n = " << n << endl;
  81. cout << "actuallen = " << actuallen << endl;
  82. cl_I p, q;
  83. sum_exp1 (0, n, p, q);
  84. cout << "sum_exp1 ends ok" << endl;
  85. extern cl_LF cl_I_to_LF(const cl_I&, uintC);
  86. result = The(cl_LF)(cl_I_to_LF (p, actuallen) / cl_I_to_LF (q, actuallen));
  87. cout << "const_exp1 returns ok" << endl;
  88. }
  89. int
  90. main (int argc, char *argv[])
  91. {
  92. int digits = 100;
  93. while (argc >= 3) {
  94. if (!strcmp(argv[1],"-n")) {
  95. digits = atoi(argv[2]);
  96. argc -= 2; argv += 2;
  97. continue;
  98. }
  99. break;
  100. }
  101. if (argc < 1)
  102. exit(1);
  103. cl_LF c1;
  104. long l = digits;
  105. cout << "\nCalculating exp1 to " << l << " decimals" << endl;
  106. { CL_TIMING;
  107. const_exp1 (c1, l);
  108. }
  109. { CL_TIMING;
  110. cout << "@" << endl;
  111. cout << c1 << endl;
  112. cout << "@" << endl;
  113. }
  114. }