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.
Files changed (153) hide show
  1. data/README +23 -16
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/doc/classes/LongDecimal.html +343 -343
  5. data/doc/classes/LongDecimal.src/M000036.html +4 -4
  6. data/doc/classes/LongDecimal.src/M000037.html +4 -4
  7. data/doc/classes/LongDecimal.src/M000038.html +4 -4
  8. data/doc/classes/LongDecimal.src/M000039.html +4 -4
  9. data/doc/classes/LongDecimal.src/M000040.html +4 -6
  10. data/doc/classes/LongDecimal.src/M000041.html +4 -106
  11. data/doc/classes/LongDecimal.src/M000042.html +6 -21
  12. data/doc/classes/LongDecimal.src/M000043.html +105 -10
  13. data/doc/classes/LongDecimal.src/M000044.html +17 -23
  14. data/doc/classes/LongDecimal.src/M000045.html +10 -18
  15. data/doc/classes/LongDecimal.src/M000046.html +27 -4
  16. data/doc/classes/LongDecimal.src/M000047.html +17 -13
  17. data/doc/classes/LongDecimal.src/M000048.html +4 -28
  18. data/doc/classes/LongDecimal.src/M000049.html +15 -4
  19. data/doc/classes/LongDecimal.src/M000050.html +26 -6
  20. data/doc/classes/LongDecimal.src/M000051.html +4 -6
  21. data/doc/classes/LongDecimal.src/M000052.html +8 -4
  22. data/doc/classes/LongDecimal.src/M000053.html +6 -15
  23. data/doc/classes/LongDecimal.src/M000054.html +4 -7
  24. data/doc/classes/LongDecimal.src/M000055.html +15 -4
  25. data/doc/classes/LongDecimal.src/M000056.html +6 -14
  26. data/doc/classes/LongDecimal.src/M000057.html +4 -13
  27. data/doc/classes/LongDecimal.src/M000058.html +15 -4
  28. data/doc/classes/LongDecimal.src/M000059.html +13 -4
  29. data/doc/classes/LongDecimal.src/M000060.html +4 -4
  30. data/doc/classes/LongDecimal.src/M000062.html +4 -5
  31. data/doc/classes/LongDecimal.src/M000063.html +5 -4
  32. data/doc/classes/LongDecimal.src/M000064.html +5 -8
  33. data/doc/classes/LongDecimal.src/M000065.html +4 -9
  34. data/doc/classes/LongDecimal.src/M000066.html +6 -7
  35. data/doc/classes/LongDecimal.src/M000067.html +6 -6
  36. data/doc/classes/LongDecimal.src/M000068.html +9 -4
  37. data/doc/classes/LongDecimal.src/M000069.html +7 -13
  38. data/doc/classes/LongDecimal.src/M000070.html +4 -9
  39. data/doc/classes/LongDecimal.src/M000071.html +13 -7
  40. data/doc/classes/LongDecimal.src/M000072.html +7 -18
  41. data/doc/classes/LongDecimal.src/M000073.html +8 -7
  42. data/doc/classes/LongDecimal.src/M000074.html +20 -5
  43. data/doc/classes/LongDecimal.src/M000075.html +7 -8
  44. data/doc/classes/LongDecimal.src/M000076.html +5 -9
  45. data/doc/classes/LongDecimal.src/M000077.html +5 -5
  46. data/doc/classes/LongDecimal.src/M000078.html +9 -4
  47. data/doc/classes/LongDecimal.src/M000079.html +8 -6
  48. data/doc/classes/LongDecimal.src/M000080.html +4 -7
  49. data/doc/classes/LongDecimal.src/M000081.html +7 -4
  50. data/doc/classes/LongDecimal.src/M000082.html +7 -4
  51. data/doc/classes/LongDecimal.src/M000083.html +4 -9
  52. data/doc/classes/LongDecimal.src/M000084.html +4 -9
  53. data/doc/classes/LongDecimal.src/M000085.html +9 -5
  54. data/doc/classes/LongDecimal.src/M000086.html +7 -7
  55. data/doc/classes/LongDecimal.src/M000087.html +5 -4
  56. data/doc/classes/LongDecimal.src/M000088.html +9 -4
  57. data/doc/classes/LongDecimal.src/M000089.html +4 -4
  58. data/doc/classes/LongDecimal.src/M000090.html +4 -4
  59. data/doc/classes/LongDecimal.src/M000091.html +4 -59
  60. data/doc/classes/LongDecimal.src/M000092.html +4 -4
  61. data/doc/classes/LongDecimal.src/M000093.html +59 -4
  62. data/doc/classes/LongDecimal.src/M000094.html +4 -5
  63. data/doc/classes/LongDecimal.src/M000095.html +4 -4
  64. data/doc/classes/LongDecimal.src/M000098.html +5 -4
  65. data/doc/classes/LongDecimal.src/M000099.html +5 -4
  66. data/doc/classes/LongDecimal.src/M000100.html +4 -4
  67. data/doc/classes/LongDecimal.src/M000101.html +4 -4
  68. data/doc/classes/LongDecimalBase.html +53 -53
  69. data/doc/classes/LongDecimalBase.src/M000107.html +4 -4
  70. data/doc/classes/LongDecimalBase.src/M000108.html +4 -4
  71. data/doc/classes/LongDecimalBase.src/M000109.html +4 -4
  72. data/doc/classes/LongDecimalBase.src/M000110.html +4 -4
  73. data/doc/classes/LongDecimalBase.src/M000111.html +4 -5
  74. data/doc/classes/LongDecimalBase.src/M000112.html +9 -9
  75. data/doc/classes/LongDecimalBase.src/M000115.html +23 -0
  76. data/doc/classes/LongDecimalQuot.html +174 -133
  77. data/doc/classes/LongDecimalQuot.src/M000003.html +1 -1
  78. data/doc/classes/LongDecimalQuot.src/M000004.html +2 -1
  79. data/doc/classes/LongDecimalQuot.src/M000005.html +1 -1
  80. data/doc/classes/LongDecimalQuot.src/M000006.html +1 -1
  81. data/doc/classes/LongDecimalQuot.src/M000007.html +6 -5
  82. data/doc/classes/LongDecimalQuot.src/M000008.html +5 -4
  83. data/doc/classes/LongDecimalQuot.src/M000009.html +4 -4
  84. data/doc/classes/LongDecimalQuot.src/M000010.html +4 -4
  85. data/doc/classes/LongDecimalQuot.src/M000011.html +4 -4
  86. data/doc/classes/LongDecimalQuot.src/M000012.html +4 -4
  87. data/doc/classes/LongDecimalQuot.src/M000013.html +7 -4
  88. data/doc/classes/LongDecimalQuot.src/M000014.html +5 -8
  89. data/doc/classes/LongDecimalQuot.src/M000015.html +5 -9
  90. data/doc/classes/LongDecimalQuot.src/M000016.html +6 -7
  91. data/doc/classes/LongDecimalQuot.src/M000017.html +4 -4
  92. data/doc/classes/LongDecimalQuot.src/M000018.html +4 -4
  93. data/doc/classes/LongDecimalQuot.src/M000019.html +6 -18
  94. data/doc/classes/LongDecimalQuot.src/M000020.html +8 -7
  95. data/doc/classes/LongDecimalQuot.src/M000021.html +21 -5
  96. data/doc/classes/LongDecimalQuot.src/M000022.html +8 -4
  97. data/doc/classes/LongDecimalQuot.src/M000023.html +5 -96
  98. data/doc/classes/LongDecimalQuot.src/M000024.html +4 -38
  99. data/doc/classes/LongDecimalQuot.src/M000025.html +96 -4
  100. data/doc/classes/LongDecimalQuot.src/M000026.html +38 -4
  101. data/doc/classes/LongDecimalQuot.src/M000027.html +4 -4
  102. data/doc/classes/LongDecimalQuot.src/M000028.html +4 -4
  103. data/doc/classes/LongDecimalQuot.src/M000029.html +4 -4
  104. data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.html +10 -10
  105. data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000148.html +22 -0
  106. data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000149.html +18 -0
  107. data/doc/classes/LongMath.html +159 -161
  108. data/doc/classes/LongMath.src/M000118.html +5 -4
  109. data/doc/classes/LongMath.src/M000119.html +4 -5
  110. data/doc/classes/LongMath.src/M000120.html +4 -4
  111. data/doc/classes/LongMath.src/M000121.html +5 -18
  112. data/doc/classes/LongMath.src/M000122.html +4 -18
  113. data/doc/classes/LongMath.src/M000123.html +18 -5
  114. data/doc/classes/LongMath.src/M000124.html +16 -27
  115. data/doc/classes/LongMath.src/M000125.html +4 -4
  116. data/doc/classes/LongMath.src/M000126.html +17 -45
  117. data/doc/classes/LongMath.src/M000127.html +5 -21
  118. data/doc/classes/LongMath.src/M000128.html +50 -29
  119. data/doc/classes/LongMath.src/M000129.html +21 -6
  120. data/doc/classes/LongMath.src/M000130.html +31 -28
  121. data/doc/classes/LongMath.src/M000131.html +6 -48
  122. data/doc/classes/LongMath.src/M000132.html +33 -8
  123. data/doc/classes/LongMath.src/M000133.html +51 -4
  124. data/doc/classes/LongMath.src/M000134.html +7 -4
  125. data/doc/classes/LongMath.src/M000135.html +4 -64
  126. data/doc/classes/LongMath.src/M000136.html +4 -43
  127. data/doc/classes/LongMath.src/M000137.html +64 -4
  128. data/doc/classes/LongMath.src/M000138.html +43 -4
  129. data/doc/classes/LongMath.src/M000139.html +4 -7
  130. data/doc/classes/LongMath.src/M000140.html +4 -20
  131. data/doc/classes/LongMath.src/M000141.html +4 -18
  132. data/doc/classes/LongMath.src/M000142.html +11 -34
  133. data/doc/classes/LongMath.src/M000143.html +13 -253
  134. data/doc/classes/LongMath.src/M000144.html +40 -16
  135. data/doc/classes/LongMath.src/M000145.html +227 -0
  136. data/doc/classes/LongMath.src/M000146.html +33 -0
  137. data/doc/classes/LongMath/CacheKey.html +6 -6
  138. data/doc/classes/LongMath/CacheKey.src/M000147.html +36 -0
  139. data/doc/classes/Numeric.html +10 -10
  140. data/doc/classes/Numeric.src/M000103.html +18 -0
  141. data/doc/classes/Rational.html +5 -5
  142. data/doc/classes/Rational.src/M000104.html +23 -0
  143. data/doc/created.rid +1 -1
  144. data/doc/files/lib/long-decimal_rb.src/M000001.html +1 -1
  145. data/doc/files/lib/long-decimal_rb.src/M000002.html +1 -1
  146. data/doc/fr_method_index.html +145 -143
  147. data/lib/long-decimal.rb +52 -71
  148. data/test/testlongdecimal.rb +218 -449
  149. data/test/testlongdeclib.rb +485 -0
  150. data/test/testrandom.rb +75 -0
  151. data/version.rb +1 -1
  152. metadata +12 -3
  153. data/doc/files/lib/long-decimal_rb.html +0 -189
