long-decimal 0.00.13 → 0.00.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/README +16 -10
  2. data/VERSION +1 -1
  3. data/doc/classes/LongMath.src/M000019.html +2 -2
  4. data/doc/classes/LongMath.src/M000020.html +2 -1
  5. data/doc/classes/LongMath.src/M000021.html +1 -1
  6. data/doc/classes/LongMath.src/M000022.html +1 -1
  7. data/doc/classes/LongMath.src/M000023.html +1 -1
  8. data/doc/classes/LongMath.src/M000024.html +1 -1
  9. data/doc/classes/LongMath.src/M000025.html +1 -1
  10. data/doc/classes/LongMath/LongDecimal.src/M000060.html +1 -1
  11. data/doc/classes/LongMath/LongDecimal.src/M000061.html +1 -1
  12. data/doc/classes/LongMath/LongDecimal.src/M000062.html +2 -2
  13. data/doc/classes/LongMath/LongDecimal.src/M000063.html +1 -1
  14. data/doc/classes/LongMath/LongDecimal.src/M000064.html +1 -1
  15. data/doc/classes/LongMath/LongDecimal.src/M000065.html +1 -1
  16. data/doc/classes/LongMath/LongDecimal.src/M000066.html +1 -1
  17. data/doc/classes/LongMath/LongDecimal.src/M000067.html +1 -1
  18. data/doc/classes/LongMath/LongDecimal.src/M000068.html +1 -1
  19. data/doc/classes/LongMath/LongDecimal.src/M000069.html +1 -1
  20. data/doc/classes/LongMath/LongDecimal.src/M000070.html +3 -3
  21. data/doc/classes/LongMath/LongDecimal.src/M000071.html +1 -1
  22. data/doc/classes/LongMath/LongDecimal.src/M000072.html +1 -1
  23. data/doc/classes/LongMath/LongDecimal.src/M000073.html +1 -1
  24. data/doc/classes/LongMath/LongDecimal.src/M000074.html +1 -1
  25. data/doc/classes/LongMath/LongDecimal.src/M000075.html +1 -1
  26. data/doc/classes/LongMath/LongDecimal.src/M000076.html +1 -1
  27. data/doc/classes/LongMath/LongDecimal.src/M000077.html +1 -1
  28. data/doc/classes/LongMath/LongDecimal.src/M000078.html +1 -1
  29. data/doc/classes/LongMath/LongDecimal.src/M000079.html +2 -2
  30. data/doc/classes/LongMath/LongDecimal.src/M000080.html +2 -2
  31. data/doc/classes/LongMath/LongDecimal.src/M000081.html +1 -1
  32. data/doc/classes/LongMath/LongDecimal.src/M000082.html +1 -1
  33. data/doc/classes/LongMath/LongDecimal.src/M000083.html +1 -1
  34. data/doc/classes/LongMath/LongDecimal.src/M000085.html +1 -1
  35. data/doc/classes/LongMath/LongDecimal.src/M000086.html +1 -1
  36. data/doc/classes/LongMath/LongDecimal.src/M000087.html +1 -1
  37. data/doc/classes/LongMath/LongDecimal.src/M000088.html +1 -1
  38. data/doc/classes/LongMath/LongDecimal.src/M000089.html +1 -1
  39. data/doc/classes/LongMath/LongDecimal.src/M000090.html +1 -1
  40. data/doc/classes/LongMath/LongDecimal.src/M000091.html +1 -1
  41. data/doc/classes/LongMath/LongDecimal.src/M000092.html +1 -1
  42. data/doc/classes/LongMath/LongDecimal.src/M000093.html +1 -1
  43. data/doc/classes/LongMath/LongDecimal.src/M000094.html +1 -1
  44. data/doc/classes/LongMath/LongDecimal.src/M000095.html +1 -1
  45. data/doc/classes/LongMath/LongDecimal.src/M000096.html +1 -1
  46. data/doc/classes/LongMath/LongDecimal.src/M000097.html +1 -1
  47. data/doc/classes/LongMath/LongDecimal.src/M000098.html +1 -1
  48. data/doc/classes/LongMath/LongDecimal.src/M000099.html +1 -1
  49. data/doc/classes/LongMath/LongDecimal.src/M000100.html +1 -1
  50. data/doc/classes/LongMath/LongDecimal.src/M000101.html +1 -1
  51. data/doc/classes/LongMath/LongDecimal.src/M000102.html +1 -1
  52. data/doc/classes/LongMath/LongDecimal.src/M000103.html +1 -1
  53. data/doc/classes/LongMath/LongDecimal.src/M000104.html +1 -1
  54. data/doc/classes/LongMath/LongDecimal.src/M000105.html +1 -1
  55. data/doc/classes/LongMath/LongDecimal.src/M000106.html +1 -1
  56. data/doc/classes/LongMath/LongDecimal.src/M000107.html +1 -1
  57. data/doc/classes/LongMath/LongDecimal.src/M000108.html +1 -1
  58. data/doc/classes/LongMath/LongDecimal.src/M000109.html +1 -1
  59. data/doc/classes/LongMath/LongDecimal.src/M000110.html +1 -1
  60. data/doc/classes/LongMath/LongDecimal.src/M000111.html +1 -1
  61. data/doc/classes/LongMath/LongDecimal.src/M000112.html +1 -1
  62. data/doc/classes/LongMath/LongDecimal.src/M000113.html +1 -1
  63. data/doc/classes/LongMath/LongDecimal.src/M000114.html +1 -1
  64. data/doc/classes/LongMath/LongDecimal.src/M000115.html +1 -1
  65. data/doc/classes/LongMath/LongDecimal.src/M000116.html +1 -1
  66. data/doc/classes/LongMath/LongDecimal.src/M000117.html +1 -1
  67. data/doc/classes/LongMath/LongDecimal.src/M000119.html +1 -1
  68. data/doc/classes/LongMath/LongDecimal.src/M000121.html +1 -1
  69. data/doc/classes/LongMath/LongDecimal.src/M000122.html +1 -1
  70. data/doc/classes/LongMath/LongDecimal.src/M000123.html +1 -1
  71. data/doc/classes/LongMath/LongDecimal.src/M000124.html +1 -1
  72. data/doc/classes/LongMath/LongDecimal.src/M000125.html +1 -1
  73. data/doc/classes/LongMath/LongDecimal.src/M000126.html +1 -1
  74. data/doc/classes/LongMath/LongDecimal.src/M000129.html +1 -1
  75. data/doc/classes/LongMath/LongDecimal.src/M000130.html +1 -1
  76. data/doc/classes/LongMath/LongDecimal.src/M000131.html +1 -1
  77. data/doc/classes/LongMath/LongDecimal.src/M000132.html +1 -1
  78. data/doc/classes/LongMath/LongDecimal.src/M000133.html +1 -1
  79. data/doc/classes/LongMath/LongDecimalQuot.src/M000026.html +1 -1
  80. data/doc/classes/LongMath/LongDecimalQuot.src/M000027.html +1 -1
  81. data/doc/classes/LongMath/LongDecimalQuot.src/M000028.html +1 -1
  82. data/doc/classes/LongMath/LongDecimalQuot.src/M000029.html +1 -1
  83. data/doc/classes/LongMath/LongDecimalQuot.src/M000030.html +1 -1
  84. data/doc/classes/LongMath/LongDecimalQuot.src/M000031.html +1 -1
  85. data/doc/classes/LongMath/LongDecimalQuot.src/M000032.html +1 -1
  86. data/doc/classes/LongMath/LongDecimalQuot.src/M000033.html +1 -1
  87. data/doc/classes/LongMath/LongDecimalQuot.src/M000034.html +1 -1
  88. data/doc/classes/LongMath/LongDecimalQuot.src/M000035.html +1 -1
  89. data/doc/classes/LongMath/LongDecimalQuot.src/M000036.html +1 -1
  90. data/doc/classes/LongMath/LongDecimalQuot.src/M000037.html +1 -1
  91. data/doc/classes/LongMath/LongDecimalQuot.src/M000038.html +1 -1
  92. data/doc/classes/LongMath/LongDecimalQuot.src/M000039.html +1 -1
  93. data/doc/classes/LongMath/LongDecimalQuot.src/M000040.html +1 -1
  94. data/doc/classes/LongMath/LongDecimalQuot.src/M000041.html +1 -1
  95. data/doc/classes/LongMath/LongDecimalQuot.src/M000042.html +1 -1
  96. data/doc/classes/LongMath/LongDecimalQuot.src/M000043.html +1 -1
  97. data/doc/classes/LongMath/LongDecimalQuot.src/M000044.html +1 -1
  98. data/doc/classes/LongMath/LongDecimalQuot.src/M000045.html +1 -1
  99. data/doc/classes/LongMath/LongDecimalQuot.src/M000046.html +1 -1
  100. data/doc/classes/LongMath/LongDecimalQuot.src/M000047.html +1 -1
  101. data/doc/classes/LongMath/LongDecimalQuot.src/M000048.html +1 -1
  102. data/doc/classes/LongMath/LongDecimalQuot.src/M000049.html +1 -1
  103. data/doc/classes/LongMath/LongDecimalQuot.src/M000050.html +1 -1
  104. data/doc/classes/LongMath/LongDecimalQuot.src/M000051.html +1 -1
  105. data/doc/classes/LongMath/LongDecimalQuot.src/M000052.html +1 -1
  106. data/doc/classes/LongMath/LongDecimalQuot.src/M000053.html +1 -1
  107. data/doc/classes/LongMath/LongDecimalQuot.src/M000054.html +1 -1
  108. data/doc/classes/LongMath/LongDecimalQuot.src/M000055.html +1 -1
  109. data/doc/classes/LongMath/LongDecimalQuot.src/M000058.html +1 -1
  110. data/doc/classes/LongMath/LongDecimalQuot.src/M000059.html +1 -1
  111. data/doc/classes/LongMath/Numeric.src/M000134.html +1 -1
  112. data/doc/created.rid +1 -1
  113. data/doc/files/lib/long-decimal_rb.html +2 -2
  114. data/lib/long-decimal.rb +14 -29
  115. data/test/testlongdecimal.rb +371 -15
  116. metadata +2 -3
  117. data/lib/longdecimal.rb +0 -2246
