long-decimal 0.00.18 → 0.00.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. data/README +23 -5
  2. data/Rakefile +5 -5
  3. data/VERSION +1 -1
  4. data/doc/classes/LongDecimal.html +10 -9
  5. data/doc/classes/LongDecimal.src/M000034.html +1 -1
  6. data/doc/classes/LongDecimal.src/M000035.html +1 -1
  7. data/doc/classes/LongDecimal.src/M000036.html +1 -1
  8. data/doc/classes/LongDecimal.src/M000037.html +1 -1
  9. data/doc/classes/LongDecimal.src/M000038.html +1 -1
  10. data/doc/classes/LongDecimal.src/M000039.html +1 -1
  11. data/doc/classes/LongDecimal.src/M000040.html +1 -1
  12. data/doc/classes/LongDecimal.src/M000041.html +1 -1
  13. data/doc/classes/LongDecimal.src/M000042.html +1 -1
  14. data/doc/classes/LongDecimal.src/M000043.html +1 -1
  15. data/doc/classes/LongDecimal.src/M000044.html +1 -1
  16. data/doc/classes/LongDecimal.src/M000045.html +1 -1
  17. data/doc/classes/LongDecimal.src/M000046.html +1 -1
  18. data/doc/classes/LongDecimal.src/M000047.html +1 -1
  19. data/doc/classes/LongDecimal.src/M000048.html +1 -1
  20. data/doc/classes/LongDecimal.src/M000049.html +1 -1
  21. data/doc/classes/LongDecimal.src/M000050.html +1 -1
  22. data/doc/classes/LongDecimal.src/M000051.html +1 -1
  23. data/doc/classes/LongDecimal.src/M000052.html +1 -1
  24. data/doc/classes/LongDecimal.src/M000053.html +1 -1
  25. data/doc/classes/LongDecimal.src/M000054.html +1 -1
  26. data/doc/classes/LongDecimal.src/M000055.html +1 -1
  27. data/doc/classes/LongDecimal.src/M000056.html +1 -1
  28. data/doc/classes/LongDecimal.src/M000058.html +1 -1
  29. data/doc/classes/LongDecimal.src/M000059.html +1 -1
  30. data/doc/classes/LongDecimal.src/M000060.html +1 -1
  31. data/doc/classes/LongDecimal.src/M000061.html +1 -1
  32. data/doc/classes/LongDecimal.src/M000062.html +1 -1
  33. data/doc/classes/LongDecimal.src/M000063.html +1 -1
  34. data/doc/classes/LongDecimal.src/M000064.html +1 -1
  35. data/doc/classes/LongDecimal.src/M000065.html +1 -1
  36. data/doc/classes/LongDecimal.src/M000066.html +1 -1
  37. data/doc/classes/LongDecimal.src/M000067.html +1 -1
  38. data/doc/classes/LongDecimal.src/M000068.html +1 -1
  39. data/doc/classes/LongDecimal.src/M000069.html +1 -1
  40. data/doc/classes/LongDecimal.src/M000070.html +1 -1
  41. data/doc/classes/LongDecimal.src/M000071.html +1 -1
  42. data/doc/classes/LongDecimal.src/M000072.html +1 -1
  43. data/doc/classes/LongDecimal.src/M000073.html +1 -1
  44. data/doc/classes/LongDecimal.src/M000074.html +1 -1
  45. data/doc/classes/LongDecimal.src/M000075.html +1 -1
  46. data/doc/classes/LongDecimal.src/M000076.html +1 -1
  47. data/doc/classes/LongDecimal.src/M000077.html +1 -1
  48. data/doc/classes/LongDecimal.src/M000078.html +1 -1
  49. data/doc/classes/LongDecimal.src/M000079.html +1 -1
  50. data/doc/classes/LongDecimal.src/M000080.html +1 -1
  51. data/doc/classes/LongDecimal.src/M000081.html +1 -1
  52. data/doc/classes/LongDecimal.src/M000082.html +1 -1
  53. data/doc/classes/LongDecimal.src/M000083.html +1 -1
  54. data/doc/classes/LongDecimal.src/M000084.html +1 -1
  55. data/doc/classes/LongDecimal.src/M000085.html +1 -1
  56. data/doc/classes/LongDecimal.src/M000086.html +1 -1
  57. data/doc/classes/LongDecimal.src/M000087.html +1 -1
  58. data/doc/classes/LongDecimal.src/M000088.html +1 -1
  59. data/doc/classes/LongDecimal.src/M000089.html +1 -1
  60. data/doc/classes/LongDecimal.src/M000090.html +1 -1
  61. data/doc/classes/LongDecimal.src/M000091.html +1 -1
  62. data/doc/classes/LongDecimal.src/M000094.html +1 -1
  63. data/doc/classes/LongDecimal.src/M000095.html +1 -1
  64. data/doc/classes/LongDecimal.src/M000096.html +1 -1
  65. data/doc/classes/LongDecimal.src/M000097.html +1 -1
  66. data/doc/classes/LongDecimal.src/M000098.html +1 -1
  67. data/doc/classes/LongDecimal.src/M000099.html +1 -1
  68. data/doc/classes/LongDecimalBase.html +10 -9
  69. data/doc/classes/LongDecimalBase.src/M000102.html +1 -1
  70. data/doc/classes/LongDecimalBase.src/M000103.html +1 -1
  71. data/doc/classes/LongDecimalBase.src/M000104.html +1 -1
  72. data/doc/classes/LongDecimalBase.src/M000105.html +1 -1
  73. data/doc/classes/LongDecimalBase.src/M000106.html +1 -1
  74. data/doc/classes/LongDecimalBase.src/M000107.html +1 -1
  75. data/doc/classes/LongDecimalBase.src/M000110.html +1 -1
  76. data/doc/classes/LongDecimalBase.src/M000111.html +1 -1
  77. data/doc/classes/LongDecimalBase.src/M000112.html +1 -1
  78. data/doc/classes/LongDecimalQuot.html +10 -9
  79. data/doc/classes/LongDecimalQuot.src/M000003.html +1 -1
  80. data/doc/classes/LongDecimalQuot.src/M000004.html +1 -1
  81. data/doc/classes/LongDecimalQuot.src/M000005.html +1 -1
  82. data/doc/classes/LongDecimalQuot.src/M000006.html +1 -1
  83. data/doc/classes/LongDecimalQuot.src/M000007.html +1 -1
  84. data/doc/classes/LongDecimalQuot.src/M000008.html +1 -1
  85. data/doc/classes/LongDecimalQuot.src/M000009.html +1 -1
  86. data/doc/classes/LongDecimalQuot.src/M000010.html +1 -1
  87. data/doc/classes/LongDecimalQuot.src/M000011.html +1 -1
  88. data/doc/classes/LongDecimalQuot.src/M000012.html +1 -1
  89. data/doc/classes/LongDecimalQuot.src/M000013.html +1 -1
  90. data/doc/classes/LongDecimalQuot.src/M000014.html +1 -1
  91. data/doc/classes/LongDecimalQuot.src/M000015.html +1 -1
  92. data/doc/classes/LongDecimalQuot.src/M000016.html +1 -1
  93. data/doc/classes/LongDecimalQuot.src/M000017.html +1 -1
  94. data/doc/classes/LongDecimalQuot.src/M000018.html +1 -1
  95. data/doc/classes/LongDecimalQuot.src/M000019.html +1 -1
  96. data/doc/classes/LongDecimalQuot.src/M000020.html +1 -1
  97. data/doc/classes/LongDecimalQuot.src/M000021.html +1 -1
  98. data/doc/classes/LongDecimalQuot.src/M000022.html +1 -1
  99. data/doc/classes/LongDecimalQuot.src/M000023.html +1 -1
  100. data/doc/classes/LongDecimalQuot.src/M000024.html +1 -1
  101. data/doc/classes/LongDecimalQuot.src/M000025.html +1 -1
  102. data/doc/classes/LongDecimalQuot.src/M000026.html +1 -1
  103. data/doc/classes/LongDecimalQuot.src/M000027.html +1 -1
  104. data/doc/classes/LongDecimalQuot.src/M000028.html +1 -1
  105. data/doc/classes/LongDecimalQuot.src/M000029.html +1 -1
  106. data/doc/classes/LongDecimalQuot.src/M000032.html +1 -1
  107. data/doc/classes/LongDecimalQuot.src/M000033.html +1 -1
  108. data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.html +20 -5
  109. data/doc/classes/LongMath.html +119 -64
  110. data/doc/classes/LongMath.src/M000113.html +1 -1
  111. data/doc/classes/LongMath.src/M000114.html +1 -1
  112. data/doc/classes/LongMath.src/M000115.html +1 -1
  113. data/doc/classes/LongMath.src/M000116.html +1 -1
  114. data/doc/classes/LongMath.src/M000117.html +1 -1
  115. data/doc/classes/LongMath.src/M000118.html +1 -1
  116. data/doc/classes/LongMath.src/M000119.html +1 -1
  117. data/doc/classes/LongMath.src/M000120.html +1 -1
  118. data/doc/classes/LongMath.src/M000121.html +1 -1
  119. data/doc/classes/LongMath.src/M000122.html +1 -1
  120. data/doc/classes/LongMath.src/M000123.html +1 -1
  121. data/doc/classes/LongMath.src/M000124.html +1 -1
  122. data/doc/classes/LongMath.src/M000125.html +1 -1
  123. data/doc/classes/LongMath.src/M000126.html +41 -25
  124. data/doc/classes/LongMath.src/M000127.html +1 -1
  125. data/doc/classes/LongMath.src/M000128.html +1 -1
  126. data/doc/classes/LongMath.src/M000129.html +1 -1
  127. data/doc/classes/LongMath.src/M000130.html +10 -38
  128. data/doc/classes/LongMath.src/M000131.html +41 -8
  129. data/doc/classes/LongMath.src/M000132.html +7 -4
  130. data/doc/classes/LongMath.src/M000133.html +4 -18
  131. data/doc/classes/LongMath.src/M000134.html +8 -7
  132. data/doc/classes/LongMath.src/M000135.html +13 -204
  133. data/doc/classes/LongMath.src/M000136.html +35 -39
  134. data/doc/classes/LongMath.src/M000137.html +129 -3
  135. data/doc/classes/Numeric.html +10 -9
  136. data/doc/classes/Numeric.src/M000100.html +1 -1
  137. data/doc/classes/Rational.html +10 -9
  138. data/doc/classes/Rational.src/M000101.html +1 -1
  139. data/doc/created.rid +1 -1
  140. data/doc/dot/f_0.dot +20 -7
  141. data/doc/dot/f_0.png +0 -0
  142. data/doc/dot/m_0_0.dot +20 -1
  143. data/doc/dot/m_0_0.png +0 -0
  144. data/doc/files/lib/long-decimal_rb.html +12 -11
  145. data/doc/files/lib/long-decimal_rb.src/M000001.html +1 -1
  146. data/doc/files/lib/long-decimal_rb.src/M000002.html +1 -1
  147. data/doc/fr_class_index.html +1 -0
  148. data/doc/fr_method_index.html +30 -26
  149. data/lib/long-decimal.rb +201 -53
  150. data/test/testlongdecimal.rb +4 -3
  151. metadata +3 -3