@@ -2,8 +2,8 @@
2
2
  #
3
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.28 2006/04/05 23:33:54 bk1 Exp $
6
- # CVS-Label: $Name: PRE_ALPHA_0_21 $
5
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal.rb,v 1.32 2006/04/07 22:26:08 bk1 Exp $
6
+ # CVS-Label: $Name: PRE_ALPHA_0_22 $
7
7
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
8
  #
9
9
 
@@ -11,47 +11,16 @@ require "runit/testcase"
11
11
  require "runit/cui/testrunner"
12
12
  require "runit/testsuite"
13
13
 
14
- load "lib/long-decimal.rb"
14
+ # load "lib/long-decimal.rb"
15
+ load "test/testlongdeclib.rb"
15
16
 
16
17
  #
17
18
  # test class for LongDecimal and LongDecimalQuot
18
19
  #
19
20
  class TestLongDecimal_class < RUNIT::TestCase
21
+ include TestLongDecHelper
20
22
 
21
- @RCS_ID='-$Id: testlongdecimal.rb,v 1.28 2006/04/05 23:33:54 bk1 Exp $-'
22
-
23
- #
24
- # convenience method for comparing two numbers. true if and only if
25
- # they express the same value
26
- #
27
- def assert_val_equal(expected, actual, message="")
28
- _wrap_assertion {
29
- full_message = build_message(message, "Expected <?> to match <?>", actual, expected)
30
- assert_block(full_message) {
31
- (expected <=> actual).zero?
32
- }
33
- }
34
- end
35
-
36
- #
37
- # convenience method for comparing Float with LongDecimal
38
- # using a delta coming from these
39
- #
40
- def assert_mixed_equal(expected_f, actual_ld, message="")
41
- delta = [ actual_ld.unit, expected_f.abs / 1e10 ].max
42
- assert_equal_float(expected_f, actual_ld, delta, message)
43
- end
44
-
45
- #
46
- # helper method for test_split_merge_words
47
- #
48
- def check_split_merge_words(x, l, wl)
49
- w = LongMath.split_to_words(x, l)
50
- y = LongMath.merge_from_words(w, l)
51
- assert_equal(x, y, "#{x} splitted and merged should be equal but is #{y} l=#{l}")
52
- assert_equal(wl, w.length, "#{x} splitted to l=#{l} should have length #{wl} but has #{w.length}")
53
- w
54
- end
23
+ @RCS_ID='-$Id: testlongdecimal.rb,v 1.32 2006/04/07 22:26:08 bk1 Exp $-'
55
24
 