@@ -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 1891</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1876</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_r</span>
15
15
  <span class="ruby-constant">Rational</span>(<span class="ruby-identifier">numerator</span>, <span class="ruby-identifier">denominator</span>)
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 1898</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1883</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_f</span>
15
15
  <span class="ruby-identifier">to_r</span>.<span class="ruby-identifier">to_f</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 1905</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1890</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_i</span>
15
15
  <span class="ruby-identifier">to_r</span>.<span class="ruby-identifier">to_i</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 1912</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1897</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_ld</span>
15
15
  <span class="ruby-identifier">round_to_scale</span>(<span class="ruby-identifier">scale</span>, <span class="ruby-constant">ROUND_HALF_UP</span>)
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 1919</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1904</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">+@</span>
15
15
  <span class="ruby-keyword kw">self</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 1927</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1912</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">-@</span>
15
15
  <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">zero?</span> <span class="ruby-keyword kw">then</span>
16
16
  <span class="ruby-keyword kw">self</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 1941</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1926</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">+</span>(<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span> = <span class="ruby-identifier">coerce</span>(<span class="ruby-identifier">other</span>)
16
16
  <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">s</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimalQuot</span>) <span class="ruby-keyword kw">then</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 1950</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1935</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">-</span>(<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span> = <span class="ruby-identifier">coerce</span>(<span class="ruby-identifier">other</span>)
16
16
  <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">s</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimalQuot</span>) <span class="ruby-keyword kw">then</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 1959</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1944</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">*</span>(<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span> = <span class="ruby-identifier">coerce</span>(<span class="ruby-identifier">other</span>)
16
16
  <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">s</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimalQuot</span>) <span class="ruby-keyword kw">then</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 1968</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1953</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">/</span>(<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span> = <span class="ruby-identifier">coerce</span>(<span class="ruby-identifier">other</span>)
16
16
  <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">s</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimalQuot</span>) <span class="ruby-keyword kw">then</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 1977</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1962</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">**</span>(<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimal</span>) <span class="ruby-operator">||</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimalQuot</span>) <span class="ruby-keyword kw">then</span>
16
16
  <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">is_int?</span> <span class="ruby-keyword kw">then</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 1998</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1983</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">divmod</span>(<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Complex</span>) <span class="ruby-keyword kw">then</span>
16
16
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;divmod not supported for Complex&quot;</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 2006</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1991</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">%</span>(<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-identifier">q</span>, <span class="ruby-identifier">r</span> = <span class="ruby-identifier">divmod</span> <span class="ruby-identifier">other</span>
16
16
  <span class="ruby-identifier">r</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 2020</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2005</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">square</span>
15
15
  <span class="ruby-keyword kw">self</span> <span class="ruby-operator">*</span> <span class="ruby-keyword kw">self</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 2027</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2012</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reciprocal</span>
15
15
  <span class="ruby-value">1</span> <span class="ruby-operator">/</span> <span class="ruby-keyword kw">self</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 2034</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2019</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">abs</span>
15
15
  <span class="ruby-constant">LongDecimalQuot</span>(<span class="ruby-identifier">rat</span>.<span class="ruby-identifier">abs</span>, <span class="ruby-identifier">scale</span>)
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 2038</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2023</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">abs2</span>
15
15
  <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">abs</span>.<span class="ruby-identifier">square</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 2046</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2031</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">round_to_scale</span>(<span class="ruby-identifier">new_scale</span> = <span class="ruby-ivar">@scale</span>, <span class="ruby-identifier">mode</span> = <span class="ruby-constant">ROUND_UNNECESSARY</span>)
15
15
 
16
16
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;new_scale #{new_scale.inspect} must be integer&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">new_scale</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Integer</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 2118</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2103</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">coerce</span>(<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">other</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-keyword kw">return</span> <span class="ruby-constant">LongDecimalQuot</span>(<span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_r</span>, <span class="ruby-identifier">other</span>.<span class="ruby-identifier">scale</span>), <span class="ruby-keyword kw">self</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 2150</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2135</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">==</span>(<span class="ruby-identifier">other</span>)
15
15
  (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimalQuot</span>) <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-keyword kw">self</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">other</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scale</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">scale</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 2157</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2142</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">&lt;=&gt;</span> (<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-identifier">diff</span> = (<span class="ruby-keyword kw">self</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">other</span>)
16
16
  <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">diff</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimal</span>) <span class="ruby-operator">||</span> (<span class="ruby-identifier">diff</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimalQuot</span>) <span class="ruby-keyword kw">then</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 2169</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2154</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scale_ufo</span>(<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;only works for LongDecimal and LongDecimalQuot&quot;</span> <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimal</span>) <span class="ruby-operator">||</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimalQuot</span>)
16
16
  <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scale</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">scale</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 2177</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2162</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scale_equal</span>(<span class="ruby-identifier">other</span>)
15
15
  <span class="ruby-identifier">scale_ufo</span>(<span class="ruby-identifier">other</span>).<span class="ruby-identifier">zero?</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 2184</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2169</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_int?</span>
15
15
  <span class="ruby-identifier">denominator</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 2191</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2176</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sgn</span>
15
15
  <span class="ruby-identifier">numerator</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-value">0</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 2200</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2185</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hash</span>
15
15
  <span class="ruby-identifier">rat</span>.<span class="ruby-identifier">hash</span> <span class="ruby-operator">^</span> <span class="ruby-identifier">scale</span>.<span class="ruby-identifier">hash</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 2208</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2193</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>
15
15
  <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;LongDecimalQuot(Rational(%s, %s), %s)&quot;</span>, <span class="ruby-identifier">numerator</span>.<span class="ruby-identifier">inspect</span>, <span class="ruby-identifier">denominator</span>.<span class="ruby-identifier">inspect</span>, <span class="ruby-identifier">scale</span>.<span class="ruby-identifier">inspect</span>)
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -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 2240</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 2225</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_ld</span>
15
15
  <span class="ruby-constant">LongDecimal</span>(<span class="ruby-keyword kw">self</span>)
16
16
  <span class="ruby-keyword kw">end</span></pre>
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Sat Mar 18 10:59:14 CET 2006
1
+ Sun Mar 19 12:51:33 CET 2006
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sat Mar 18 09:34:28 CET 2006</td>
59
+ <td>Sun Mar 19 12:47:57 CET 2006</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -87,7 +87,7 @@ point
87
87
  </p>
88
88
  <p>
89
89
  CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/lib/long-decimal.rb,v
90
- 1.1 2006/03/18 08:34:28 bk1 Exp $ CVS-Label: $Name: PRE_ALPHA_0_13 $
90
+ 1.2 2006/03/19 11:17:55 bk1 Exp $ CVS-Label: $Name: PRE_ALPHA_0_14 $
91
91
  Author: $Author: bk1 $ (Karl Brodowsky)
92
92
  </p>
93
93
 
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.1 2006/03/18 08:34:28 bk1 Exp $
5
- # CVS-Label: $Name: PRE_ALPHA_0_13 $
4
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/lib/long-decimal.rb,v 1.2 2006/03/19 11:17:55 bk1 Exp $
5
+ # CVS-Label: $Name: PRE_ALPHA_0_14 $
6
6
  # Author: $Author: bk1 $ (Karl Brodowsky)
7
7
  #
8
8
  require "complex"
@@ -467,7 +467,7 @@ module LongMath
467
467
  k = (s1 + Math.log([1, prec].max) / LOG2).round
468
468
  end
469
469
  if (x > 1) then
470
- k += (Math.log(x.to_f) / LOG2).abs.round
470
+ k += (Math.log(x.to_f) / LOG2).abs.round
471
471
  end
472
472
  end
473
473
  if (j <= 0) then
@@ -553,8 +553,8 @@ module LongMath
553
553
  # puts("x=#{x} xx=#{xx} id=#{id} iprec=#{iprec}\n")
554
554
  lnxx = log_internal(xx, iprec, mode)
555
555
  ln10 = log_internal(10.to_ld, iprec, mode)
556
- y = id + (lnxx / ln10).to_ld
557
- return y.round_to_scale(prec, mode)
556
+ y = id + (lnxx / ln10).round_to_scale(prec, mode)
557
+ return y
558
558
  end
559
559
 
560
560
  #
@@ -574,7 +574,8 @@ module LongMath
574
574
  # puts("x=#{x} xx=#{xx} id=#{id} iprec=#{iprec}\n")
575
575
  lnxx = log_internal(xx, iprec, mode)
576
576
  ln2 = log_internal(2.to_ld, iprec, mode)
577
- y = id + (lnxx / ln2).to_ld
577
+ y = id + (lnxx / ln2).round_to_scale(prec, mode)
578
+ return y
578
579
  end
579
580
 
580
581
  #
@@ -741,7 +742,7 @@ end # LongMath
741
742
  # digits and the other one the position of the decimal point.
742
743
  #
743
744
  class LongDecimal < Numeric
744
- @RCS_ID='-$Id: long-decimal.rb,v 1.1 2006/03/18 08:34:28 bk1 Exp $-'
745
+ @RCS_ID='-$Id: long-decimal.rb,v 1.2 2006/03/19 11:17:55 bk1 Exp $-'
745
746
 
746
747
  include LongDecimalRoundingMode
747
748
 
@@ -777,7 +778,7 @@ class LongDecimal < Numeric
777
778
  # digits after the decimal point (scale=s)
778
779
  #
779
780
  def LongDecimal.one!(s = 0)
780
- new(1, s)
781
+ new(10**s, s)
781
782
  end
782
783
 
783
784
 
@@ -923,22 +924,6 @@ class LongDecimal < Numeric
923
924
 
924
925
  attr_reader :int_val, :scale
925
926
 
926
- # #
927
- # # get the integer value of self, disregarding the decimal point.
928
- # # Mostly for internal use.
929
- # #
930
- # def int_val
931
- # @int_val
932
- # end
933
-
934
- # #
935
- # # get the scale, i.e. the position of the decimal point.
936
- # # Mostly for internal use.
937
- # #
938
- # def scale
939
- # @scale
940
- # end
941
-
942
927
  #
943
928
  # alter scale (changes self)
944
929
  #
@@ -1028,9 +1013,9 @@ class LongDecimal < Numeric
1028
1013
  raise TypeError, "base must be integer between 2 and 36"
1029
1014
  end
1030
1015
  quot = (self.move_point_right(scale) * base ** shown_scale) / 10 ** scale
1031
- p(quot)
1016
+ # p(quot)
1032
1017
  rounded = quot.round_to_scale(0, mode)
1033
- p(rounded)
1018
+ # p(rounded)
1034
1019
  rounded.to_s_internal(base, shown_scale)
1035
1020
  end
1036
1021
  end
@@ -1161,7 +1146,7 @@ class LongDecimal < Numeric
1161
1146
  # ...
1162
1147
  #
1163
1148
  def int_digits2
1164
- int_part = self.to_i.abs
1149
+ int_part = self.abs.to_i
1165
1150
  if int_part.zero? then
1166
1151
  return 0
1167
1152
  end
@@ -1184,7 +1169,7 @@ class LongDecimal < Numeric
1184
1169
  # ...
1185
1170
  #
1186
1171
  def int_digits10
1187
- int_part = self.to_i.abs
1172
+ int_part = self.abs.to_i
1188
1173
  if int_part.zero? then
1189
1174
  return 0
1190
1175
  end
@@ -1805,7 +1790,7 @@ end # LongDecimal
1805
1790
  #
1806
1791
  class LongDecimalQuot < Numeric
1807
1792
 
1808
- @RCS_ID='-$Id: long-decimal.rb,v 1.1 2006/03/18 08:34:28 bk1 Exp $-'
1793
+ @RCS_ID='-$Id: long-decimal.rb,v 1.2 2006/03/19 11:17:55 bk1 Exp $-'
1809
1794
 
1810
1795
  include LongDecimalRoundingMode
1811
1796
 
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # testlong-decimal.rb -- runit test for long-decimal.rb
3
+ # testlongdecimal.rb -- runit test for long-decimal.rb
4
4
  #
5
- # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal.rb,v 1.8 2006/03/18 08:32:02 bk1 Exp $
6
- # CVS-Label: $Name: PRE_ALPHA_0_13 $
5
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal.rb,v 1.9 2006/03/19 11:17:55 bk1 Exp $
6
+ # CVS-Label: $Name: PRE_ALPHA_0_14 $
7
7
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
8
  #
9
9
 
@@ -18,8 +18,11 @@ load "lib/long-decimal.rb"
18
18
  #
19
19
  class TestLongDecimal_class < RUNIT::TestCase
20
20
 
21
- @RCS_ID='-$Id: testlongdecimal.rb,v 1.8 2006/03/18 08:32:02 bk1 Exp $-'
21
+ @RCS_ID='-$Id: testlongdecimal.rb,v 1.9 2006/03/19 11:17:55 bk1 Exp $-'
22
22
 
23
+ #
24
+ # helper method for test_split_merge_words
25
+ #
23
26
  def check_split_merge_words(x, l, wl)
24
27
  w = LongMath.split_to_words(x, l)
25
28
  y = LongMath.merge_from_words(w, l)
@@ -114,7 +117,7 @@ class TestLongDecimal_class < RUNIT::TestCase
114
117
  check_exp_floated(-700, 10)
115
118
  check_exp_floated(xx, 10)
116
119
  check_exp_floated(-xx, 10)
117
-
120
+
118
121
  check_exp_floated(700, 100)
119
122
  check_exp_floated(100, 100)
120
123
  check_exp_floated(1, 100)
@@ -131,7 +134,7 @@ class TestLongDecimal_class < RUNIT::TestCase
131
134
 
132
135
  #
133
136
  # helper method for test_log
134
- # tests if exp(x) with precision prec is calculated correctly
137
+ # tests if log(x) with precision prec is calculated correctly
135
138
  #
136
139
  def check_log_floated(x, prec)
137
140
 
@@ -204,7 +207,7 @@ class TestLongDecimal_class < RUNIT::TestCase
204
207
  end
205
208
 
206
209
  #
207
- # helper method for test_exp
210
+ # helper method for test_lm_power
208
211
  # tests if LongMath::power(x, y, prec) with precision prec is calculated correctly
209
212
  #
210
213
  def check_power_floated(x, y, prec)
@@ -238,7 +241,7 @@ class TestLongDecimal_class < RUNIT::TestCase
238
241
  end
239
242
  l10y = 0
240
243
  if (y > 1) then
241
- l10y = (Math.log(y.to_f) / Math.log(10)).ceil
244
+ l10y = (Math.log(y.to_f) / Math.log(10)).ceil
242
245
  end
243
246
  u = LongMath.log(z, lprec)
244
247
  v = LongMath.log(x, lprec+l10y)
@@ -250,7 +253,7 @@ class TestLongDecimal_class < RUNIT::TestCase
250
253
  end
251
254
 
252
255
  #
253
- # test the calculation of the exponential function
256
+ # test the calculation of the power-function of LongMath
254
257
  #
255
258
  def test_lm_power
256
259
  check_power_floated(1, 1, 10)
@@ -263,7 +266,7 @@ class TestLongDecimal_class < RUNIT::TestCase
263
266
  end
264
267
 
265
268
  #
266
- # helper method for test_log
269
+ # helper method for test_log10
267
270
  # tests if log10(x) with precision prec is calculated correctly
268
271
  #
269
272
  def check_log10_floated(x, prec)
@@ -309,7 +312,7 @@ class TestLongDecimal_class < RUNIT::TestCase
309
312
  end
310
313
 
311
314
  #
312
- # helper method for test_log
315
+ # helper method for test_log10
313
316
  # tests if log10(x) with precision prec is calculated correctly
314
317
  #
315
318
  def check_log10_exact(x, log10x, prec)
@@ -324,7 +327,7 @@ class TestLongDecimal_class < RUNIT::TestCase
324
327
  end
325
328
 
326
329
  #
327
- # test the calculation of the logarithm function
330
+ # test the calculation of the base-10-logarithm function
328
331
  #
329
332
  def test_log10
330
333
  check_log10_floated(10**2000, 30)
@@ -342,6 +345,87 @@ class TestLongDecimal_class < RUNIT::TestCase
342
345
  check_log10_exact(10**10, 10, 30)
343
346
  end
344
347
 
348
+ #
349
+ # helper method for test_log2
350
+ # tests if log2(x) with precision prec is calculated correctly
351
+ #
352
+ def check_log2_floated(x, prec)
353
+
354
+ # make sure x is LongDecimal
355
+ x0 = x
356
+ x = x.to_ld
357
+ # calculate y = log2(x)
358
+ y = LongMath.log2(x, prec)
359
+
360
+ # compare y against z = log2(x) calculated using regular floating
361
+ # point arithmetic
362
+ if (x <= LongMath::MAX_FLOATABLE) then
363
+ xf = x.to_f
364
+ if (xf > 0) then
365
+ z = Math.log(x.to_f) / Math.log(2)
366
+ yf = y.to_f
367
+ assert((yf - z) / [yf.abs, z.abs, Float::MIN].max < 1e-9, "y=#{yf.to_s} and z=#{z.to_s} should be almost equal x=#{x}")
368
+ end
369
+ end
370
+
371
+ # check by taking 2**(log2(x))
372
+ # we have to take into account that we might not have enough
373
+ # significant digits, so we have to go down with the precision
374
+ if (y <= LongMath::MAX_EXP_ABLE) then
375
+ eprec = prec
376
+ if (y > 1) then
377
+ lx = 0
378
+ if (x > LongMath::MAX_FLOATABLE) then
379
+ puts("unusual x=#{x} y=#{y}\n")
380
+ lx = LongMath::MAX_EXP_ABLE
381
+ else
382
+ lx = Math.log(x.to_f)
383
+ end
384
+ l10 = (lx / Math.log(10)).ceil
385
+ eprec = [ eprec - l10, 0 ].max
386
+ end
387
+
388
+ z = LongMath.power(2.to_ld, y, eprec)
389
+ assert((x - z).abs <= z.unit, "x=#{x.to_s} and z=#{z.to_s} should be almost equal (y=#{y.to_s} eprec=#{eprec} prec=#{prec})")
390
+ end
391
+
392
+ end
393
+
394
+ #
395
+ # helper method for test_log2
396
+ # tests if log2(x) with precision prec is calculated correctly
397
+ #
398
+ def check_log2_exact(x, log2x, prec)
399
+
400
+ # make sure x is LongDecimal
401
+ x0 = x
402
+ x = x.to_ld
403
+ log2x = log2x.to_ld.round_to_scale(prec)
404
+ # calculate y = log2(x)
405
+ y = LongMath.log2(x, prec)
406
+ assert_equal(y, log2x, "log x should match exactly x=#{x} y=#{y} log2x=#{log2x} prec=#{prec}")
407
+ end
408
+
409
+ #
410
+ # test the calculation of the base-10-logarithm function
411
+ #
412
+ def test_log2
413
+ check_log2_floated(10**2000, 30)
414
+ check_log2_floated(2**2000, 30)
415
+ check_log2_floated(100, 30)
416
+ check_log2_floated(1, 30)
417
+ check_log2_floated(0.01, 30)
418
+ check_log2_floated(1e-10, 30)
419
+ check_log2_floated(1e-90, 30)
420
+ check_log2_floated(1e-300, 30)
421
+ check_log2_floated(LongDecimal(1, 2000), 30)
422
+
423
+ check_log2_exact(2**2000, 2000, 30)
424
+ check_log2_exact(2**0, 0, 30)
425
+ check_log2_exact(2**1, 1, 30)
426
+ check_log2_exact(2**10, 10, 30)
427
+ end
428
+
345
429
  #
346
430
  # helper method for test_sqrtb
347
431
  #
@@ -442,6 +526,118 @@ class TestLongDecimal_class < RUNIT::TestCase
442
526
  end
443
527
  end
444
528
 
529
+ #
530
+ # helper method for test_sqrtb_with_remainder
531
+ #
532
+ def check_sqrtb_with_remainder(x, s)
533
+ y, r = LongMath.sqrtb_with_remainder(x)
534
+ z0 = y * y
535
+ z1 = z0 + r
536
+ z2 = (y+1)*(y+1)
537
+ assert(0 <= y, "sqrt _with_remaindermust be >= 0" + s)
538
+ assert_equal(z1, x, "x=#{x} y=#{y} r=#{r} z0=#{z0} z1=#{z1} z2=#{z2}" + s)
539
+ assert(z0 <= x && x < z2, "y=#{y}=sqrt(_with_remainder#{x}) and x in [#{z0}, #{z2}) r=#{r} z0=#{z0} z1=#{z1} z2=#{z2}" + s)
540
+ y
541
+ end
542
+
543
+ #
544
+ # test method sqrtb_with_remainder for calculating sqrt _with_remainderof short integers
545
+ #
546
+ def test_sqrtb_with_remainder
547
+ 10.times do |x|
548
+ check_sqrtb_with_remainder(x, " loop x=#{x}")
549
+ end
550
+ 100.times do |i|
551
+ x = 10*i + 10
552
+ check_sqrtb_with_remainder(x, " loop x=#{x}")
553
+ end
554
+ 50.times do |j|
555
+ i = 10 * j
556
+ x1 = i * i
557
+ y = check_sqrtb_with_remainder(x1, " i*i i=#{i}")
558
+ assert_equal(i, y, "i=#{i} y=#{y}")
559
+ if (i > 0) then
560
+ x2 = x1 + 1
561
+ y = check_sqrtb_with_remainder(x2, " i*i+1 i=#{i}")
562
+ assert_equal(i, y, "i=#{i} y=#{y}")
563
+ x0 = x1 - 1
564
+ y = check_sqrtb_with_remainder(x0, " i*i-1 i=#{i}")
565
+ assert_equal(i-1, y, "i=#{i} y=#{y}")
566
+ end
567
+
568
+ x1 = 1 << i
569
+ y = check_sqrtb_with_remainder(x1, " 2**i i=#{i}")
570
+ if (i[0] == 0)
571
+ assert_equal(1 << (i>>1), y, "2^(i/2) i=#{i} y=#{y}")
572
+ end
573
+ if (i > 0) then
574
+ check_sqrtb_with_remainder(x1-1, " 2**i-1 i=#{i}")
575
+ check_sqrtb_with_remainder(x1+1, " 2**i+1 i=#{i}")
576
+ end
577
+
578
+ x1 = 3 << i
579
+ check_sqrtb_with_remainder(x1, " 3*2**i i=#{i}")
580
+ check_sqrtb_with_remainder(x1-1, " 3*2**i-1 i=#{i}")
581
+ check_sqrtb_with_remainder(x1+1, " 3*2**i+1 i=#{i}")
582
+ end
583
+ end
584
+
585
+ #
586
+ # helper method for test_sqrtw_with_remainder
587
+ #
588
+ def check_sqrtw_with_remainder(x, s)
589
+ y, r = LongMath.sqrtw_with_remainder(x)
590
+ z0 = y * y
591
+ z1 = z0 + r
592
+ z2 = (y+1)*(y+1)
593
+ assert(0 <= y, "sqrt _with_remaindermust be >= 0" + s)
594
+ assert_equal(z1, x, "x=#{x} y=#{y} r=#{r} z0=#{z0} z1=#{z1} z2=#{z2}" + s)
595
+ assert(z0 <= x && x < z2, "y=#{y}=sqrt(_with_remainder#{x}) and x in [#{z0}, #{z2}) r=#{r} z0=#{z0} z1=#{z1} z2=#{z2}" + s)
596
+ y
597
+ end
598
+
599
+ #
600
+ # test method sqrtb_with_remainder for calculating sqrt _with_remainderof long integers
601
+ #
602
+ def test_sqrtw_with_remainder
603
+ 10.times do |x|
604
+ check_sqrtw_with_remainder(x, " loop x=#{x}")
605
+ end
606
+ 100.times do |j|
607
+ x = 10 * j + 10
608
+ check_sqrtw_with_remainder(x, " loop x=#{x}")
609
+ end
610
+ 100.times do |j|
611
+ i = 10*j
612
+ x1 = i*i
613
+ y = check_sqrtw_with_remainder(x1, " i*i i=#{i}")
614
+ assert_equal(i, y, "i=#{i} y=#{y}")
615
+ if (i > 0) then
616
+ x2 = x1 + 1
617
+ y = check_sqrtw_with_remainder(x2, " i*i+1 i=#{i}")
618
+ assert_equal(i, y, "i=#{i} y=#{y}")
619
+ x0 = x1 - 1
620
+ y = check_sqrtw_with_remainder(x0, " i*i-1 i=#{i}")
621
+ assert_equal(i-1, y, "i=#{i} y=#{y}")
622
+ end
623
+
624
+ x1 = 1 << i
625
+ y = check_sqrtw_with_remainder(x1, " 2**i i=#{i}")
626
+ if (i[0] == 0)
627
+ assert_equal(1 << (i>>1), y, "2^(i/2) i=#{i} y=#{y}")
628
+ end
629
+ if (i > 0) then
630
+ check_sqrtw_with_remainder(x1-1, " 2**i-1 i=#{i}")
631
+ check_sqrtw_with_remainder(x1+1, " 2**i+1 i=#{i}")
632
+ end
633
+
634
+ x1 = 3 << i
635
+ check_sqrtw_with_remainder(x1, " 3*2**i i=#{i}")
636
+ check_sqrtw_with_remainder(x1-1, " 3*2**i-1 i=#{i}")
637
+ check_sqrtw_with_remainder(x1+1, " 3*2**i+1 i=#{i}")
638
+ end
639
+ end
640
+
445
641
  #
446
642
  # test gcd_with_high_power
447
643
  #
@@ -490,7 +686,7 @@ class TestLongDecimal_class < RUNIT::TestCase
490
686
  #
491
687
  # test multiplicity_of_factor for LongDecimal
492
688
  #
493
- def test_rat_multiplicity_of_factor
689
+ def test_ld_multiplicity_of_factor
494
690
  # 0.729
495
691
  n = LongDecimal(729, 3)
496
692
  assert_equal(-3, LongMath.multiplicity_of_factor(n, 2), "ny_2(n) is -3")
@@ -500,6 +696,62 @@ class TestLongDecimal_class < RUNIT::TestCase
500
696
  assert_equal(0, LongMath.multiplicity_of_factor(n, 11), "ny_11(n) is 0")
501
697
  end
502
698
 
699
+ #
700
+ # test creation of 0 with given number of digits after the decimal point
701
+ #
702
+ def test_zero_init
703
+ l = LongDecimal.zero!(224)
704
+ assert_equal(l.to_r, 0, "to_r")
705
+ assert_equal(l.scale, 224, "scale")
706
+ end
707
+
708
+ #
709
+ # test creation of 1 with given number of digits after the decimal point
710
+ #
711
+ def test_one_init
712
+ l = LongDecimal.one!(224)
713
+ assert_equal(l.to_r, 1, "to_r")
714
+ assert_equal(l.scale, 224, "scale")
715
+ end
716
+
717
+ #
718
+ # test creation of 2 with given number of digits after the decimal point
719
+ #
720
+ def test_two_init
721
+ l = LongDecimal.two!(224)
722
+ assert_equal(l.to_r, 2, "to_r")
723
+ assert_equal(l.scale, 224, "scale")
724
+ end
725
+
726
+ #
727
+ # test creation of 10 with given number of digits after the decimal point
728
+ #
729
+ def test_ten_init
730
+ l = LongDecimal.ten!(224)
731
+ assert_equal(l.to_r, 10, "to_r")
732
+ assert_equal(l.scale, 224, "scale")
733
+ end
734
+
735
+ #
736
+ # test creation of -1 with given number of digits after the decimal point
737
+ #
738
+ def test_minus_one_init
739
+ l = LongDecimal.minus_one!(224)
740
+ assert_equal(l.to_r, -1, "to_r")
741
+ assert_equal(l.scale, 224, "scale")
742
+ end
743
+
744
+ #
745
+ # test creation of 10**e with given number of digits after the decimal point
746
+ #
747
+ def test_power_of_ten_init
748
+ 20.times do |e|
749
+ l = LongDecimal.power_of_ten!(e, 224)
750
+ assert_equal(l.to_r, 10**e, "to_r e=#{e}")
751
+ assert_equal(l.scale, 224, "scale")
752
+ end
753
+ end
754
+
503
755
  #
504
756
  # test construction of LongDecimal from Integer
505
757
  #
@@ -558,6 +810,54 @@ class TestLongDecimal_class < RUNIT::TestCase
558
810
  assert_equal("0.000271", l.to_s, "l=#{l.inspect} b=#{b.inspect}")
559
811
  end
560
812
 
813
+ #
814
+ # test int_digits2 of LongDecimal
815
+ #
816
+ def test_int_digits2
817
+ assert_equal(0, LongDecimal("0.0000").int_digits2, "0.0000")
818
+ assert_equal(0, LongDecimal("0.9999").int_digits2, "0.9999")
819
+ assert_equal(1, LongDecimal("1.0000").int_digits2, "1.0000")
820
+ assert_equal(1, LongDecimal("1.9999").int_digits2, "1.9999")
821
+ assert_equal(2, LongDecimal("2.0000").int_digits2, "2.0000")
822
+ assert_equal(2, LongDecimal("3.9999").int_digits2, "3.9999")
823
+ assert_equal(3, LongDecimal("4.0000").int_digits2, "4.0000")
824
+ assert_equal(3, LongDecimal("7.9999").int_digits2, "7.9999")
825
+ assert_equal(4, LongDecimal("8.0000").int_digits2, "8.0000")
826
+ assert_equal(4, LongDecimal("15.9999").int_digits2, "15.9999")
827
+
828
+ assert_equal(0, LongDecimal("-0.0000").int_digits2, "-0.0000")
829
+ assert_equal(0, LongDecimal("-0.9999").int_digits2, "-0.9999")
830
+ assert_equal(1, LongDecimal("-1.0000").int_digits2, "-1.0000")
831
+ assert_equal(1, LongDecimal("-1.9999").int_digits2, "-1.9999")
832
+ assert_equal(2, LongDecimal("-2.0000").int_digits2, "-2.0000")
833
+ assert_equal(2, LongDecimal("-3.9999").int_digits2, "-3.9999")
834
+ assert_equal(3, LongDecimal("-4.0000").int_digits2, "-4.0000")
835
+ assert_equal(3, LongDecimal("-7.9999").int_digits2, "-7.9999")
836
+ end
837
+
838
+ #
839
+ # test int_digits10 of LongDecimal
840
+ #
841
+ def test_int_digits10
842
+ assert_equal(0, LongDecimal("0.0000").int_digits10, "0.0000")
843
+ assert_equal(0, LongDecimal("0.9999").int_digits10, "0.9999")
844
+ assert_equal(1, LongDecimal("1.0000").int_digits10, "1.0000")
845
+ assert_equal(1, LongDecimal("9.9999").int_digits10, "9.9999")
846
+ assert_equal(2, LongDecimal("10.0000").int_digits10, "10.0000")
847
+ assert_equal(2, LongDecimal("99.9999").int_digits10, "99.9999")
848
+ assert_equal(3, LongDecimal("100.0000").int_digits10, "100.0000")
849
+ assert_equal(3, LongDecimal("999.9999").int_digits10, "999.9999")
850
+
851
+ assert_equal(0, LongDecimal("-0.0000").int_digits10, "-0.0000")
852
+ assert_equal(0, LongDecimal("-0.9999").int_digits10, "-0.9999")
853
+ assert_equal(1, LongDecimal("-1.0000").int_digits10, "-1.0000")
854
+ assert_equal(1, LongDecimal("-9.9999").int_digits10, "-9.9999")
855
+ assert_equal(2, LongDecimal("-10.0000").int_digits10, "-10.0000")
856
+ assert_equal(2, LongDecimal("-99.9999").int_digits10, "-99.9999")
857
+ assert_equal(3, LongDecimal("-100.0000").int_digits10, "-100.0000")
858
+ assert_equal(3, LongDecimal("-999.9999").int_digits10, "-999.9999")
859
+ end
860
+
561
861
  #
562
862
  # test rounding of LongDecimal with ROUND_UP
563
863
  #
@@ -835,6 +1135,63 @@ class TestLongDecimal_class < RUNIT::TestCase
835
1135
  assert_equal("-0.0224", l.to_s, "l=#{l.inspect}")
836
1136
  end
837
1137
 
1138
+ #
1139
+ # test conversion to String with extra parameters
1140
+ #
1141
+ def test_to_s_with_params
1142
+ l = LongDecimal(224, 0)
1143
+ s = l.to_s(5)
1144
+ assert_equal("224.00000", s, "l=#{l.inspect} 5")
1145
+ s = l.to_s(5, LongDecimal::ROUND_UNNECESSARY, 16)
1146
+ assert_equal("e0.00000", s, "l=#{l.inspect} 5 ROUND_UNNECESSARY 16")
1147
+
1148
+ l = LongDecimal(224, 1)
1149
+ s = l.to_s(0, LongDecimal::ROUND_HALF_UP)
1150
+ assert_equal("22", s, "l=#{l.inspect} 0 ROUND_HALF_UP")
1151
+ s = l.to_s(5, LongDecimal::ROUND_HALF_UP)
1152
+ assert_equal("22.40000", s, "l=#{l.inspect} 5 ROUND_HALF_UP")
1153
+ s = l.to_s(5, LongDecimal::ROUND_HALF_UP, 16)
1154
+ assert_equal("16.66666", s, "l=#{l.inspect} 5 ROUND_HALF_UP")
1155
+ s = l.to_s(5, LongDecimal::ROUND_HALF_DOWN, 16)
1156
+ assert_equal("16.66666", s, "l=#{l.inspect} 5 ROUND_HALF_DOWN")
1157
+
1158
+ l = LongDecimal(224, 2)
1159
+ s = l.to_s(0, LongDecimal::ROUND_HALF_UP)
1160
+ assert_equal("2", s, "l=#{l.inspect} 0 ROUND_HALF_UP")
1161
+ s = l.to_s(5, LongDecimal::ROUND_HALF_UP)
1162
+ assert_equal("2.24000", s, "l=#{l.inspect} 5 ROUND_HALF_UP")
1163
+ s = l.to_s(5, LongDecimal::ROUND_HALF_UP, 16)
1164
+ assert_equal("2.3d70a", s, "l=#{l.inspect} 5 ROUND_HALF_UP")
1165
+ s = l.to_s(5, LongDecimal::ROUND_HALF_DOWN, 16)
1166
+ assert_equal("2.3d70a", s, "l=#{l.inspect} 5 ROUND_HALF_DOWN")
1167
+
1168
+ l = LongDecimal(-224, 0)
1169
+ s = l.to_s(5)
1170
+ assert_equal("-224.00000", s, "l=#{l.inspect} 5")
1171
+ s = l.to_s(5, LongDecimal::ROUND_UNNECESSARY, 16)
1172
+ assert_equal("-e0.00000", s, "l=#{l.inspect} 5 ROUND_UNNECESSARY 16")
1173
+
1174
+ l = LongDecimal(-224, 1)
1175
+ s = l.to_s(0, LongDecimal::ROUND_HALF_UP)
1176
+ assert_equal("-22", s, "l=#{l.inspect} 0 ROUND_HALF_UP")
1177
+ s = l.to_s(5, LongDecimal::ROUND_HALF_UP)
1178
+ assert_equal("-22.40000", s, "l=#{l.inspect} 5 ROUND_HALF_UP")
1179
+ s = l.to_s(5, LongDecimal::ROUND_HALF_UP, 16)
1180
+ assert_equal("-16.66666", s, "l=#{l.inspect} 5 ROUND_HALF_UP")
1181
+ s = l.to_s(5, LongDecimal::ROUND_HALF_DOWN, 16)
1182
+ assert_equal("-16.66666", s, "l=#{l.inspect} 5 ROUND_HALF_DOWN")
1183
+
1184
+ l = LongDecimal(-224, 2)
1185
+ s = l.to_s(0, LongDecimal::ROUND_HALF_UP)
1186
+ assert_equal("-2", s, "l=#{l.inspect} 0 ROUND_HALF_UP")
1187
+ s = l.to_s(5, LongDecimal::ROUND_HALF_UP)
1188
+ assert_equal("-2.24000", s, "l=#{l.inspect} 5 ROUND_HALF_UP")
1189
+ s = l.to_s(5, LongDecimal::ROUND_HALF_UP, 16)
1190
+ assert_equal("-2.3d70a", s, "l=#{l.inspect} 5 ROUND_HALF_UP")
1191
+ s = l.to_s(5, LongDecimal::ROUND_HALF_DOWN, 16)
1192
+ assert_equal("-2.3d70a", s, "l=#{l.inspect} 5 ROUND_HALF_DOWN")
1193
+ end
1194
+
838
1195
  #
839
1196
  # test conversion to Rational
840
1197
  #
@@ -2366,5 +2723,4 @@ end
2366
2723
 
2367
2724
  RUNIT::CUI::TestRunner.run(TestLongDecimal_class.suite)
2368
2725
 
2369
- # end of file testlong-decimal.rb
2370
-
2726
+ # end of file testlongdecimal.rb