@@ -79,15 +79,16 @@
79
79
  <div id="contextContent">
80
80
  <div id="diagram">
81
81
  <map id="map" name="map">
82
- <area shape="RECT" coords="68,197,186,245" href="LongDecimalBase.html" alt="LongDecimalBase">
83
- <area shape="RECT" coords="163,5,243,53" href="Comparable.html" alt="Comparable">
84
- <area shape="RECT" coords="139,101,267,149" href="LongDecimalRoundingMode/RoundingModeClass.html" alt="RoundingModeClass">
85
- <area shape="RECT" coords="6,293,120,341" href="LongDecimalQuot.html" alt="LongDecimalQuot">
86
- <area shape="RECT" coords="144,293,238,341" href="LongDecimal.html" alt="LongDecimal">
87
- <area shape="RECT" coords="43,101,115,149" href="Numeric.html" alt="Numeric">
88
- <area shape="RECT" coords="267,5,339,53" href="Rational.html" alt="Rational">
89
- <area shape="RECT" coords="246,187,339,233" href="LongMath.html" alt="LongMath">
90
- <area shape="RECT" coords="128,68,304,160" href="LongDecimalRoundingMode.html" alt="LongDecimalRoundingMode">
82
+ <area shape="RECT" coords="29,5,109,53" href="Comparable.html" alt="Comparable">
83
+ <area shape="RECT" coords="60,204,140,252" href="LongMath/CacheKey.html" alt="CacheKey">
84
+ <area shape="RECT" coords="56,101,184,149" href="LongDecimalRoundingMode/RoundingModeClass.html" alt="RoundingModeClass">
85
+ <area shape="RECT" coords="201,204,319,252" href="LongDecimalBase.html" alt="LongDecimalBase">
86
+ <area shape="RECT" coords="139,300,253,348" href="LongDecimalQuot.html" alt="LongDecimalQuot">
87
+ <area shape="RECT" coords="277,300,371,348" href="LongDecimal.html" alt="LongDecimal">
88
+ <area shape="RECT" coords="235,101,307,149" href="Numeric.html" alt="Numeric">
89
+ <area shape="RECT" coords="133,5,205,53" href="Rational.html" alt="Rational">
90
+ <area shape="RECT" coords="49,171,177,263" href="LongMath.html" alt="LongMath">
91
+ <area shape="RECT" coords="45,68,221,160" href="LongDecimalRoundingMode.html" alt="LongDecimalRoundingMode">
91
92
  </map>
92
93
  <img src="../dot/f_0.png" usemap="#map" border=0 alt="TopLevel">