56
25
  #
57
26
  # test split_to_words and merge_from_words
@@ -85,43 +54,6 @@ class TestLongDecimal_class < RUNIT::TestCase
85
54
  check_split_merge_words(x, 1000, 1)
86
55
  end
87
56
 
88
- #
89
- # helper method for test_exp
90
- # tests if exp(x) with precision prec is calculated correctly
91
- #
92
- def check_exp_floated(x, prec)
93
-
94
- # make sure x is LongDecimal
95
- x0 = x
96
- x = x.to_ld
97
- # calculate y = exp(x)
98
- y = LongMath.exp(x, prec)
99
-
100
- # compare y against z = exp(x) calculated using regular floating point arithmetic
101
- z = Math.exp(x.to_f)
102
- yf = y.to_f
103
- assert((yf - z).abs <= [ y.unit, z.abs / 1e9 ].max, "y=#{yf.to_s} and z=#{z.to_s} should be almost equal x=#{x}")
104
-
105
- # check by taking log(exp(x))
106
- # we have to take into account that we might not have enough
107
- # significant digits, so we have to go down with the precision
108
- if (y > 0) then
109
- lprec = prec
110
- if (y < 1) then
111
- l10 = (Math.log(y.to_f) / Math.log(10)).round
112
- lprec += l10
113
- end
114
- z = LongMath.log(y, lprec)
115
- assert((x - z).abs <= z.unit, "x=#{x.to_s} and z=#{z.to_s} should be almost equal (y=#{y.to_s} lprec=#{lprec} prec=#{prec})")
116
- end
117
-
118
- # check by doing calculation with different internal rounding modes. They should not differ.
119
- yd = LongMath.exp_internal(x, prec, nil, nil, nil, nil, LongDecimal::ROUND_DOWN)
120
- yu = LongMath.exp_internal(x, prec, nil, nil, nil, nil, LongDecimal::ROUND_UP)
121
- assert_equal(yd, yu, "the result yd/yu should not depend on the internal rounding mode x0=#{x0} x=#{x} p=#{prec} d=#{(yd-yu).to_f.to_s}")
122
- assert_equal(y, yu, "the result y/yu should not depend on the internal rounding mode x0=#{x0} x=#{x} p=#{prec} d=#{(y -yu).to_f.to_s}")
123
- end
124
-
125
57
  #
126
58
  # test the calculation of the exponential function
127
59
  #
@@ -152,32 +84,10 @@ class TestLongDecimal_class < RUNIT::TestCase
152
84
  check_exp_floated(-700, 100)
153
85
  check_exp_floated(xx, 100)
154
86
  check_exp_floated(-xx, 100)
155
- end
156
-
157
- #
158
- # helper method for test_exp_int
159
- # tests if exp(x) with precision prec is calculated correctly
160
- #
161
- def check_exp_int(x)
162
-
163
- # make sure x is LongDecimal
164
- x0 = x
165
- x = x.to_ld
166
- y = LongMath.exp(x, 0)
167
- assert_equal(y.scale, 0, "scale must be 0")
168
-
169
- # compare y against z = exp(x) calculated using regular floating point arithmetic
170
- z = Math.exp(x0.to_f)
171
- yf = y.to_f
172
- yi = yf.round
173
- zi = z.round
174
- assert((yi-zi).abs / [yf.abs, z.abs, Float::MIN].max < 1e-9, "yi=#{yi} and zi=#{zi} should be equal x=#{x} y=#{y} z=#{z}")
175
-
176
- if (y > 1)
177
- w = LongMath.log(y, 0)
178
- assert((w-x).abs < 1, "log(y)=#{w} must be almost x=#{x0}")
179
- end
180
87
 
88
+ # random tests that have failed previously
89
+ check_exp_floated(LongDecimal("0.0000000000000000000000000050000000000000000000000000000000000000000000000000000000000000017066"), 25)
90
+ check_exp_floated(LongDecimal("0.00000000000000000000000000000000000000000000000000000000000000570000000004000000000000050"), 86)
181
91
  end
182
92
 
183
93
  #
@@ -219,24 +129,6 @@ class TestLongDecimal_class < RUNIT::TestCase
219
129
 
220
130
  end
221
131
 
222
- #
223
- # helper method for test_lm_power_xint
224
- # tests if exp(x) with precision prec is calculated correctly
225
- #
226
- def check_power_xint(x, y, prec)
227
-
228
- xi = x.to_i
229
- x = x.to_ld()
230
- y = y.to_ld()
231
- z = LongMath.power(x, y, prec)
232
- zz = LongMath.power_internal(x, y, prec)
233
- assert((zz - z).abs <= z.unit, "power with and without optimizations z=#{z} zz=#{zz} x=#{x} y=#{y}")
234
- # compare y against z = exp(x) calculated using regular floating point arithmetic
235
- zz = (xi) ** (y.to_f)
236
- zf = z.to_f
237
- assert((zf - zz).abs < [z.unit.to_f, zz.abs / 1e9 ].max, "z=#{z} and zz=#{zz} should be almost equal x=#{x} y=#{y} (zf=#{zf})")
238
- end
239
-
240
132
  #
