long-decimal 0.00.21 → 0.00.22
Sign up to get free protection for your applications and to get access to all the features.
- data/README +23 -16
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/doc/classes/LongDecimal.html +343 -343
- data/doc/classes/LongDecimal.src/M000036.html +4 -4
- data/doc/classes/LongDecimal.src/M000037.html +4 -4
- data/doc/classes/LongDecimal.src/M000038.html +4 -4
- data/doc/classes/LongDecimal.src/M000039.html +4 -4
- data/doc/classes/LongDecimal.src/M000040.html +4 -6
- data/doc/classes/LongDecimal.src/M000041.html +4 -106
- data/doc/classes/LongDecimal.src/M000042.html +6 -21
- data/doc/classes/LongDecimal.src/M000043.html +105 -10
- data/doc/classes/LongDecimal.src/M000044.html +17 -23
- data/doc/classes/LongDecimal.src/M000045.html +10 -18
- data/doc/classes/LongDecimal.src/M000046.html +27 -4
- data/doc/classes/LongDecimal.src/M000047.html +17 -13
- data/doc/classes/LongDecimal.src/M000048.html +4 -28
- data/doc/classes/LongDecimal.src/M000049.html +15 -4
- data/doc/classes/LongDecimal.src/M000050.html +26 -6
- data/doc/classes/LongDecimal.src/M000051.html +4 -6
- data/doc/classes/LongDecimal.src/M000052.html +8 -4
- data/doc/classes/LongDecimal.src/M000053.html +6 -15
- data/doc/classes/LongDecimal.src/M000054.html +4 -7
- data/doc/classes/LongDecimal.src/M000055.html +15 -4
- data/doc/classes/LongDecimal.src/M000056.html +6 -14
- data/doc/classes/LongDecimal.src/M000057.html +4 -13
- data/doc/classes/LongDecimal.src/M000058.html +15 -4
- data/doc/classes/LongDecimal.src/M000059.html +13 -4
- data/doc/classes/LongDecimal.src/M000060.html +4 -4
- data/doc/classes/LongDecimal.src/M000062.html +4 -5
- data/doc/classes/LongDecimal.src/M000063.html +5 -4
- data/doc/classes/LongDecimal.src/M000064.html +5 -8
- data/doc/classes/LongDecimal.src/M000065.html +4 -9
- data/doc/classes/LongDecimal.src/M000066.html +6 -7
- data/doc/classes/LongDecimal.src/M000067.html +6 -6
- data/doc/classes/LongDecimal.src/M000068.html +9 -4
- data/doc/classes/LongDecimal.src/M000069.html +7 -13
- data/doc/classes/LongDecimal.src/M000070.html +4 -9
- data/doc/classes/LongDecimal.src/M000071.html +13 -7
- data/doc/classes/LongDecimal.src/M000072.html +7 -18
- data/doc/classes/LongDecimal.src/M000073.html +8 -7
- data/doc/classes/LongDecimal.src/M000074.html +20 -5
- data/doc/classes/LongDecimal.src/M000075.html +7 -8
- data/doc/classes/LongDecimal.src/M000076.html +5 -9
- data/doc/classes/LongDecimal.src/M000077.html +5 -5
- data/doc/classes/LongDecimal.src/M000078.html +9 -4
- data/doc/classes/LongDecimal.src/M000079.html +8 -6
- data/doc/classes/LongDecimal.src/M000080.html +4 -7
- data/doc/classes/LongDecimal.src/M000081.html +7 -4
- data/doc/classes/LongDecimal.src/M000082.html +7 -4
- data/doc/classes/LongDecimal.src/M000083.html +4 -9
- data/doc/classes/LongDecimal.src/M000084.html +4 -9
- data/doc/classes/LongDecimal.src/M000085.html +9 -5
- data/doc/classes/LongDecimal.src/M000086.html +7 -7
- data/doc/classes/LongDecimal.src/M000087.html +5 -4
- data/doc/classes/LongDecimal.src/M000088.html +9 -4
- data/doc/classes/LongDecimal.src/M000089.html +4 -4
- data/doc/classes/LongDecimal.src/M000090.html +4 -4
- data/doc/classes/LongDecimal.src/M000091.html +4 -59
- data/doc/classes/LongDecimal.src/M000092.html +4 -4
- data/doc/classes/LongDecimal.src/M000093.html +59 -4
- data/doc/classes/LongDecimal.src/M000094.html +4 -5
- data/doc/classes/LongDecimal.src/M000095.html +4 -4
- data/doc/classes/LongDecimal.src/M000098.html +5 -4
- data/doc/classes/LongDecimal.src/M000099.html +5 -4
- data/doc/classes/LongDecimal.src/M000100.html +4 -4
- data/doc/classes/LongDecimal.src/M000101.html +4 -4
- data/doc/classes/LongDecimalBase.html +53 -53
- data/doc/classes/LongDecimalBase.src/M000107.html +4 -4
- data/doc/classes/LongDecimalBase.src/M000108.html +4 -4
- data/doc/classes/LongDecimalBase.src/M000109.html +4 -4
- data/doc/classes/LongDecimalBase.src/M000110.html +4 -4
- data/doc/classes/LongDecimalBase.src/M000111.html +4 -5
- data/doc/classes/LongDecimalBase.src/M000112.html +9 -9
- data/doc/classes/LongDecimalBase.src/M000115.html +23 -0
- data/doc/classes/LongDecimalQuot.html +174 -133
- data/doc/classes/LongDecimalQuot.src/M000003.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000004.html +2 -1
- data/doc/classes/LongDecimalQuot.src/M000005.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000006.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000007.html +6 -5
- data/doc/classes/LongDecimalQuot.src/M000008.html +5 -4
- data/doc/classes/LongDecimalQuot.src/M000009.html +4 -4
- data/doc/classes/LongDecimalQuot.src/M000010.html +4 -4
- data/doc/classes/LongDecimalQuot.src/M000011.html +4 -4
- data/doc/classes/LongDecimalQuot.src/M000012.html +4 -4
- data/doc/classes/LongDecimalQuot.src/M000013.html +7 -4
- data/doc/classes/LongDecimalQuot.src/M000014.html +5 -8
- data/doc/classes/LongDecimalQuot.src/M000015.html +5 -9
- data/doc/classes/LongDecimalQuot.src/M000016.html +6 -7
- data/doc/classes/LongDecimalQuot.src/M000017.html +4 -4
- data/doc/classes/LongDecimalQuot.src/M000018.html +4 -4
- data/doc/classes/LongDecimalQuot.src/M000019.html +6 -18
- data/doc/classes/LongDecimalQuot.src/M000020.html +8 -7
- data/doc/classes/LongDecimalQuot.src/M000021.html +21 -5
- data/doc/classes/LongDecimalQuot.src/M000022.html +8 -4
- data/doc/classes/LongDecimalQuot.src/M000023.html +5 -96
- data/doc/classes/LongDecimalQuot.src/M000024.html +4 -38
- data/doc/classes/LongDecimalQuot.src/M000025.html +96 -4
- data/doc/classes/LongDecimalQuot.src/M000026.html +38 -4
- data/doc/classes/LongDecimalQuot.src/M000027.html +4 -4
- data/doc/classes/LongDecimalQuot.src/M000028.html +4 -4
- data/doc/classes/LongDecimalQuot.src/M000029.html +4 -4
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.html +10 -10
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000148.html +22 -0
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000149.html +18 -0
- data/doc/classes/LongMath.html +159 -161
- data/doc/classes/LongMath.src/M000118.html +5 -4
- data/doc/classes/LongMath.src/M000119.html +4 -5
- data/doc/classes/LongMath.src/M000120.html +4 -4
- data/doc/classes/LongMath.src/M000121.html +5 -18
- data/doc/classes/LongMath.src/M000122.html +4 -18
- data/doc/classes/LongMath.src/M000123.html +18 -5
- data/doc/classes/LongMath.src/M000124.html +16 -27
- data/doc/classes/LongMath.src/M000125.html +4 -4
- data/doc/classes/LongMath.src/M000126.html +17 -45
- data/doc/classes/LongMath.src/M000127.html +5 -21
- data/doc/classes/LongMath.src/M000128.html +50 -29
- data/doc/classes/LongMath.src/M000129.html +21 -6
- data/doc/classes/LongMath.src/M000130.html +31 -28
- data/doc/classes/LongMath.src/M000131.html +6 -48
- data/doc/classes/LongMath.src/M000132.html +33 -8
- data/doc/classes/LongMath.src/M000133.html +51 -4
- data/doc/classes/LongMath.src/M000134.html +7 -4
- data/doc/classes/LongMath.src/M000135.html +4 -64
- data/doc/classes/LongMath.src/M000136.html +4 -43
- data/doc/classes/LongMath.src/M000137.html +64 -4
- data/doc/classes/LongMath.src/M000138.html +43 -4
- data/doc/classes/LongMath.src/M000139.html +4 -7
- data/doc/classes/LongMath.src/M000140.html +4 -20
- data/doc/classes/LongMath.src/M000141.html +4 -18
- data/doc/classes/LongMath.src/M000142.html +11 -34
- data/doc/classes/LongMath.src/M000143.html +13 -253
- data/doc/classes/LongMath.src/M000144.html +40 -16
- data/doc/classes/LongMath.src/M000145.html +227 -0
- data/doc/classes/LongMath.src/M000146.html +33 -0
- data/doc/classes/LongMath/CacheKey.html +6 -6
- data/doc/classes/LongMath/CacheKey.src/M000147.html +36 -0
- data/doc/classes/Numeric.html +10 -10
- data/doc/classes/Numeric.src/M000103.html +18 -0
- data/doc/classes/Rational.html +5 -5
- data/doc/classes/Rational.src/M000104.html +23 -0
- data/doc/created.rid +1 -1
- data/doc/files/lib/long-decimal_rb.src/M000001.html +1 -1
- data/doc/files/lib/long-decimal_rb.src/M000002.html +1 -1
- data/doc/fr_method_index.html +145 -143
- data/lib/long-decimal.rb +52 -71
- data/test/testlongdecimal.rb +218 -449
- data/test/testlongdeclib.rb +485 -0
- data/test/testrandom.rb +75 -0
- data/version.rb +1 -1
- metadata +12 -3
- data/doc/files/lib/long-decimal_rb.html +0 -189
@@ -5,14 +5,19 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title
|
8
|
+
<title>| (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-operator"
|
15
|
-
<span class="ruby-
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 918</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">|</span>(<span class="ruby-identifier">other</span>)
|
15
|
+
<span class="ruby-identifier">s</span>, <span class="ruby-identifier">o</span> = <span class="ruby-identifier">equalize_scale</span>(<span class="ruby-identifier">other</span>)
|
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">LongDecimal</span> <span class="ruby-keyword kw">then</span>
|
17
|
+
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">s</span>.<span class="ruby-identifier">int_val</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">int_val</span>, <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scale</span>)
|
18
|
+
<span class="ruby-keyword kw">else</span>
|
19
|
+
<span class="ruby-identifier">s</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">o</span>
|
20
|
+
<span class="ruby-keyword kw">end</span>
|
16
21
|
<span class="ruby-keyword kw">end</span></pre>
|
17
22
|
</body>
|
18
23
|
</html>
|
@@ -5,17 +5,19 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title
|
8
|
+
<title>^ (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-operator"
|
15
|
-
<span class="ruby-
|
16
|
-
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 930</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">^</span>(<span class="ruby-identifier">other</span>)
|
15
|
+
<span class="ruby-identifier">s</span>, <span class="ruby-identifier">o</span> = <span class="ruby-identifier">equalize_scale</span>(<span class="ruby-identifier">other</span>)
|
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">LongDecimal</span> <span class="ruby-keyword kw">then</span>
|
17
|
+
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">s</span>.<span class="ruby-identifier">int_val</span> <span class="ruby-operator">^</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">int_val</span>, <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scale</span>)
|
18
|
+
<span class="ruby-keyword kw">else</span>
|
19
|
+
<span class="ruby-identifier">s</span> <span class="ruby-operator">^</span> <span class="ruby-identifier">o</span>
|
17
20
|
<span class="ruby-keyword kw">end</span>
|
18
|
-
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">int_val</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">other</span>, <span class="ruby-identifier">scale</span>)
|
19
21
|
<span class="ruby-keyword kw">end</span></pre>
|
20
22
|
</body>
|
21
23
|
</html>
|
@@ -5,17 +5,14 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title
|
8
|
+
<title>~ (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-operator"
|
15
|
-
<span class="ruby-
|
16
|
-
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"cannot shift by something other than Fixnum >= 0"</span>
|
17
|
-
<span class="ruby-keyword kw">end</span>
|
18
|
-
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">int_val</span> <span class="ruby-operator">>></span> <span class="ruby-identifier">other</span>, <span class="ruby-identifier">scale</span>)
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 942</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">~</span>
|
15
|
+
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-operator">~</span><span class="ruby-identifier">int_val</span>, <span class="ruby-identifier">scale</span>)
|
19
16
|
<span class="ruby-keyword kw">end</span></pre>
|
20
17
|
</body>
|
21
18
|
</html>
|
@@ -5,14 +5,17 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title
|
8
|
+
<title><< (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-operator"
|
15
|
-
<span class="ruby-identifier">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 949</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator"><<</span>(<span class="ruby-identifier">other</span>)
|
15
|
+
<span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Fixnum</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">other</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">then</span>
|
16
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"cannot shift by something other than Fixnum >= 0"</span>
|
17
|
+
<span class="ruby-keyword kw">end</span>
|
18
|
+
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">int_val</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">other</span>, <span class="ruby-identifier">scale</span>)
|
16
19
|
<span class="ruby-keyword kw">end</span></pre>
|
17
20
|
</body>
|
18
21
|
</html>
|
@@ -5,14 +5,17 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title
|
8
|
+
<title>>> (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
<span class="ruby-identifier">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 959</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">>></span>(<span class="ruby-identifier">other</span>)
|
15
|
+
<span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Fixnum</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">other</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">then</span>
|
16
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"cannot shift by something other than Fixnum >= 0"</span>
|
17
|
+
<span class="ruby-keyword kw">end</span>
|
18
|
+
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">int_val</span> <span class="ruby-operator">>></span> <span class="ruby-identifier">other</span>, <span class="ruby-identifier">scale</span>)
|
16
19
|
<span class="ruby-keyword kw">end</span></pre>
|
17
20
|
</body>
|
18
21
|
</html>
|
@@ -5,19 +5,14 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>[] (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-
|
15
|
-
<span class="ruby-identifier">
|
16
|
-
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">n</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
17
|
-
<span class="ruby-identifier">move_point_left_int</span>(<span class="ruby-identifier">n</span>)
|
18
|
-
<span class="ruby-keyword kw">else</span>
|
19
|
-
<span class="ruby-identifier">move_point_right_int</span>(<span class="ruby-operator">-</span><span class="ruby-identifier">n</span>)
|
20
|
-
<span class="ruby-keyword kw">end</span>
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 969</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-identifier">other</span>)
|
15
|
+
<span class="ruby-identifier">int_val</span>[<span class="ruby-identifier">other</span>]
|
21
16
|
<span class="ruby-keyword kw">end</span></pre>
|
22
17
|
</body>
|
23
18
|
</html>
|
@@ -5,19 +5,14 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>size (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
<span class="ruby-identifier">
|
16
|
-
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">n</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
17
|
-
<span class="ruby-identifier">move_point_left_int</span>(<span class="ruby-operator">-</span><span class="ruby-identifier">n</span>)
|
18
|
-
<span class="ruby-keyword kw">else</span>
|
19
|
-
<span class="ruby-identifier">move_point_right_int</span>(<span class="ruby-identifier">n</span>)
|
20
|
-
<span class="ruby-keyword kw">end</span>
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 976</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">size</span>
|
15
|
+
<span class="ruby-identifier">int_val</span>.<span class="ruby-identifier">size</span>
|
21
16
|
<span class="ruby-keyword kw">end</span></pre>
|
22
17
|
</body>
|
23
18
|
</html>
|
@@ -5,15 +5,19 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>move_point_left (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"only implemented for Fixnum
|
16
|
-
<span class="ruby-
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 983</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">move_point_left</span>(<span class="ruby-identifier">n</span>)
|
15
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"only implemented for Fixnum"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Fixnum</span>
|
16
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">n</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
17
|
+
<span class="ruby-identifier">move_point_left_int</span>(<span class="ruby-identifier">n</span>)
|
18
|
+
<span class="ruby-keyword kw">else</span>
|
19
|
+
<span class="ruby-identifier">move_point_right_int</span>(<span class="ruby-operator">-</span><span class="ruby-identifier">n</span>)
|
20
|
+
<span class="ruby-keyword kw">end</span>
|
17
21
|
<span class="ruby-keyword kw">end</span></pre>
|
18
22
|
</body>
|
19
23
|
</html>
|
@@ -5,18 +5,18 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>move_point_right (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"only implemented for Fixnum
|
16
|
-
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">n</span> <span class="ruby-operator">&
|
17
|
-
<span class="ruby-
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 995</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">move_point_right</span>(<span class="ruby-identifier">n</span>)
|
15
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"only implemented for Fixnum"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Fixnum</span>
|
16
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">n</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
17
|
+
<span class="ruby-identifier">move_point_left_int</span>(<span class="ruby-operator">-</span><span class="ruby-identifier">n</span>)
|
18
18
|
<span class="ruby-keyword kw">else</span>
|
19
|
-
<span class="ruby-
|
19
|
+
<span class="ruby-identifier">move_point_right_int</span>(<span class="ruby-identifier">n</span>)
|
20
20
|
<span class="ruby-keyword kw">end</span>
|
21
21
|
<span class="ruby-keyword kw">end</span></pre>
|
22
22
|
</body>
|
@@ -5,14 +5,15 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>move_point_left_int (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
<span class="ruby-keyword kw">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1008</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">move_point_left_int</span>(<span class="ruby-identifier">n</span>)
|
15
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"only implemented for Fixnum >= 0"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0</span>
|
16
|
+
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">int_val</span>, <span class="ruby-identifier">scale</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">n</span>)
|
16
17
|
<span class="ruby-keyword kw">end</span></pre>
|
17
18
|
</body>
|
18
19
|
</html>
|
@@ -5,14 +5,19 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>move_point_right_int (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
<span class="ruby-
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1017</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">move_point_right_int</span>(<span class="ruby-identifier">n</span>)
|
15
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"only implemented for Fixnum >= 0"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0</span>
|
16
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">n</span> <span class="ruby-operator">></span> <span class="ruby-identifier">scale</span>) <span class="ruby-keyword kw">then</span>
|
17
|
+
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">int_val</span> <span class="ruby-operator">*</span> <span class="ruby-value">10</span><span class="ruby-operator">**</span>(<span class="ruby-identifier">n</span><span class="ruby-operator">-</span><span class="ruby-identifier">scale</span>), <span class="ruby-value">0</span>)
|
18
|
+
<span class="ruby-keyword kw">else</span>
|
19
|
+
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">int_val</span>, <span class="ruby-identifier">scale</span><span class="ruby-operator">-</span><span class="ruby-identifier">n</span>)
|
20
|
+
<span class="ruby-keyword kw">end</span>
|
16
21
|
<span class="ruby-keyword kw">end</span></pre>
|
17
22
|
</body>
|
18
23
|
</html>
|
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>square (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
<span class="ruby-
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1031</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">square</span>
|
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>
|
17
17
|
</body>
|
18
18
|
</html>
|
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>sqrt (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
<span class="ruby-constant">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1041</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sqrt</span>(<span class="ruby-identifier">new_scale</span>, <span class="ruby-identifier">rounding_mode</span>)
|
15
|
+
<span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">sqrt</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">new_scale</span>, <span class="ruby-identifier">rounding_mode</span>)
|
16
16
|
<span class="ruby-keyword kw">end</span></pre>
|
17
17
|
</body>
|
18
18
|
</html>
|
@@ -5,69 +5,14 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>sqrt_with_remainder (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
|
16
|
-
<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>
|
17
|
-
<span class="ruby-comment cmt"># if other is LongDecimal as well, nothing to do</span>
|
18
|
-
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">other</span>, <span class="ruby-keyword kw">self</span>
|
19
|
-
|
20
|
-
<span class="ruby-keyword kw">elsif</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>
|
21
|
-
<span class="ruby-comment cmt"># if other is LongDecimalQuot, convert self to LongDecimalQuot</span>
|
22
|
-
<span class="ruby-comment cmt"># as well</span>
|
23
|
-
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">other</span>, <span class="ruby-constant">LongDecimalQuot</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_r</span>, <span class="ruby-identifier">scale</span>)
|
24
|
-
|
25
|
-
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Rational</span> <span class="ruby-keyword kw">then</span>
|
26
|
-
<span class="ruby-comment cmt"># if other is Rational, convert self and other to</span>
|
27
|
-
<span class="ruby-comment cmt"># LongDecimalQuot. This is well adapted to cover both.</span>
|
28
|
-
<span class="ruby-identifier">sc</span> = <span class="ruby-identifier">scale</span>
|
29
|
-
<span class="ruby-identifier">o</span> = <span class="ruby-constant">LongDecimalQuot</span>(<span class="ruby-identifier">other</span>, <span class="ruby-identifier">sc</span>)
|
30
|
-
<span class="ruby-identifier">s</span> = <span class="ruby-constant">LongDecimalQuot</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_r</span>, <span class="ruby-identifier">sc</span>)
|
31
|
-
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span>
|
32
|
-
|
33
|
-
<span class="ruby-comment cmt"># we could use BigDecimal as common type for combining Float and</span>
|
34
|
-
<span class="ruby-comment cmt"># LongDecimal, but this needs a lot of consideration. For the</span>
|
35
|
-
<span class="ruby-comment cmt"># time being we assume that we live well enough with converting</span>
|
36
|
-
<span class="ruby-comment cmt"># Float into LongDecimal</span>
|
37
|
-
<span class="ruby-comment cmt"># elsif (other.kind_of? Float) && size > 8 then</span>
|
38
|
-
<span class="ruby-comment cmt"># return coerce(BigDecimal(other.to_s))</span>
|
39
|
-
|
40
|
-
<span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Integer</span>) <span class="ruby-operator">||</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Float</span>) <span class="ruby-keyword kw">then</span>
|
41
|
-
<span class="ruby-comment cmt"># if other is Integer or Float, convert it to LongDecimal</span>
|
42
|
-
<span class="ruby-identifier">other</span> = <span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">other</span>)
|
43
|
-
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">scale</span> <span class="ruby-operator">></span> <span class="ruby-identifier">scale</span>) <span class="ruby-keyword kw">then</span>
|
44
|
-
<span class="ruby-identifier">other</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">round_to_scale</span>(<span class="ruby-identifier">scale</span>, <span class="ruby-constant">ROUND_HALF_UP</span>)
|
45
|
-
<span class="ruby-keyword kw">end</span>
|
46
|
-
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">other</span>, <span class="ruby-keyword kw">self</span>
|
47
|
-
|
48
|
-
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">BigDecimal</span> <span class="ruby-keyword kw">then</span>
|
49
|
-
<span class="ruby-comment cmt"># if other is BigDecimal convert self to BigDecimal</span>
|
50
|
-
<span class="ruby-identifier">s</span>, <span class="ruby-identifier">o</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_bd</span>)
|
51
|
-
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span>
|
52
|
-
|
53
|
-
<span class="ruby-keyword kw">elsif</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>
|
54
|
-
<span class="ruby-comment cmt"># if other is Complex, convert self to Float and then to</span>
|
55
|
-
<span class="ruby-comment cmt"># Complex. It need to be observed that this will fail if self</span>
|
56
|
-
<span class="ruby-comment cmt"># has too many digits before the decimal point to be expressed</span>
|
57
|
-
<span class="ruby-comment cmt"># as Float.</span>
|
58
|
-
<span class="ruby-identifier">s</span>, <span class="ruby-identifier">o</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-constant">Complex</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_f</span>, <span class="ruby-value">0</span>))
|
59
|
-
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span>
|
60
|
-
|
61
|
-
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Numeric</span> <span class="ruby-keyword kw">then</span>
|
62
|
-
<span class="ruby-comment cmt"># all other go by expressing self as Float and seeing how it</span>
|
63
|
-
<span class="ruby-comment cmt"># combines with other.</span>
|
64
|
-
<span class="ruby-identifier">s</span>, <span class="ruby-identifier">o</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_f</span>)
|
65
|
-
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span>
|
66
|
-
|
67
|
-
<span class="ruby-keyword kw">else</span>
|
68
|
-
<span class="ruby-comment cmt"># non-numeric types do not work here</span>
|
69
|
-
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">"unsupported type #{other.inspect} for coerce of LongDecimal"</span>
|
70
|
-
<span class="ruby-keyword kw">end</span>
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1051</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sqrt_with_remainder</span>(<span class="ruby-identifier">new_scale</span>)
|
15
|
+
<span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">sqrt_with_remainder</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">new_scale</span>)
|
71
16
|
<span class="ruby-keyword kw">end</span></pre>
|
72
17
|
</body>
|
73
18
|
</html>
|
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>abs (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
<span class="ruby-
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1058</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">abs</span>
|
15
|
+
<span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">int_val</span>.<span class="ruby-identifier">abs</span>, <span class="ruby-identifier">scale</span>)
|
16
16
|
<span class="ruby-keyword kw">end</span></pre>
|
17
17
|
</body>
|
18
18
|
</html>
|
@@ -5,14 +5,69 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>coerce (LongDecimal)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
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
|
14
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
15
|
-
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/long-decimal.rb, line 1067</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">coerce</span>(<span class="ruby-identifier">other</span>)
|
15
|
+
|
16
|
+
<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>
|
17
|
+
<span class="ruby-comment cmt"># if other is LongDecimal as well, nothing to do</span>
|
18
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">other</span>, <span class="ruby-keyword kw">self</span>
|
19
|
+
|
20
|
+
<span class="ruby-keyword kw">elsif</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>
|
21
|
+
<span class="ruby-comment cmt"># if other is LongDecimalQuot, convert self to LongDecimalQuot</span>
|
22
|
+
<span class="ruby-comment cmt"># as well</span>
|
23
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">other</span>, <span class="ruby-constant">LongDecimalQuot</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_r</span>, <span class="ruby-identifier">scale</span>)
|
24
|
+
|
25
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Rational</span> <span class="ruby-keyword kw">then</span>
|
26
|
+
<span class="ruby-comment cmt"># if other is Rational, convert self and other to</span>
|
27
|
+
<span class="ruby-comment cmt"># LongDecimalQuot. This is well adapted to cover both.</span>
|
28
|
+
<span class="ruby-identifier">sc</span> = <span class="ruby-identifier">scale</span>
|
29
|
+
<span class="ruby-identifier">o</span> = <span class="ruby-constant">LongDecimalQuot</span>(<span class="ruby-identifier">other</span>, <span class="ruby-identifier">sc</span>)
|
30
|
+
<span class="ruby-identifier">s</span> = <span class="ruby-constant">LongDecimalQuot</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_r</span>, <span class="ruby-identifier">sc</span>)
|
31
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span>
|
32
|
+
|
33
|
+
<span class="ruby-comment cmt"># we could use BigDecimal as common type for combining Float and</span>
|
34
|
+
<span class="ruby-comment cmt"># LongDecimal, but this needs a lot of consideration. For the</span>
|
35
|
+
<span class="ruby-comment cmt"># time being we assume that we live well enough with converting</span>
|
36
|
+
<span class="ruby-comment cmt"># Float into LongDecimal</span>
|
37
|
+
<span class="ruby-comment cmt"># elsif (other.kind_of? Float) && size > 8 then</span>
|
38
|
+
<span class="ruby-comment cmt"># return coerce(BigDecimal(other.to_s))</span>
|
39
|
+
|
40
|
+
<span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Integer</span>) <span class="ruby-operator">||</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Float</span>) <span class="ruby-keyword kw">then</span>
|
41
|
+
<span class="ruby-comment cmt"># if other is Integer or Float, convert it to LongDecimal</span>
|
42
|
+
<span class="ruby-identifier">other</span> = <span class="ruby-constant">LongDecimal</span>(<span class="ruby-identifier">other</span>)
|
43
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">scale</span> <span class="ruby-operator">></span> <span class="ruby-identifier">scale</span>) <span class="ruby-keyword kw">then</span>
|
44
|
+
<span class="ruby-identifier">other</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">round_to_scale</span>(<span class="ruby-identifier">scale</span>, <span class="ruby-constant">ROUND_HALF_UP</span>)
|
45
|
+
<span class="ruby-keyword kw">end</span>
|
46
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">other</span>, <span class="ruby-keyword kw">self</span>
|
47
|
+
|
48
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">BigDecimal</span> <span class="ruby-keyword kw">then</span>
|
49
|
+
<span class="ruby-comment cmt"># if other is BigDecimal convert self to BigDecimal</span>
|
50
|
+
<span class="ruby-identifier">s</span>, <span class="ruby-identifier">o</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_bd</span>)
|
51
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span>
|
52
|
+
|
53
|
+
<span class="ruby-keyword kw">elsif</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>
|
54
|
+
<span class="ruby-comment cmt"># if other is Complex, convert self to Float and then to</span>
|
55
|
+
<span class="ruby-comment cmt"># Complex. It need to be observed that this will fail if self</span>
|
56
|
+
<span class="ruby-comment cmt"># has too many digits before the decimal point to be expressed</span>
|
57
|
+
<span class="ruby-comment cmt"># as Float.</span>
|
58
|
+
<span class="ruby-identifier">s</span>, <span class="ruby-identifier">o</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-constant">Complex</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_f</span>, <span class="ruby-value">0</span>))
|
59
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span>
|
60
|
+
|
61
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Numeric</span> <span class="ruby-keyword kw">then</span>
|
62
|
+
<span class="ruby-comment cmt"># all other go by expressing self as Float and seeing how it</span>
|
63
|
+
<span class="ruby-comment cmt"># combines with other.</span>
|
64
|
+
<span class="ruby-identifier">s</span>, <span class="ruby-identifier">o</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_f</span>)
|
65
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>, <span class="ruby-identifier">s</span>
|
66
|
+
|
67
|
+
<span class="ruby-keyword kw">else</span>
|
68
|
+
<span class="ruby-comment cmt"># non-numeric types do not work here</span>
|
69
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">"unsupported type #{other.inspect} for coerce of LongDecimal"</span>
|
70
|
+
<span class="ruby-keyword kw">end</span>
|
16
71
|
<span class="ruby-keyword kw">end</span></pre>
|
17
72
|
</body>
|
18
73
|
</html>
|