93
94
  </div>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1693</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1698</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_ld</span>(<span class="ruby-identifier">prec</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">mode</span> = <span class="ruby-constant">LongDecimal</span><span class="ruby-operator">::</span><span class="ruby-constant">ROUND_HALF_UP</span>)
15
15
  <span class="ruby-identifier">l</span> = <span class="ruby-constant">LongDecimal</span>(<span class="ruby-keyword kw">self</span>)
16
16
  <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">prec</span>.<span class="ruby-identifier">nil?</span>)
@@ -79,15 +79,16 @@
79
79
  <div id="contextContent">
80
80
  <div id="diagram">
81
81
  <map id="map" name="map">
82
- <area shape="RECT" coords="68,197,186,245" href="LongDecimalBase.html" alt="LongDecimalBase">
83
- <area shape="RECT" coords="163,5,243,53" href="Comparable.html" alt="Comparable">
84
- <area shape="RECT" coords="139,101,267,149" href="LongDecimalRoundingMode/RoundingModeClass.html" alt="RoundingModeClass">
85
- <area shape="RECT" coords="6,293,120,341" href="LongDecimalQuot.html" alt="LongDecimalQuot">
86
- <area shape="RECT" coords="144,293,238,341" href="LongDecimal.html" alt="LongDecimal">
87
- <area shape="RECT" coords="43,101,115,149" href="Numeric.html" alt="Numeric">
88
- <area shape="RECT" coords="267,5,339,53" href="Rational.html" alt="Rational">
89
- <area shape="RECT" coords="246,187,339,233" href="LongMath.html" alt="LongMath">
90
- <area shape="RECT" coords="128,68,304,160" href="LongDecimalRoundingMode.html" alt="LongDecimalRoundingMode">
82
+ <area shape="RECT" coords="29,5,109,53" href="Comparable.html" alt="Comparable">
83
+ <area shape="RECT" coords="60,204,140,252" href="LongMath/CacheKey.html" alt="CacheKey">
84
+ <area shape="RECT" coords="56,101,184,149" href="LongDecimalRoundingMode/RoundingModeClass.html" alt="RoundingModeClass">
85
+ <area shape="RECT" coords="201,204,319,252" href="LongDecimalBase.html" alt="LongDecimalBase">
86
+ <area shape="RECT" coords="139,300,253,348" href="LongDecimalQuot.html" alt="LongDecimalQuot">
87
+ <area shape="RECT" coords="277,300,371,348" href="LongDecimal.html" alt="LongDecimal">
88
+ <area shape="RECT" coords="235,101,307,149" href="Numeric.html" alt="Numeric">
89
+ <area shape="RECT" coords="133,5,205,53" href="Rational.html" alt="Rational">
90
+ <area shape="RECT" coords="49,171,177,263" href="LongMath.html" alt="LongMath">
91
+ <area shape="RECT" coords="45,68,221,160" href="LongDecimalRoundingMode.html" alt="LongDecimalRoundingMode">
91
92
  </map>
92
93
  <img src="../dot/f_0.png" usemap="#map" border=0 alt="TopLevel">
93
94
  </div>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1713</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1718</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_ld</span>(<span class="ruby-identifier">prec</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">mode</span> = <span class="ruby-constant">LongDecimal</span><span class="ruby-operator">::</span><span class="ruby-constant">ROUND_HALF_UP</span>)
15
15
  <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">prec</span>.<span class="ruby-identifier">nil?</span>)
16
16
  <span class="ruby-keyword kw">return</span> <span class="ruby-constant">LongDecimal</span>(<span class="ruby-keyword kw">self</span>)
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Thu Mar 30 23:29:34 CEST 2006
1
+ Sat Apr 01 11:11:32 CEST 2006
data/doc/dot/f_0.dot CHANGED
@@ -10,6 +10,16 @@ digraph TopLevel {
10
10
  color = black
11
11
  ]
12
12
 
13
+ Comparable [
14
+ URL = "classes/Comparable.html",
15
+ shape = box,
16
+ label = "Comparable"
17
+ ]
18
+
19
+ Comparable -> LongMath__CacheKey [
20
+
21
+ ]
22
+
13
23
  subgraph cluster_LongMath {
14
24
  fillcolor = palegreen1
15
25
  URL = "classes/LongMath.html"
@@ -20,10 +30,19 @@ digraph TopLevel {
20
30
  LongMath [
21
31
  shape = plaintext,
22
32
  height = 0.01,
23
- width = 0.75,
33
+ width = 0.01,
24
34
  label = ""
25
35
  ]
26
36
 
37
+ LongMath__CacheKey [
38
+ fontcolor = black,
39
+ URL = "classes/LongMath/CacheKey.html",
40
+ shape = ellipse,
41
+ color = palegoldenrod,
42
+ style = filled,
43
+ label = "CacheKey"
44
+ ]
45
+
27
46
  }
28
47
 
29
48
  LongDecimalRoundingMode -> LongMath [
@@ -31,12 +50,6 @@ digraph TopLevel {
31
50
  ltail = cluster_LongDecimalRoundingMode
32
51
  ]
33
52
 
34
- Comparable [
35
- URL = "classes/Comparable.html",
36
- shape = box,
37
- label = "Comparable"
38
- ]
39
-
40
53
  Comparable -> LongDecimalRoundingMode__RoundingModeClass [
41
54
 
42
55
  ]
data/doc/dot/f_0.png CHANGED
Binary file
data/doc/dot/m_0_0.dot CHANGED
@@ -10,6 +10,16 @@ digraph TopLevel {
10
10
  color = black
11
11
  ]
12
12
 
13
+ Comparable [
14
+ URL = "classes/Comparable.html",
15
+ shape = box,
16
+ label = "Comparable"
17
+ ]
18
+
19
+ Comparable -> LongMath__CacheKey [
20
+
21
+ ]
22
+
13
23
  subgraph cluster_LongMath {
14
24
  fillcolor = palegreen1
15
25
  URL = "classes/LongMath.html"
@@ -20,10 +30,19 @@ digraph TopLevel {
20
30
  LongMath [
21
31
  shape = plaintext,
22
32
  height = 0.01,
23
- width = 0.75,
33
+ width = 0.01,
24
34
  label = ""
25
35
  ]
26
36
 
37
+ LongMath__CacheKey [
38
+ fontcolor = black,
39
+ URL = "classes/LongMath/CacheKey.html",
40
+ shape = ellipse,
41
+ color = palegoldenrod,
42
+ style = filled,
43
+ label = "CacheKey"
44
+ ]
45
+
27
46
  }
28
47
 
29
48
  LongDecimalRoundingMode [
data/doc/dot/m_0_0.png CHANGED
Binary file
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Thu Mar 30 23:27:14 CEST 2006</td>
59
+ <td>Sat Apr 01 11:11:28 CEST 2006</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -69,15 +69,16 @@
69
69
  <div id="contextContent">
70
70
  <div id="diagram">
71
71
  <map id="map" name="map">
72
- <area shape="RECT" coords="68,197,186,245" href="../../classes/LongDecimalBase.html" alt="LongDecimalBase">
73
- <area shape="RECT" coords="163,5,243,53" href="../../classes/Comparable.html" alt="Comparable">
74
- <area shape="RECT" coords="139,101,267,149" href="../../classes/LongDecimalRoundingMode/RoundingModeClass.html" alt="RoundingModeClass">
75
- <area shape="RECT" coords="6,293,120,341" href="../../classes/LongDecimalQuot.html" alt="LongDecimalQuot">
76
- <area shape="RECT" coords="144,293,238,341" href="../../classes/LongDecimal.html" alt="LongDecimal">
77
- <area shape="RECT" coords="43,101,115,149" href="../../classes/Numeric.html" alt="Numeric">
78
- <area shape="RECT" coords="267,5,339,53" href="../../classes/Rational.html" alt="Rational">
79
- <area shape="RECT" coords="246,187,339,233" href="../../classes/LongMath.html" alt="LongMath">
80
- <area shape="RECT" coords="128,68,304,160" href="../../classes/LongDecimalRoundingMode.html" alt="LongDecimalRoundingMode">
72
+ <area shape="RECT" coords="29,5,109,53" href="../../classes/Comparable.html" alt="Comparable">
73
+ <area shape="RECT" coords="60,204,140,252" href="../../classes/LongMath/CacheKey.html" alt="CacheKey">
74
+ <area shape="RECT" coords="56,101,184,149" href="../../classes/LongDecimalRoundingMode/RoundingModeClass.html" alt="RoundingModeClass">
75
+ <area shape="RECT" coords="201,204,319,252" href="../../classes/LongDecimalBase.html" alt="LongDecimalBase">
76
+ <area shape="RECT" coords="139,300,253,348" href="../../classes/LongDecimalQuot.html" alt="LongDecimalQuot">
77
+ <area shape="RECT" coords="277,300,371,348" href="../../classes/LongDecimal.html" alt="LongDecimal">
78
+ <area shape="RECT" coords="235,101,307,149" href="../../classes/Numeric.html" alt="Numeric">
79
+ <area shape="RECT" coords="133,5,205,53" href="../../classes/Rational.html" alt="Rational">
80
+ <area shape="RECT" coords="49,171,177,263" href="../../classes/LongMath.html" alt="LongMath">
81
+ <area shape="RECT" coords="45,68,221,160" href="../../classes/LongDecimalRoundingMode.html" alt="LongDecimalRoundingMode">
81
82
  </map>
82
83
  <img src="../../dot/f_0.png" usemap="#map" border=0 alt="TopLevel">
83
84
  </div>
@@ -89,7 +90,7 @@ point
89
90
  </p>
90
91
  <p>
91
92
  CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/lib/long-decimal.rb,v
92
- 1.18 2006/03/30 21:06:43 bk1 Exp $ CVS-Label: $Name: PRE_ALPHA_0_18 $
93
+ 1.19 2006/04/01 08:52:06 bk1 Exp $ CVS-Label: $Name: PRE_ALPHA_0_19 $
93
94
  Author: $Author: bk1 $ (Karl Brodowsky)
94
95
  </p>
95
96
 
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1668</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1673</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span> = <span class="ruby-value">0</span>)
15
15
  <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">a</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimal</span>) <span class="ruby-keyword kw">then</span>
16
16
  <span class="ruby-identifier">a</span>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1681</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1686</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongDecimalQuot</span>(<span class="ruby-identifier">first</span>, <span class="ruby-identifier">second</span>)
15
15
  <span class="ruby-constant">LongDecimalQuot</span>.<span class="ruby-identifier">new!</span>(<span class="ruby-identifier">first</span>, <span class="ruby-identifier">second</span>)
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -26,6 +26,7 @@
26
26
  <a href="classes/LongDecimalRoundingMode.html">LongDecimalRoundingMode</a><br />
27
27
  <a href="classes/LongDecimalRoundingMode/RoundingModeClass.html">LongDecimalRoundingMode::RoundingModeClass</a><br />
28
28
  <a href="classes/LongMath.html">LongMath</a><br />
29
+ <a href="classes/LongMath/CacheKey.html">LongMath::CacheKey</a><br />
29
30
  <a href="classes/Numeric.html">Numeric</a><br />
30
31
  <a href="classes/Rational.html">Rational</a><br />
31
32
  </div>
@@ -20,25 +20,26 @@
20
20
  <div id="index">
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
- <a href="classes/LongDecimalQuot.html#M000021">% (LongDecimalQuot)</a><br />
24
23
  <a href="classes/LongDecimal.html#M000072">% (LongDecimal)</a><br />
24
+ <a href="classes/LongDecimalQuot.html#M000021">% (LongDecimalQuot)</a><br />
25
25
  <a href="classes/LongDecimal.html#M000073">& (LongDecimal)</a><br />
26
- <a href="classes/LongDecimal.html#M000065">* (LongDecimal)</a><br />
27
26
  <a href="classes/LongDecimalQuot.html#M000017">* (LongDecimalQuot)</a><br />
28
- <a href="classes/LongDecimalQuot.html#M000019">** (LongDecimalQuot)</a><br />
27
+ <a href="classes/LongDecimal.html#M000065">* (LongDecimal)</a><br />
29
28
  <a href="classes/LongDecimal.html#M000070">** (LongDecimal)</a><br />
30
- <a href="classes/LongDecimal.html#M000063">+ (LongDecimal)</a><br />
29
+ <a href="classes/LongDecimalQuot.html#M000019">** (LongDecimalQuot)</a><br />
31
30
  <a href="classes/LongDecimalQuot.html#M000015">+ (LongDecimalQuot)</a><br />
31
+ <a href="classes/LongDecimal.html#M000063">+ (LongDecimal)</a><br />
32
32
  <a href="classes/LongDecimalBase.html#M000105">+@ (LongDecimalBase)</a><br />
33
33
  <a href="classes/LongDecimal.html#M000064">- (LongDecimal)</a><br />
34
34
  <a href="classes/LongDecimalQuot.html#M000016">- (LongDecimalQuot)</a><br />
35
- <a href="classes/LongDecimalQuot.html#M000014">-@ (LongDecimalQuot)</a><br />
36
35
  <a href="classes/LongDecimal.html#M000062">-@ (LongDecimal)</a><br />
37
- <a href="classes/LongDecimalQuot.html#M000018">/ (LongDecimalQuot)</a><br />
36
+ <a href="classes/LongDecimalQuot.html#M000014">-@ (LongDecimalQuot)</a><br />
38
37
  <a href="classes/LongDecimal.html#M000069">/ (LongDecimal)</a><br />
38
+ <a href="classes/LongDecimalQuot.html#M000018">/ (LongDecimalQuot)</a><br />
39
39
  <a href="classes/LongDecimal.html#M000077"><< (LongDecimal)</a><br />
40
+ <a href="classes/LongMath/CacheKey.html#M000140"><=> (LongMath::CacheKey)</a><br />
41
+ <a href="classes/LongDecimalRoundingMode/RoundingModeClass.html#M000141"><=> (LongDecimalRoundingMode::RoundingModeClass)</a><br />
40
42
  <a href="classes/LongDecimalBase.html#M000110"><=> (LongDecimalBase)</a><br />
41
- <a href="classes/LongDecimalRoundingMode/RoundingModeClass.html#M000138"><=> (LongDecimalRoundingMode::RoundingModeClass)</a><br />
42
43
  <a href="classes/LongDecimal.html#M000094">== (LongDecimal)</a><br />
43
44
  <a href="classes/LongDecimalQuot.html#M000025">== (LongDecimalQuot)</a><br />
44
45
  <a href="classes/LongDecimal.html#M000095">=== (LongDecimal)</a><br />
@@ -51,7 +52,6 @@
51
52
  <a href="classes/LongDecimal.html#M000088">abs (LongDecimal)</a><br />
52
53
  <a href="classes/LongDecimalBase.html#M000109">abs2 (LongDecimalBase)</a><br />
53
54
  <a href="classes/LongDecimal.html#M000055">anti_equalize_scale (LongDecimal)</a><br />
54
- <a href="classes/LongMath.html#M000126">calc_pi (LongMath)</a><br />
55
55
  <a href="classes/LongMath.html#M000114">check_is_int (LongMath)</a><br />
56
56
  <a href="classes/LongMath.html#M000115">check_is_ld (LongMath)</a><br />
57
57
  <a href="classes/LongMath.html#M000117">check_is_mode (LongMath)</a><br />
@@ -60,36 +60,39 @@
60
60
  <a href="classes/LongDecimal.html#M000089">coerce (LongDecimal)</a><br />
61
61
  <a href="classes/LongDecimalQuot.html#M000024">coerce (LongDecimalQuot)</a><br />
62
62
  <a href="classes/LongDecimalBase.html#M000104">dec (LongDecimalBase)</a><br />
63
- <a href="classes/LongDecimalQuot.html#M000013">dec! (LongDecimalQuot)</a><br />
64
63
  <a href="classes/LongDecimal.html#M000060">dec! (LongDecimal)</a><br />
64
+ <a href="classes/LongDecimalQuot.html#M000013">dec! (LongDecimalQuot)</a><br />
65
65
  <a href="classes/LongDecimalQuot.html#M000006">denominator (LongDecimalQuot)</a><br />
66
66
  <a href="classes/LongDecimal.html#M000051">denominator (LongDecimal)</a><br />
67
67
  <a href="classes/LongDecimal.html#M000066">divide (LongDecimal)</a><br />
68
68
  <a href="classes/LongDecimal.html#M000067">divide_s (LongDecimal)</a><br />
69
- <a href="classes/LongDecimalQuot.html#M000020">divmod (LongDecimalQuot)</a><br />
70
69
  <a href="classes/LongDecimal.html#M000071">divmod (LongDecimal)</a><br />
70
+ <a href="classes/LongDecimalQuot.html#M000020">divmod (LongDecimalQuot)</a><br />
71
71
  <a href="classes/LongDecimal.html#M000054">equalize_scale (LongDecimal)</a><br />
72
72
  <a href="classes/LongMath.html#M000127">exp (LongMath)</a><br />
73
73
  <a href="classes/LongMath.html#M000129">exp10 (LongMath)</a><br />
74
74
  <a href="classes/LongMath.html#M000128">exp2 (LongMath)</a><br />
75
75
  <a href="classes/LongMath.html#M000130">exp_internal (LongMath)</a><br />
76
+ <a href="classes/LongMath.html#M000131">exp_raw (LongMath)</a><br />
76
77
  <a href="classes/LongMath.html#M000124">gcd_with_high_power (LongMath)</a><br />
77
- <a href="classes/LongDecimalQuot.html#M000032">hash (LongDecimalQuot)</a><br />
78
78
  <a href="classes/LongDecimal.html#M000098">hash (LongDecimal)</a><br />
79
+ <a href="classes/LongDecimalQuot.html#M000032">hash (LongDecimalQuot)</a><br />
80
+ <a href="classes/LongDecimalRoundingMode/RoundingModeClass.html#M000142">hash (LongDecimalRoundingMode::RoundingModeClass)</a><br />
79
81
  <a href="classes/LongDecimalBase.html#M000103">inc (LongDecimalBase)</a><br />
80
- <a href="classes/LongDecimalQuot.html#M000012">inc! (LongDecimalQuot)</a><br />
81
82
  <a href="classes/LongDecimal.html#M000059">inc! (LongDecimal)</a><br />
82
- <a href="classes/LongDecimal.html#M000099">inspect (LongDecimal)</a><br />
83
+ <a href="classes/LongDecimalQuot.html#M000012">inc! (LongDecimalQuot)</a><br />
83
84
  <a href="classes/LongDecimalQuot.html#M000033">inspect (LongDecimalQuot)</a><br />
85
+ <a href="classes/LongDecimal.html#M000099">inspect (LongDecimal)</a><br />
84
86
  <a href="classes/LongDecimal.html#M000053">int_digits10 (LongDecimal)</a><br />
85
87
  <a href="classes/LongDecimal.html#M000052">int_digits2 (LongDecimal)</a><br />
86
88
  <a href="classes/LongDecimalBase.html#M000108">inverse (LongDecimalBase)</a><br />
87
89
  <a href="classes/LongDecimalQuot.html#M000028">is_int? (LongDecimalQuot)</a><br />
88
90
  <a href="classes/LongDecimal.html#M000090">is_int? (LongDecimal)</a><br />
89
- <a href="classes/LongMath.html#M000132">log (LongMath)</a><br />
90
- <a href="classes/LongMath.html#M000133">log10 (LongMath)</a><br />
91
- <a href="classes/LongMath.html#M000134">log2 (LongMath)</a><br />
92
- <a href="classes/LongMath.html#M000135">log_internal (LongMath)</a><br />
91
+ <a href="classes/LongMath.html#M000133">log (LongMath)</a><br />
92
+ <a href="classes/LongMath.html#M000134">log10 (LongMath)</a><br />
93
+ <a href="classes/LongMath.html#M000135">log2 (LongMath)</a><br />
94
+ <a href="classes/LongMath.html#M000136">log_internal (LongMath)</a><br />
95
+ <a href="classes/LongMath.html#M000137">log_raw (LongMath)</a><br />
93
96
  <a href="classes/LongMath.html#M000119">merge_from_words (LongMath)</a><br />
94
97
  <a href="classes/LongDecimal.html#M000039">minus_one! (LongDecimal)</a><br />
95
98
  <a href="classes/LongDecimal.html#M000081">move_point_left (LongDecimal)</a><br />
@@ -97,23 +100,24 @@
97
100
  <a href="classes/LongDecimal.html#M000082">move_point_right (LongDecimal)</a><br />
98
101
  <a href="classes/LongDecimal.html#M000084">move_point_right_int (LongDecimal)</a><br />
99
102
  <a href="classes/LongMath.html#M000125">multiplicity_of_factor (LongMath)</a><br />
100
- <a href="classes/LongDecimal.html#M000041">new (LongDecimal)</a><br />
101
103
  <a href="classes/LongDecimalQuot.html#M000004">new (LongDecimalQuot)</a><br />
104
+ <a href="classes/LongDecimal.html#M000041">new (LongDecimal)</a><br />
102
105
  <a href="classes/LongDecimalQuot.html#M000003">new! (LongDecimalQuot)</a><br />
103
106
  <a href="classes/LongDecimal.html#M000034">new! (LongDecimal)</a><br />
104
107
  <a href="classes/LongDecimal.html#M000057">next (LongDecimal)</a><br />
105
108
  <a href="classes/LongDecimalQuot.html#M000005">numerator (LongDecimalQuot)</a><br />
106
109
  <a href="classes/LongDecimal.html#M000036">one! (LongDecimal)</a><br />
107
- <a href="classes/LongDecimal.html#M000097">one? (LongDecimal)</a><br />
108
110
  <a href="classes/LongDecimalQuot.html#M000027">one? (LongDecimalQuot)</a><br />
109
- <a href="classes/LongMath.html#M000136">power (LongMath)</a><br />
110
- <a href="classes/LongMath.html#M000137">power_internal (LongMath)</a><br />
111
+ <a href="classes/LongDecimal.html#M000097">one? (LongDecimal)</a><br />
112
+ <a href="classes/LongMath.html#M000126">pi (LongMath)</a><br />
113
+ <a href="classes/LongMath.html#M000138">power (LongMath)</a><br />
114
+ <a href="classes/LongMath.html#M000139">power_internal (LongMath)</a><br />
111
115
  <a href="classes/LongDecimal.html#M000040">power_of_ten! (LongDecimal)</a><br />
112
116
  <a href="classes/LongDecimal.html#M000058">pred (LongDecimal)</a><br />
113
117
  <a href="classes/LongDecimal.html#M000068">rdiv (LongDecimal)</a><br />
114
118
  <a href="classes/LongDecimalBase.html#M000107">reciprocal (LongDecimalBase)</a><br />
115
- <a href="classes/LongDecimalQuot.html#M000023">round_to_scale (LongDecimalQuot)</a><br />
116
119
  <a href="classes/LongDecimal.html#M000043">round_to_scale (LongDecimal)</a><br />
120
+ <a href="classes/LongDecimalQuot.html#M000023">round_to_scale (LongDecimalQuot)</a><br />
117
121
  <a href="classes/LongDecimal.html#M000042">scale= (LongDecimal)</a><br />
118
122
  <a href="classes/LongDecimalBase.html#M000112">scale_equal (LongDecimalBase)</a><br />
119
123
  <a href="classes/LongDecimalBase.html#M000111">scale_ufo (LongDecimalBase)</a><br />
@@ -121,12 +125,12 @@
121
125
  <a href="classes/LongDecimalQuot.html#M000029">sgn (LongDecimalQuot)</a><br />
122
126
  <a href="classes/LongDecimalQuot.html#M000031">sign (LongDecimalQuot)</a><br />
123
127
  <a href="classes/LongDecimal.html#M000093">sign (LongDecimal)</a><br />
124
- <a href="classes/LongDecimal.html#M000092">signum (LongDecimal)</a><br />
125
128
  <a href="classes/LongDecimalQuot.html#M000030">signum (LongDecimalQuot)</a><br />
129
+ <a href="classes/LongDecimal.html#M000092">signum (LongDecimal)</a><br />
126
130
  <a href="classes/LongDecimal.html#M000080">size (LongDecimal)</a><br />
127
131
  <a href="classes/LongMath.html#M000118">split_to_words (LongMath)</a><br />
132
+ <a href="classes/LongMath.html#M000132">sqrt (LongMath)</a><br />
128
133
  <a href="classes/LongDecimal.html#M000086">sqrt (LongDecimal)</a><br />
129
- <a href="classes/LongMath.html#M000131">sqrt (LongMath)</a><br />
130
134
  <a href="classes/LongDecimal.html#M000087">sqrt_with_remainder (LongDecimal)</a><br />
131
135
  <a href="classes/LongMath.html#M000120">sqrtb (LongMath)</a><br />
132
136
  <a href="classes/LongMath.html#M000121">sqrtb_with_remainder (LongMath)</a><br />
@@ -136,15 +140,15 @@
136
140
  <a href="classes/LongDecimalBase.html#M000106">square (LongDecimalBase)</a><br />
137
141
  <a href="classes/LongDecimal.html#M000056">succ (LongDecimal)</a><br />
138
142
  <a href="classes/LongDecimal.html#M000038">ten! (LongDecimal)</a><br />
139
- <a href="classes/LongDecimalQuot.html#M000009">to_bd (LongDecimalQuot)</a><br />
140
143
  <a href="classes/LongDecimal.html#M000050">to_bd (LongDecimal)</a><br />
144
+ <a href="classes/LongDecimalQuot.html#M000009">to_bd (LongDecimalQuot)</a><br />
141
145
  <a href="classes/LongDecimalQuot.html#M000008">to_f (LongDecimalQuot)</a><br />
142
146
  <a href="classes/LongDecimal.html#M000047">to_f (LongDecimal)</a><br />
143
147
  <a href="classes/LongDecimal.html#M000048">to_i (LongDecimal)</a><br />
144
148
  <a href="classes/LongDecimalQuot.html#M000010">to_i (LongDecimalQuot)</a><br />
145
- <a href="classes/LongDecimalQuot.html#M000011">to_ld (LongDecimalQuot)</a><br />
146
149
  <a href="classes/Numeric.html#M000100">to_ld (Numeric)</a><br />
147
150
  <a href="classes/LongDecimal.html#M000049">to_ld (LongDecimal)</a><br />
151
+ <a href="classes/LongDecimalQuot.html#M000011">to_ld (LongDecimalQuot)</a><br />
148
152
  <a href="classes/Rational.html#M000101">to_ld (Rational)</a><br />
149
153
  <a href="classes/LongDecimalBase.html#M000102">to_r (LongDecimalBase)</a><br />
150
154
  <a href="classes/LongDecimal.html#M000044">to_s (LongDecimal)</a><br />
data/lib/long-decimal.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  #
2
2
  # long-decimal.rb -- Arbitrary precision decimals with fixed decimal point
3
3
  #
4
- # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/lib/long-decimal.rb,v 1.18 2006/03/30 21:06:43 bk1 Exp $
5
- # CVS-Label: $Name: PRE_ALPHA_0_18 $
4
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/lib/long-decimal.rb,v 1.19 2006/04/01 08:52:06 bk1 Exp $
5
+ # CVS-Label: $Name: PRE_ALPHA_0_19 $
6
6
  # Author: $Author: bk1 $ (Karl Brodowsky)
7
7
  #
8
8
  require "complex"
@@ -36,6 +36,11 @@ module LongDecimalRoundingMode
36
36
  self.num <=> o
37
37
  end
38
38
  end
39
+
40
+ def hash
41
+ num
42
+ end
43
+
39
44
  end
40
45
 
41
46
  #
@@ -56,7 +61,7 @@ end # LongDecimalRoundingMode
56
61
  # common base class for LongDecimal and LongDecimalQuot
57
62
  #
58
63
  class LongDecimalBase < Numeric
59
- @RCS_ID='-$Id: long-decimal.rb,v 1.18 2006/03/30 21:06:43 bk1 Exp $-'
64
+ @RCS_ID='-$Id: long-decimal.rb,v 1.19 2006/04/01 08:52:06 bk1 Exp $-'
60
65
 
61
66
  include LongDecimalRoundingMode
62
67
 
@@ -159,7 +164,7 @@ end # class LongDecimalBase
159
164
  # digits and the other one the position of the decimal point.
160
165
  #
161
166
  class LongDecimal < LongDecimalBase
162
- @RCS_ID='-$Id: long-decimal.rb,v 1.18 2006/03/30 21:06:43 bk1 Exp $-'
167
+ @RCS_ID='-$Id: long-decimal.rb,v 1.19 2006/04/01 08:52:06 bk1 Exp $-'
163
168
 
164
169
  # MINUS_ONE = LongDecimal(-1)
165
170
  # ZERO = LongDecimal(0)
@@ -1203,7 +1208,7 @@ end # LongDecimal
1203
1208
  #
1204
1209
  class LongDecimalQuot < LongDecimalBase
1205
1210
 
1206
- @RCS_ID='-$Id: long-decimal.rb,v 1.18 2006/03/30 21:06:43 bk1 Exp $-'
1211
+ @RCS_ID='-$Id: long-decimal.rb,v 1.19 2006/04/01 08:52:06 bk1 Exp $-'
1207
1212
 
1208
1213
  #
1209
1214
  # constructor
@@ -1737,6 +1742,100 @@ module LongMath
1737
1742
  LOG2 = Math.log(2.0)
1738
1743
  LOG10 = Math.log(10.0)
1739
1744
 
1745
+ @@cache = {}
1746
+
1747
+ CacheKey = Struct.new(:fname, :arg, :mode)
1748
+
1749
+ #
1750
+ # used as key to store an already calculated value for any triplet
1751
+ # of function name (fname), argument (arg, typically 2, 3, 5, 10 or
1752
+ # so) and internal rounding mode (mode)
1753
+ #
1754
+ class CacheKey
1755
+ include Comparable
1756
+
1757
+ #
1758
+ # introduce some ordering for rounding modes
1759
+ #
1760
+ def <=>(o)
1761
+ r = 0
1762
+ if o.respond_to?:fname
1763
+ r = self.fname <=> o.fname
1764
+ else
1765
+ r = self.fname <=> o
1766
+ end
1767
+ return r if (r != 0)
1768
+ if o.respond_to?:arg
1769
+ r = self.arg <=> o.arg
1770
+ else
1771
+ r = self.arg <=> o
1772
+ end
1773
+ return r if (r != 0)
1774
+ if o.respond_to?:mode
1775
+ r = self.mode <=> o.mode
1776
+ else
1777
+ r = self.mode <=> o
1778
+ end
1779
+ return r
1780
+ end
1781
+
1782
+ end
1783
+
1784
+ private
1785
+
1786
+ #
1787
+ # check if arg is allowed for caching
1788
+ # if true, return key for caching
1789
+ # else return nil
1790
+ #
1791
+ def LongMath.get_cache_key(fname, arg, mode, allowed_args)
1792
+ key = nil
1793
+ if (arg.kind_of? Integer) || (arg.kind_of? LongDecimalBase) && arg.is_int? then
1794
+ arg = arg.to_i
1795
+ unless (allowed_args.index(arg).nil?)
1796
+ key = CacheKey.new(fname, arg, mode)
1797
+ end
1798
+ end
1799
+ return key
1800
+ end
1801
+
1802
+ #
1803
+ # get a cached value, if available in the required precision
1804
+ #
1805
+ def LongMath.get_cached(key, arg, iprec)
1806
+
1807
+ val = nil
1808
+ if key.nil? then
1809
+ return nil
1810
+ end
1811
+ val = @@cache[key]
1812
+ if val.nil? || val.scale < iprec then
1813
+ return nil
1814
+ end
1815
+ return val
1816
+ end
1817
+
1818
+ #
1819
+ # store new value in cache, if it provides an improvement of
1820
+ # precision
1821
+ #
1822
+ def LongMath.set_cached(key, val)
1823
+ unless key.nil? || val.nil?
1824
+ oval = @@cache[key]
1825
+ # puts("set key=#{key}\noval=#{oval}\nval=#{val}\n")
1826
+ unless (oval.nil?)
1827
+ raise TypeError, "must be LongDecimal" unless (val.kind_of? LongDecimal) && (oval.kind_of? LongDecimal)
1828
+ r = val.scale_ufo(oval)
1829
+ if (r <= 0)
1830
+ return
1831
+ end
1832
+ end
1833
+ @@cache[key] = val
1834
+ end
1835
+ end
1836
+
1837
+ public
1838
+
1740
1839
  #
1741
1840
  # helper method for internal use: checks if word_len is a reasonable
1742
1841
  # size for splitting a number into parts
@@ -2026,37 +2125,60 @@ module LongMath
2026
2125
  # Since calculation of pi is not what should typically be done with
2027
2126
  # LongDecimal, you may consider this method to be the easter egg of
2028
2127
  # LongDecimal. ;-)
2128
+ # parameters
2129
+ # prec precision of the end result
2130
+ # final_mode rounding mode to be used when creating the end result
2131
+ # iprec precision used internally
2132
+ # mode rounding_mode used internally
2133
+ # cache_result should the result be cached? Set to false, if an
2134
+ # extraordinary long result is really needed only once
2029
2135
  #
2030
- def LongMath.calc_pi(prec, final_mode = LongDecimal::ROUND_HALF_DOWN)
2031
- mode = LongDecimal::ROUND_HALF_DOWN
2032
- iprec = 5*(prec+1)
2033
- sprec = (iprec >> 1) + 1
2034
- dprec = (prec+1) << 1
2136
+ def LongMath.pi(prec, final_mode = LongDecimal::ROUND_HALF_DOWN, iprec = nil, mode = nil, cache_result = true)
2035
2137
 
2036
- a = LongDecimal(1)
2037
- b = (1 / LongDecimal(2).sqrt(iprec,mode)).round_to_scale(iprec, mode)
2038
- c = LongDecimal(5,1)
2039
- k = 1
2040
- pow_k = 2
2138
+ check_is_prec(prec, "prec")
2139
+ if (mode.nil?)
2140
+ mode = LongDecimal::ROUND_HALF_DOWN
2141
+ end
2142
+ check_is_mode(final_mode, "final_mode")
2143
+ check_is_mode(mode, "mode")
2041
2144
 
2042
- pi = 0
2043
- last_pi = 0
2044
- last_diff = 1
2145
+ if (iprec.nil?)
2146
+ iprec = 5*(prec+1)
2147
+ end
2148
+ check_is_prec(iprec, "iprec")
2149
+ sprec = (iprec >> 1) + 1
2150
+ dprec = (prec+1) << 1
2045
2151
 
2046
- loop do
2047
- a, b = ((a + b) / 2).round_to_scale(sprec, mode), (a * b).round_to_scale(iprec, mode).sqrt(sprec, mode)
2048
- c = (c - pow_k * (a * a - b * b)).round_to_scale(iprec, mode)
2049
- pi = (2 * a * a / c).round_to_scale(sprec, mode)
2050
- diff = (pi - last_pi).round_to_scale(dprec, mode).abs
2051
- if (diff.zero? && last_diff.zero?) then
2052
- break
2152
+ cache_key = get_cache_key("pi", 0, mode, [0])
2153
+ curr_pi = get_cached(cache_key, 0, sprec)
2154
+ if curr_pi.nil? then
2155
+
2156
+ a = LongDecimal(1)
2157
+ b = (1 / LongDecimal(2).sqrt(iprec,mode)).round_to_scale(iprec, mode)
2158
+ c = LongDecimal(5,1)
2159
+ k = 1
2160
+ pow_k = 2
2161
+
2162
+ curr_pi = 0
2163
+ last_pi = 0
2164
+ last_diff = 1
2165
+
2166
+ loop do
2167
+ a, b = ((a + b) / 2).round_to_scale(sprec, mode), (a * b).round_to_scale(iprec, mode).sqrt(sprec, mode)
2168
+ c = (c - pow_k * (a * a - b * b)).round_to_scale(iprec, mode)
2169
+ curr_pi = (2 * a * a / c).round_to_scale(sprec, mode)
2170
+ diff = (curr_pi - last_pi).round_to_scale(dprec, mode).abs
2171
+ if (diff.zero? && last_diff.zero?) then
2172
+ break
2173
+ end
2174
+ last_pi = curr_pi
2175
+ last_diff = diff
2176
+ k += 1
2177
+ pow_k = pow_k << 1
2053
2178
  end
2054
- last_pi = pi
2055
- last_diff = diff
2056
- k += 1
2057
- pow_k = pow_k << 1
2179
+ set_cached(cache_key, curr_pi) if cache_result
2058
2180
  end
2059
- pi.round_to_scale(prec, final_mode)
2181
+ curr_pi.round_to_scale(prec, final_mode)
2060
2182
  end
2061
2183
 
2062
2184
  #
@@ -2130,7 +2252,7 @@ module LongMath
2130
2252
  # create a bug report, if the default settings for the parameters do
2131
2253
  # not work correctly
2132
2254
  #
2133
- def LongMath.exp_internal(x, prec = nil, final_mode = LongDecimal::ROUND_HALF_DOWN, j = nil, k = nil, iprec = nil, mode = LongDecimal::ROUND_HALF_DOWN)
2255
+ def LongMath.exp_internal(x, prec = nil, final_mode = LongDecimal::ROUND_HALF_DOWN, j = nil, k = nil, iprec = nil, mode = LongDecimal::ROUND_HALF_DOWN, cache_result = true)
2134
2256
  # check_is_ld(x, "x")
2135
2257
  if (prec == nil) then
2136
2258
  if (x.kind_of? LongDecimalBase)
@@ -2178,7 +2300,27 @@ module LongMath
2178
2300
  iprec = calc_iprec_for_exp(x, prec)
2179
2301
  end
2180
2302
  check_is_prec(iprec, "iprec")
2303
+
2304
+ # we only cache exp(1)
2305
+ cache_key = get_cache_key("exp", x, mode, [1])
2306
+ y_k = get_cached(cache_key, x, iprec)
2307
+
2308
+ if (y_k.nil?) then
2309
+ y_k = exp_raw(x, prec, j, k, iprec, mode)
2310
+
2311
+ # keep result around for exp(1)
2312
+ set_cached(cache_key, y_k) if (cache_result)
2313
+ end
2314
+ y = y_k.round_to_scale(prec, final_mode)
2315
+ y
2181
2316
 
2317
+ end # exp_internal
2318
+
2319
+ #
2320
+ # calculation of exp(x) with precision used internally. Needs to be
2321
+ # rounded to be accurate to all digits that are provided.
2322
+ #
2323
+ def LongMath.exp_raw(x, prec, j, k, iprec, mode)
2182
2324
  # dprec = [ (iprec*0.9).round , (prec + 1) << 1 ].min
2183
2325
  dprec = [ (iprec*0.9).round, prec ].max
2184
2326
 
@@ -2194,9 +2336,9 @@ module LongMath
2194
2336
  f = 0
2195
2337
  loop do
2196
2338
  j.times do |i|
2197
- s[i] += t
2198
- f += 1
2199
- t = (t / f).round_to_scale(iprec, mode)
2339
+ s[i] += t
2340
+ f += 1
2341
+ t = (t / f).round_to_scale(iprec, mode)
2200
2342
  end
2201
2343
  t = (t * x_j).round_to_scale(iprec, mode)
2202
2344
  break if (t.zero?)
@@ -2210,17 +2352,16 @@ module LongMath
2210
2352
  y_k = LongDecimal(0)
2211
2353
  j.times do |i|
2212
2354
  if (i > 0) then
2213
- x_i = (x_i * x_k).round_to_scale(iprec, mode)
2355
+ x_i = (x_i * x_k).round_to_scale(iprec, mode)
2214
2356
  end
2215
2357
  y_k += (s[i] * x_i).round_to_scale(iprec, mode)
2216
2358
  end
2217
2359
  k.times do |i|
2218
2360
  y_k = y_k.square.round_to_scale(iprec, mode)
2219
2361
  end
2220
- y = y_k.round_to_scale(prec, final_mode)
2221
- y
2222
2362
 
2223
- end # exp_internal
2363
+ y_k
2364
+ end # exp_raw
2224
2365
 
2225
2366
  #
2226
2367
  # calculate approximation of sqrt of a LongDecimal.
@@ -2302,7 +2443,7 @@ module LongMath
2302
2443
  # create a bug report, if the default settings for the parameters do
2303
2444
  # not work correctly
2304
2445
  #
2305
- def LongMath.log_internal(x, prec = nil, final_mode = LongDecimal::ROUND_HALF_DOWN, iprec = nil, mode = LongDecimal::ROUND_HALF_DOWN)
2446
+ def LongMath.log_internal(x, prec = nil, final_mode = LongDecimal::ROUND_HALF_DOWN, iprec = nil, mode = LongDecimal::ROUND_HALF_DOWN, cache_result = true)
2306
2447
  # check_is_ld(x)
2307
2448
  raise TypeError, "x=#{x.inspect} must not be positive" unless x > 0
2308
2449
  if (prec == nil) then
@@ -2334,16 +2475,32 @@ module LongMath
2334
2475
  return LongDecimal.zero!(prec)
2335
2476
  end
2336
2477
 
2478
+ cache_key = get_cache_key("log", x, mode, [2, 3, 5, 10])
2479
+ y = get_cached(cache_key, x, iprec)
2480
+ if (y.nil?)
2481
+ y = log_raw(x, prec, iprec, mode)
2482
+ set_cached(cache_key, y) if cache_result
2483
+ end
2484
+
2485
+ return y.round_to_scale(prec, final_mode)
2486
+
2487
+ end # log_internal
2488
+
2489
+ #
2490
+ # calculate log with all digits used internally.
2491
+ # result needs to be rounded in order to ensure that all digits that
2492
+ # are provided are correct.
2493
+ #
2494
+ def LongMath.log_raw(x, prec, iprec, mode)
2495
+
2337
2496
  # dprec = [ iprec - 1, (prec + 1) << 1 ].min
2338
2497
  dprec = iprec - 1
2339
2498
 
2340
2499
  y = 0
2341
2500
  s = 1
2342
2501
  if (x < 1) then
2343
- # puts("x=#{x} iprec=#{iprec}\n")
2344
2502
  x = (1 / x).round_to_scale(iprec, mode)
2345
2503
  s = -1
2346
- # puts("s=#{s} x=#{x} iprec=#{iprec}\n")
2347
2504
  end
2348
2505
  exp_part = 0
2349
2506
  estimate = 0
@@ -2362,22 +2519,17 @@ module LongMath
2362
2519
 
2363
2520
  delta = LongDecimal(1, 3)
2364
2521
  while (x - 1).abs > delta do
2365
- # puts("too far from 1: x=#{x}\n")
2366
2522
  xf = x.to_f
2367
- # puts("xf=#{xf}\n")
2368
2523
  mlx = Math.log(xf)
2369
- # puts("log(xf)=#{mlx}\n")
2370
2524
  estimate = mlx.to_ld(20, mode)
2371
2525
  exp_part = exp(estimate, iprec << 1)
2372
- # puts("y=#{y} s=#{s} est=#{estimate} part=#{exp_part} x=#{x}\n")
2373
2526
  x = (x / exp_part).round_to_scale(iprec, mode)
2374
- # puts("divided by exp_part=#{exp_part}: #{x}\n")
2527
+
2375
2528
  if (s < 0) then
2376
2529
  y -= estimate
2377
2530
  else
2378
2531
  y += estimate
2379
2532
  end
2380
- # puts("y=#{y} s=#{s} est=#{estimate} part=#{exp_part} x=#{x}\n")
2381
2533
  end
2382
2534
 
2383
2535
  factor = 1
@@ -2398,15 +2550,11 @@ module LongMath
2398
2550
  i += 1
2399
2551
  sum += d
2400
2552
 
2401
- # puts("log_internal: s=#{sum} d=#{d} x=#{x} i=#{i} p=#{p} iprec=#{iprec} dprec=#{dprec}\n") if (i & 0x0f == 0x0f)
2402
2553
  end
2403
2554
 
2404
- # puts("y=#{y} s=#{s} f=#{factor} sum=#{sum}\n")
2405
2555
  y -= ((s * factor) * sum).round_to_scale(iprec, mode)
2406
- # puts("y=#{y} s=#{s} f=#{factor} sum=#{sum}\n")
2407
- return y.round_to_scale(prec, final_mode)
2408
-
2409
- end # log_internal
2556
+ return y
2557
+ end
2410
2558
 
2411
2559
  #
2412
2560
  # calc the power of x with exponent y to the given precision as