241
133
  # test LongMath.power for bases that can be expressed as integer
242
134
  #
@@ -332,28 +224,6 @@ class TestLongDecimal_class < RUNIT::TestCase
332
224
 
333
225
  end
334
226
 
335
- #
336
- # helper method for test_lm_power_yint
337
- # tests if exp(x) with precision prec is calculated correctly
338
- #
339
- def check_power_yint(x, y, prec)
340
-
341
- yi = y.to_i
342
- x = x.to_ld
343
- y = y.to_ld
344
-
345
- z = LongMath.power(x, y, prec, LongMath::ROUND_HALF_UP)
346
- zz = (x ** yi).round_to_scale(prec, LongMath::ROUND_HALF_UP)
347
- assert_equal(z, zz, "power with ** or power-method x=#{x} y=#{y} z=#{z} zz=#{zz}")
348
- zz = LongMath.power_internal(x, y, prec)
349
- assert((zz - z).abs <= z.unit, "power with and without optimizations x=#{x} y=#{y} z=#{z} zz=#{zz}")
350
-
351
- zz = (x.to_f) ** (y.to_f)
352
- zf = z.to_f
353
- # assert((zf - zz).abs / [zf.abs, zz.abs, Float::MIN].max < 1e-9, "z=#{zf.to_s} and zz=#{zz.to_s} should be almost equal x=#{x} y=#{y} z=#{z} zz=#{zz}")
354
- assert((zf - zz).abs < [ z.unit.to_f, zf.abs / 1e9 ].max, "zf=#{zf.to_s} and zz=#{zz.to_s} should be almost equal x=#{x} y=#{y} z=#{z} zz=#{zz}")
355
- end
356
-
357
227
  #
358
228
  # test LongMath.power for bases that can be expressed as integer
359
229
  #
@@ -510,58 +380,6 @@ class TestLongDecimal_class < RUNIT::TestCase
510
380
  assert((yr-wr).abs <= wr.unit, "wr-yr")
511
381
  end
512
382
 
513
- #
514
- # helper method for test_log
515
- # tests if log(x) with precision prec is calculated correctly
516
- #
517
- def check_log_floated(x, prec, divisor=1e9, summand=0)
518
-
519
- # make sure x is LongDecimal
520
- x0 = x
521
- x = x.to_ld
522
- # calculate y = log(x)
523
- y = LongMath.log(x, prec)
524
-
525
- # compare y against z = exp(x) calculated using regular floating
526
- # point arithmetic
527
- if (x <= LongMath::MAX_FLOATABLE) then
528
- xf = x.to_f
529
- if (xf > 0) then
530
- z = Math.log(x.to_f)
531
- zl = z.to_ld(y.scale)
532
- delta = [ y.unit, z.abs / divisor + summand ].max
533
- assert((y - zl).abs <= delta, "y=#{y.to_s} (#{y.to_f}) and z=#{z.to_s} (#{zl.to_f}) should be almost equal (d=#{delta} x=#{x} y=#{y})")
534
- end
535
- end
536
-
537
- # check by taking exp(log(y))
538
- # we have to take into account that we might not have enough
539
- # significant digits, so we have to go down with the precision
540
- if (y <= LongMath::MAX_EXP_ABLE) then
541
- eprec = prec-1
542
- if (y > 1) then
543
- ly = 0
544
- if (y > LongMath::MAX_FLOATABLE) then
545
- puts("unusual y=#{y} y=#{y}\n")
546
- ly = LongMath::MAX_EXP_ABLE
547
- else
548
- ly = Math.log(y.to_f)
549
- end
550
- l10 = (ly / Math.log(10)).ceil
551
- eprec = [ eprec - l10, 0 ].max
552
- end
553
-
554
- z = LongMath.exp(y, eprec)
555
- 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})")
556
- end
557
-
558
- # check by doing calculation with different internal rounding modes. They should not differ.
559
- yd = LongMath.log_internal(x, prec, nil, nil, LongDecimal::ROUND_DOWN)
560
- yu = LongMath.log_internal(x, prec, nil, nil, LongDecimal::ROUND_UP)
561
- assert_equal(yd, yu, "the result yd/yu should not depend on the internal rounding mode yd=#{yd} yu=#{yu} y=#{y} p=#{prec} d=#{(yd-yu).to_f.to_s}")
562
- assert_equal(y, yu, "the result y/yu should not depend on the internal rounding mode yd=#{yd} yu=#{yu} y=#{y} p=#{prec} d=#{(y -yu).to_f.to_s}")
563
- end
564
-
565
383
  #
566
384
  # test the calculation of the logarithm function
567
385
  #
@@ -596,57 +414,12 @@ class TestLongDecimal_class < RUNIT::TestCase
596
414
  check_log_floated(1e-90, 100)
597
415
  check_log_floated(1e-300, 100)
598
416
  check_log_floated(LongDecimal(1, 2000), 100)
599
- end
600
-
601
- #
602
- # helper method for test_lm_power
603
- # tests if LongMath::power(x, y, prec) with precision prec is calculated correctly
604
- #
605
- def check_power_floated(x, y, prec)
606
-
607
- # puts("start: check_power_floated: x=#{x} y=#{y} prec=#{prec}\n")
608
- # make sure x and y are LongDecimal
609
- x0 = x
610
- x = x.to_ld
611
- y0 = y
612
- y = y.to_ld
613
- # calculate z = x**y
614
- z = LongMath.power(x, y, prec)
615
-
616
- # compare y against w = x**y calculated using regular floating point arithmetic
617
- w = (x.to_f) ** (y.to_f)
618
- zf = z.to_f
619
- # assert((zf - w).abs / [zf.abs, w.abs, Float::MIN].max < 1e-9, "z=#{zf.to_s} and w=#{w.to_s} should be almost equal x=#{x} y=#{y}")
620
- assert((zf - w).abs <= [ z.unit, zf.abs / 1e9 ].max, "z=#{zf.to_s} and w=#{w.to_s} should be almost equal x=#{x} y=#{y}")
621
-
622
- # check by taking log(z) = y * log(x)
623
- # we have to take into account that we might not have enough
624
- # significant digits, so we have to go down with the precision
625
- if (z > 0) then
626
- lprec = prec
627
- if (z < 1) then
628
- l10 = (Math.log(z.to_f) / Math.log(10)).floor
629
- lprec += l10
630
- end
631
- if (x < 1) then
632
- l10 = (Math.log(x.to_f) / Math.log(10)).floor
633
- lprec += l10
634
- end
635
- unit = (10**(-lprec)).to_ld
636
- if (lprec < 0)
637
- lprec = 0
638
- end
639
- l10y = 0
640
- if (y > 1) then
641
- l10y = (Math.log(y.to_f) / Math.log(10)).ceil
642
- end
643
- u = LongMath.log(z, lprec)
644
- v = LongMath.log(x, lprec+l10y)
645
- yv = (y*v).round_to_scale(lprec, LongDecimal::ROUND_HALF_DOWN)
646
- assert((u - yv).abs <= unit, "u=#{u} and yv=y*v=#{yv} should be almost equal (unit=#{unit} x=#{x.to_s} y=#{y.to_s} z=#{z.to_s} u=#{u.to_s} v=#{v.to_s} lprec=#{lprec} prec=#{prec})")
647
- end
648
- # puts("ok check_power_floated: x=#{x} y=#{y} prec=#{prec}\n")
649
417
 
418
+ # random tests that have failed
419
+ check_log_floated(LongDecimal("666.000000000000000000000000000000000091600000000531000000000000000000000000000000000000000000831"), 1)
420
+ check_log_floated(LongDecimal("333.000000000000000000000000919000000000000000000000000000000000001240000000000198"), 91)
421
+ check_log_floated(LongDecimal("695.000000000000000000000000000000000000016169000000000000000572"), 10)
422
+ check_log_floated(LongDecimal("553.00000000526000000000000000000000000000000000000000000000000298000000000000000079"), 1)
650
423
  end
651
424
 
652
425
  #
@@ -681,69 +454,6 @@ class TestLongDecimal_class < RUNIT::TestCase
681
454
  check_power_floated(1.01, -1e-20, 21)
682
455
  end
683
456
 
684
- #
685
- # helper method for test_log10
686
- # tests if log10(x) with precision prec is calculated correctly
687
- #
688
- def check_log10_floated(x, prec)
689
-
690
- # make sure x is LongDecimal
691
- x0 = x
692
- x = x.to_ld
693
- # calculate y = log10(x)
694
- y = LongMath.log10(x, prec)
695
-
696
- # compare y against z = log10(x) calculated using regular floating
697
- # point arithmetic
698
- if (x <= LongMath::MAX_FLOATABLE) then
699
- xf = x.to_f
700
- if (xf > 0) then
701
- z = Math.log(x.to_f) / Math.log(10)
702
- yf = y.to_f
703
- assert((yf - z).abs / [yf.abs, z.abs, Float::MIN].max < 1e-9, "y=#{yf.to_s} and z=#{z.to_s} should be almost equal x=#{x}")
704
- end
705
- end
706
-
707
- # check by taking 10**(log10(x))
708
- # we have to take into account that we might not have enough
709
- # significant digits, so we have to go down with the precision
710
- if (y <= LongMath::MAX_EXP_ABLE) then
711
- eprec = prec
712
- if (y > 1) then
713
- lx = 0
714
- if (x > LongMath::MAX_FLOATABLE) then
715
- puts("unusual x=#{x} y=#{y}\n")
716
- lx = LongMath::MAX_EXP_ABLE
717
- else
718
- lx = Math.log(x.to_f)
719
- end
720
- l10 = (lx / Math.log(10)).ceil
721
- eprec = [ eprec - l10, 0 ].max
722
- end
723
-
724
- z = LongMath.power(10.to_ld, y, eprec)
725
- # zz = LongMath.exp10(y, eprec)
726
- # assert((zz - z).abs <= z.unit, "zz=#{zz.to_s} and z=#{z.to_s} should be almost equal (y=#{y.to_s} eprec=#{eprec} prec=#{prec})")
727
- 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})")
728
- end
729
-
730
- end
731
-
732
- #
733
- # helper method for test_log10
734
- # tests if log10(x) with precision prec is calculated correctly
735
- #
736
- def check_log10_exact(x, log10x, prec)
737
-
738
- # make sure x is LongDecimal
739
- x0 = x
740
- x = x.to_ld
741
- log10x = log10x.to_ld(prec)
742
- # calculate y = log10(x)
743
- y = LongMath.log10(x, prec)
744
- assert_equal(y, log10x, "log x should match exactly x=#{x} y=#{y} log10x=#{log10x}")
745
- end
746
-
747
457
  #
748
458
  # test the calculation of the base-10-logarithm function
749
459
  #
@@ -763,69 +473,6 @@ class TestLongDecimal_class < RUNIT::TestCase
763
473
  check_log10_exact(10**10, 10, 30)
764
474
  end
765
475
 
766
- #
767
- # helper method for test_log2
768
- # tests if log2(x) with precision prec is calculated correctly
769
- #
770
- def check_log2_floated(x, prec)
771
-
772
- # make sure x is LongDecimal
773
- x0 = x
774
- x = x.to_ld
775
- # calculate y = log2(x)
776
- y = LongMath.log2(x, prec)
777
-
778
- # compare y against z = log2(x) calculated using regular floating
779
- # point arithmetic
780
- if (x <= LongMath::MAX_FLOATABLE) then
781
- xf = x.to_f
782
- if (xf > 0) then
783
- z = Math.log(x.to_f) / Math.log(2)
784
- yf = y.to_f
785
- assert((yf - z).abs / [yf.abs, z.abs, Float::MIN].max < 1e-9, "y=#{yf.to_s} and z=#{z.to_s} should be almost equal x=#{x}")
786
- end
787
- end
788
-
789
- # check by taking 2**(log2(x))
790
- # we have to take into account that we might not have enough
791
- # significant digits, so we have to go down with the precision
792
- if (y <= LongMath::MAX_EXP_ABLE) then
793
- eprec = prec
794
- if (y > 1) then
795
- lx = 0
796
- if (x > LongMath::MAX_FLOATABLE) then
797
- puts("unusual x=#{x} y=#{y}\n")
798
- lx = LongMath::MAX_EXP_ABLE
799
- else
800
- lx = Math.log(x.to_f)
801
- end
802
- l10 = (lx / Math.log(10)).ceil
803
- eprec = [ eprec - l10, 0 ].max
804
- end
805
-
806
- z = LongMath.power(2.to_ld, y, eprec)
807
- # zz = LongMath.exp2(y, eprec)
808
- # assert((zz - z).abs <= z.unit, "zz=#{zz.to_s} and z=#{z.to_s} should be almost equal (y=#{y.to_s} eprec=#{eprec} prec=#{prec})")
809
- 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})")
810
- end
811
-
812
- end
813
-
814
- #
815
- # helper method for test_log2
816
- # tests if log2(x) with precision prec is calculated correctly
817
- #
818
- def check_log2_exact(x, log2x, prec)
819
-
820
- # make sure x is LongDecimal
821
- x0 = x
822
- x = x.to_ld
823
- log2x = log2x.to_ld(prec)
824
- # calculate y = log2(x)
825
- y = LongMath.log2(x, prec)
826
- assert_equal(y, log2x, "log x should match exactly x=#{x} y=#{y} log2x=#{log2x} prec=#{prec}")
827
- end
828
-
829
476
  #
830
477
  # test the calculation of the base-10-logarithm function
831
478
  #
@@ -904,18 +551,6 @@ class TestLongDecimal_class < RUNIT::TestCase
904
551
  assert_equal(l.round_to_scale(201, LongMath::ROUND_HALF_EVEN), pi, "201 digits")
905
552
  end
906
553
 
907
- #
908
- # helper method for test_int_sqrtb
909
- #
910
- def check_sqrtb(x, s)
911
- y = LongMath.sqrtb(x)
912
- z = y * y
913
- zz = (y+1)*(y+1)
914
- assert(0 <= y, "sqrt must be >= 0" + s)
915
- assert(z <= x && x < zz, "y=#{y}=sqrt(#{x}) and x in [#{z}, #{zz})" + s)
916
- y
917
- end
918
-
919
554
  #
920
555
  # test method sqrtb for calculating sqrt of short integers
921
556
  #
@@ -954,18 +589,6 @@ class TestLongDecimal_class < RUNIT::TestCase
954
589
  end
955
590
  end
956
591
 
957
- #
958
- # helper method of test_int_sqrtw
959
- #
960
- def check_sqrtw(x, s)
961
- y = LongMath.sqrtw(x)
962
- z = y * y
963
- zz = (y+1)*(y+1)
964
- assert(0 <= y, "sqrt must be >= 0" + s)
965
- assert(z <= x && x < zz, "y=#{y}=sqrt(#{x}) and x in [#{z}, #{zz})" + s)
966
- y
967
- end
968
-
969
592
  #
970
593
  # test method sqrtb for calculating sqrt of long integers
971
594
  #
@@ -1004,20 +627,6 @@ class TestLongDecimal_class < RUNIT::TestCase
1004
627
  end
1005
628
  end
1006
629
 
1007
- #
1008
- # helper method for test_int_sqrtb_with_remainder
1009
- #
1010
- def check_sqrtb_with_remainder(x, s)
1011
- y, r = LongMath.sqrtb_with_remainder(x)
1012
- z0 = y * y
1013
- z1 = z0 + r
1014
- z2 = (y+1)*(y+1)
1015
- assert(0 <= y, "sqrt _with_remaindermust be >= 0" + s)
1016
- assert_equal(z1, x, "x=#{x} y=#{y} r=#{r} z0=#{z0} z1=#{z1} z2=#{z2}" + s)
1017
- 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)
1018
- y
1019
- end
1020
-
1021
630
  #
1022
631
  # test method sqrtb_with_remainder for calculating sqrt _with_remainderof short integers
1023
632
  #
@@ -1060,20 +669,6 @@ class TestLongDecimal_class < RUNIT::TestCase
1060
669
  end
1061
670
  end
1062
671
 
1063
- #
1064
- # helper method for test_int_sqrtw_with_remainder
1065
- #
1066
- def check_sqrtw_with_remainder(x, s)
1067
- y, r = LongMath.sqrtw_with_remainder(x)
1068
- z0 = y * y
1069
- z1 = z0 + r
1070
- z2 = (y+1)*(y+1)
1071
- assert(0 <= y, "sqrt _with_remaindermust be >= 0" + s)
1072
- assert_equal(z1, x, "x=#{x} y=#{y} r=#{r} z0=#{z0} z1=#{z1} z2=#{z2}" + s)
1073
- 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)
1074
- y
1075
- end
1076
-
1077
672
  #
1078
673
  # test method sqrtb_with_remainder for calculating sqrt _with_remainderof long integers
1079
674
  #
@@ -1419,6 +1014,23 @@ class TestLongDecimal_class < RUNIT::TestCase
1419
1014
  assert_equal(4, LongMath.int_digits10(9999), "9999")
1420
1015
  end
1421
1016
 
1017
+ #
1018
+ # test round_trailing_zeros of LongDecimal
1019
+ #
1020
+ def test_round_trailing_zeros
1021
+ x = LongDecimal.one!(100)
1022
+ y = x.round_trailing_zeros
1023
+ z = LongDecimal.one!(0)
1024
+ assert_equal(y, z, "1 w/o trailing")
1025
+ x = LongDecimal(22400, 5)
1026
+ y = x.round_trailing_zeros
1027
+ z = LongDecimal(224, 3)
1028
+ assert_equal(y, z, "2.24 w/o trailing")
1029
+ x = LongDecimal(123456, 3)
1030
+ y = x.round_trailing_zeros
1031
+ assert_equal(y, x, "1234.56 w/o trailing")
1032
+ end
1033
+
1422
1034
  #
1423
1035
  # test rounding of LongDecimal with ROUND_UP
1424
1036
  #
@@ -1785,6 +1397,27 @@ class TestLongDecimal_class < RUNIT::TestCase
1785
1397
  assert((l.to_f - 0.0224).abs < 0.0224 * 0.000001, "l=#{l.inspect}")
1786
1398
  end
1787
1399
 
1400
+ #
1401
+ # test to_ld of Numeric
1402
+ #
1403
+ def test_to_ld
1404
+ x = LongDecimal(123, 100)
1405
+ y = x.to_ld(20, LongMath::ROUND_UP)
1406
+ z = LongDecimal(1, 20)
1407
+ assert_kind_of(LongDecimal, y, "must be ld")
1408
+ assert_equal(y, z, "x=#{x} y=#{y}")
1409
+ y = x.to_ld(20, LongMath::ROUND_HALF_UP)
1410
+ z = LongDecimal(0, 20)
1411
+ assert_kind_of(LongDecimal, y, "must be ld")
1412
+ assert_equal(y, z, "x=#{x} y=#{y}")
1413
+
1414
+ x = 224
1415
+ y = x.to_ld(20)
1416
+ z = LongDecimal(224*10**20, 20)
1417
+ assert_kind_of(LongDecimal, y, "must be ld")
1418
+ assert_equal(y, z, "x=#{x} y=#{y}")
1419
+ end
1420
+
1788
1421
  #
1789
1422
  # test conversion to BigDecimal
1790
1423
  #
@@ -2227,6 +1860,33 @@ class TestLongDecimal_class < RUNIT::TestCase
2227
1860
  assert((zz-z).abs < 1e-9, "z=#{z.inspect}")
2228
1861
  end
2229
1862
 
1863
+ #
1864
+ # test square of LongDecimal
1865
+ #
1866
+ def test_square
1867
+ 10.times do |i|
1868
+ n = (i*i+i)/2
1869
+ x = LongDecimal(n, i)
1870
+ y = x.square
1871
+ z = LongDecimal(n*n, 2*i)
1872
+ assert_equal(y, z, "square i=#{i}")
1873
+ end
1874
+ end
1875
+
1876
+ #
1877
+ # test reciprocal of LongDecimal
1878
+ #
1879
+ def test_reciprocal
1880
+ 10.times do |i|
1881
+ k = 2*i+1
1882
+ n = (k*k+k)/2
1883
+ x = LongDecimal(n, i)
1884
+ y = x.reciprocal
1885
+ z = LongDecimalQuot(Rational(10**i, n), [i+2*(Math.log10(n)-i).floor, 0].max)
1886
+ assert_equal(z, y, "reciprocal x=#{x} y=#{y} z=#{z} i=#{i} k=#{k} n=#{n}")
1887
+ end
1888
+ end
1889
+
2230
1890
  #
2231
1891
  # test power (**) of LongDecimal
2232
1892
  #
@@ -2402,6 +2062,49 @@ class TestLongDecimal_class < RUNIT::TestCase
2402
2062
  end
2403
2063
  end
2404
2064
 
2065
+ #
2066
+ # test dec, dec!, inc and inc! of LongDecimal
2067
+ #
2068
+ def test_inc_dec
2069
+
2070
+ x0 = LongDecimal(224, 1)
2071
+ x = LongDecimal(224, 1)
2072
+ y = x.inc
2073
+ z = LongDecimal(234, 1)
2074
+ assert_equal(x, x0, "x")
2075
+ assert_equal(z, y, "y, z")
2076
+ x.inc!
2077
+ assert_equal(z, x, "z, x")
2078
+
2079
+ x0 = LongDecimal(224, 1)
2080
+ x = LongDecimal(224, 1)
2081
+ y = x.dec
2082
+ z = LongDecimal(214, 1)
2083
+ assert_equal(x, x0, "x")
2084
+ assert_equal(z, y, "y, z")
2085
+ x.dec!
2086
+ assert_equal(z, x, "z, x")
2087
+ end
2088
+
2089
+ #
2090
+ # test pred and succ of LongDecimal
2091
+ #
2092
+ def test_pred_succ
2093
+ x0 = LongDecimal(2245, 2)
2094
+ x = LongDecimal(2245, 2)
2095
+ ys = x.succ
2096
+ assert_equal(x, x0, "x")
2097
+ yp = x.pred
2098
+ assert_equal(x, x0, "x")
2099
+ zs = LongDecimal(2246, 2)
2100
+ zp = LongDecimal(2244, 2)
2101
+ assert_equal(zs, ys, "succ")
2102
+ assert_equal(zp, yp, "pred")
2103
+ y = LongDecimal(2254, 2)
2104
+ n = (x..y).to_a.size
2105
+ assert_equal(10, n, "size")
2106
+ end
2107
+
2405
2108
  #
2406
2109
  # test of &-operator of LongDecimal
2407
2110
  #
@@ -2704,18 +2407,6 @@ class TestLongDecimal_class < RUNIT::TestCase
2704
2407
  assert_equal(z, y, "2240")
2705
2408
  end
2706
2409
 
2707
- #
2708
- # helper method of test_sqrt
2709
- #
2710
- def check_sqrt(x, scale, mode, su0, su1, str)
2711
- y = x.sqrt(scale, mode)
2712
- z0 = (y+su0*y.unit).square
2713
- z1 = (y+su1*y.unit).square
2714
- assert(0 <= y.sign, "sqrt must be >= 0" + str)
2715
- assert(z0 <= x && x <= z1, "y=#{y}=sqrt(#{x}) and x in [#{z0}, #{z1})" + str)
2716
- y
2717
- end
2718
-
2719
2410
  #
2720
2411
  # test sqrt of LongDecimal
2721
2412
  #
@@ -2798,19 +2489,6 @@ class TestLongDecimal_class < RUNIT::TestCase
2798
2489
  assert_equal(y1, y2, "y1 y2")
2799
2490
  end
2800
2491
 
2801
- #
2802
- # helper method of test_sqrt_with_remainder
2803
- #
2804
- def check_sqrt_with_remainder(x, scale, str)
2805
- y, r = x.sqrt_with_remainder(scale)
2806
- z0 = y.square
2807
- z1 = y.succ.square
2808
- assert(0 <= y.sign, "sqrt must be >= 0" + str)
2809
- assert(z0 <= x && x < z1, "y=#{y}=sqrt(#{x}) and x in [#{z0}, #{z1})" + str)
2810
- assert((x - z0 - r).zero?, "x=y*y+r")
2811
- r
2812
- end
2813
-
2814
2492
  #
2815
2493
  # test sqrt_with_remainder of LongDecimal
2816
2494
  #
@@ -3007,6 +2685,73 @@ class TestLongDecimal_class < RUNIT::TestCase
3007
2685
  assert_equal(y, y, "y equals y")
3008
2686
  end
3009
2687
 
2688
+ #
2689
+ # test value-equality-comparison (===) of LongDecimal
2690
+ #
2691
+ def test_val_equal
2692
+ x = LongDecimal(224, 2)
2693
+ y = LongDecimal(2240, 3)
2694
+ assert((x === y), "value equal")
2695
+ assert(x != y, "but not equal")
2696
+ assert(x === x, "x equals x")
2697
+ assert(y === y, "y equals y")
2698
+ x = 1.to_ld(100)
2699
+ y = 1
2700
+ assert((x === y), "value equal")
2701
+ assert(x != y, "but not equal")
2702
+ assert(x === x, "x equals x")
2703
+ assert(y === y, "y equals y")
2704
+ x = LongDecimal(123456, 3)
2705
+ y = Rational(123456, 1000)
2706
+ assert((x === y), "value equal")
2707
+ assert(x != y, "but not equal")
2708
+ assert(x === x, "x equals x")
2709
+ assert(y === y, "y equals y")
2710
+ end
2711
+
2712
+ #
2713
+ # test .unit() of LongDecimal
2714
+ #
2715
+ def test_unit
2716
+ 10.times do |i|
2717
+ x = LongDecimal.zero!(i)
2718
+ u = x.unit
2719
+ v = LongDecimal(1, i)
2720
+ assert_equal(u, v, "unit i=#{i}")
2721
+ x = i.to_ld(i*i)
2722
+ u = x.unit
2723
+ v = LongDecimal(1, i*i)
2724
+ assert_equal(u, v, "unit i=#{i}")
2725
+ end
2726
+ end
2727
+
2728
+ #
2729
+ # test denominator of LongDecimal
2730
+ #
2731
+ def test_denominator
2732
+ x = LongDecimal("-2.20")
2733
+ assert_equal(100, x.denominator, "-2.20")
2734
+ x = LongDecimal("2.20")
2735
+ assert_equal(100, x.denominator, "2.20")
2736
+ x = LongDecimal("2.2400")
2737
+ assert_equal(10000, x.denominator, "2.2400")
2738
+ x = LongDecimal(-1, 2)
2739
+ assert_equal(100, x.denominator, "-1 2")
2740
+ x = LongDecimal(-221, 1)
2741
+ assert_equal(10, x.denominator, "-221 1")
2742
+ x = LongDecimal(-224, 0)
2743
+ assert_equal(1, x.denominator, "-224 0")
2744
+ x = LongDecimal(-3, 5)
2745
+ assert_equal(100000, x.denominator, "-3 5")
2746
+ x = LongDecimal(0, 20)
2747
+ assert_equal(10**20, x.denominator, "0 20")
2748
+ x = LongDecimal(30000000, 8)
2749
+ assert_equal(10**8, x.denominator, "30000000 8")
2750
+ x = LongDecimal(3330000000, 8)
2751
+ assert_equal(10**8, x.denominator, "3330000000 8")
2752
+
2753
+ end
2754
+
3010
2755
  #
3011
2756
  # test construction of LongDecimalQuot from LongDecimal
3012
2757
  #
@@ -3421,27 +3166,27 @@ class TestLongDecimal_class < RUNIT::TestCase
3421
3166
  def test_ldq_to_ld
3422
3167
  x = LongDecimalQuot(1, 100)
3423
3168
  y = x.to_ld
3424
- assert((y.kind_of? LongDecimal), "must be ld")
3169
+ assert_kind_of(LongDecimal, y, "must be ld")
3425
3170
  assert_equal(100, y.scale, "scale is 100")
3426
3171
  assert(y.one?, "must be one")
3427
3172
  x = LongDecimalQuot(Rational(13, 9), 10)
3428
3173
  y = x.to_ld
3429
- assert((y.kind_of? LongDecimal), "must be ld")
3174
+ assert_kind_of(LongDecimal, y, "must be ld")
3430
3175
  assert_equal(10, y.scale, "scale is 10")
3431
3176
  assert_equal(LongDecimal("1.4444444444"), y, "1.44...")
3432
3177
  x = LongDecimalQuot(Rational(14, 9), 10)
3433
3178
  y = x.to_ld
3434
- assert((y.kind_of? LongDecimal), "must be ld")
3179
+ assert_kind_of(LongDecimal, y, "must be ld")
3435
3180
  assert_equal(10, y.scale, "scale is 10")
3436
3181
  assert_equal(LongDecimal("1.5555555556"), y, "1.55...")
3437
3182
  x = LongDecimalQuot(Rational(7, 20), 1)
3438
3183
  y = x.to_ld
3439
- assert((y.kind_of? LongDecimal), "must be ld")
3184
+ assert_kind_of(LongDecimal, y, "must be ld")
3440
3185
  assert_equal(1, y.scale, "scale is 1")
3441
3186
  assert_equal(LongDecimal("0.4"), y, "0.4")
3442
3187
  x = LongDecimalQuot(Rational(7, 2), 1)
3443
3188
  y = x.to_ld
3444
- assert((y.kind_of? LongDecimal), "must be ld")
3189
+ assert_kind_of(LongDecimal, y, "must be ld")
3445
3190
  assert_equal(1, y.scale, "scale is 1")
3446
3191
  assert_equal(LongDecimal("3.5"), y, "3.5")
3447
3192
  end
@@ -3865,6 +3610,30 @@ class TestLongDecimal_class < RUNIT::TestCase
3865
3610
  end
3866
3611
  end
3867
3612
 
3613
+ #
3614
+ # test dec, dec!, inc and inc! of LongDecimalQuot
3615
+ #
3616
+ def test_ldq_inc_dec
3617
+
3618
+ x0 = LongDecimalQuot(Rational(224, 225), 1)
3619
+ x = LongDecimalQuot(Rational(224, 225), 1)
3620
+ y = x.inc
3621
+ z = LongDecimalQuot(Rational(449, 225), 1)
3622
+ assert_equal(x, x0, "x")
3623
+ assert_equal(z, y, "y, z")
3624
+ x.inc!
3625
+ assert_equal(z, x, "z, x")
3626
+
3627
+ x0 = LongDecimalQuot(Rational(224, 225), 1)
3628
+ x = LongDecimalQuot(Rational(224, 225), 1)
3629
+ y = x.dec
3630
+ z = LongDecimalQuot(Rational(-1, 225), 1)
3631
+ assert_equal(x, x0, "x")
3632
+ assert_equal(z, y, "y, z")
3633
+ x.dec!
3634
+ assert_equal(z, x, "z, x")
3635
+ end
3636
+
3868
3637
  #
3869
3638
  # test absolute value of LongDecimalQuot
3870
3639
  #