long-decimal 0.00.19 → 0.00.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. data/README +25 -22
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/doc/classes/LongDecimal.html +327 -286
  5. data/doc/classes/LongDecimal.src/M000041.html +10 -4
  6. data/doc/classes/LongDecimal.src/M000042.html +3 -2
  7. data/doc/classes/LongDecimal.src/M000043.html +10 -26
  8. data/doc/classes/LongDecimal.src/M000044.html +24 -16
  9. data/doc/classes/LongDecimal.src/M000045.html +19 -4
  10. data/doc/classes/LongDecimal.src/M000046.html +4 -15
  11. data/doc/classes/LongDecimal.src/M000047.html +13 -26
  12. data/doc/classes/LongDecimal.src/M000048.html +28 -4
  13. data/doc/classes/LongDecimal.src/M000049.html +4 -8
  14. data/doc/classes/LongDecimal.src/M000050.html +8 -6
  15. data/doc/classes/LongDecimal.src/M000051.html +6 -4
  16. data/doc/classes/LongDecimal.src/M000052.html +4 -15
  17. data/doc/classes/LongDecimal.src/M000053.html +8 -24
  18. data/doc/classes/LongDecimal.src/M000054.html +6 -14
  19. data/doc/classes/LongDecimal.src/M000055.html +4 -13
  20. data/doc/classes/LongDecimal.src/M000056.html +15 -4
  21. data/doc/classes/LongDecimal.src/M000057.html +27 -0
  22. data/doc/classes/LongDecimal.src/M000058.html +4 -4
  23. data/doc/classes/LongDecimal.src/M000060.html +4 -4
  24. data/doc/classes/LongDecimal.src/M000061.html +5 -4
  25. data/doc/classes/LongDecimal.src/M000062.html +5 -8
  26. data/doc/classes/LongDecimal.src/M000063.html +4 -9
  27. data/doc/classes/LongDecimal.src/M000064.html +6 -7
  28. data/doc/classes/LongDecimal.src/M000065.html +6 -6
  29. data/doc/classes/LongDecimal.src/M000066.html +9 -4
  30. data/doc/classes/LongDecimal.src/M000067.html +7 -13
  31. data/doc/classes/LongDecimal.src/M000068.html +4 -9
  32. data/doc/classes/LongDecimal.src/M000069.html +13 -7
  33. data/doc/classes/LongDecimal.src/M000070.html +7 -18
  34. data/doc/classes/LongDecimal.src/M000071.html +8 -7
  35. data/doc/classes/LongDecimal.src/M000072.html +20 -5
  36. data/doc/classes/LongDecimal.src/M000073.html +6 -7
  37. data/doc/classes/LongDecimal.src/M000074.html +5 -9
  38. data/doc/classes/LongDecimal.src/M000075.html +5 -5
  39. data/doc/classes/LongDecimal.src/M000076.html +9 -4
  40. data/doc/classes/LongDecimal.src/M000077.html +7 -5
  41. data/doc/classes/LongDecimal.src/M000078.html +4 -7
  42. data/doc/classes/LongDecimal.src/M000079.html +7 -4
  43. data/doc/classes/LongDecimal.src/M000080.html +7 -4
  44. data/doc/classes/LongDecimal.src/M000081.html +4 -9
  45. data/doc/classes/LongDecimal.src/M000082.html +3 -8
  46. data/doc/classes/LongDecimal.src/M000083.html +9 -5
  47. data/doc/classes/LongDecimal.src/M000084.html +7 -7
  48. data/doc/classes/LongDecimal.src/M000085.html +5 -4
  49. data/doc/classes/LongDecimal.src/M000086.html +9 -4
  50. data/doc/classes/LongDecimal.src/M000087.html +4 -4
  51. data/doc/classes/LongDecimal.src/M000088.html +4 -4
  52. data/doc/classes/LongDecimal.src/M000089.html +4 -59
  53. data/doc/classes/LongDecimal.src/M000090.html +4 -4
  54. data/doc/classes/LongDecimal.src/M000091.html +59 -4
  55. data/doc/classes/LongDecimal.src/M000092.html +18 -0
  56. data/doc/classes/LongDecimal.src/M000093.html +18 -0
  57. data/doc/classes/LongDecimal.src/M000096.html +5 -4
  58. data/doc/classes/LongDecimal.src/M000097.html +5 -4
  59. data/doc/classes/LongDecimal.src/M000098.html +4 -4
  60. data/doc/classes/LongDecimal.src/M000099.html +4 -4
  61. data/doc/classes/LongDecimal.src/M000100.html +18 -0
  62. data/doc/classes/LongDecimal.src/M000101.html +18 -0
  63. data/doc/classes/LongDecimalBase.html +53 -53
  64. data/doc/classes/LongDecimalBase.src/M000104.html +4 -4
  65. data/doc/classes/LongDecimalBase.src/M000105.html +4 -4
  66. data/doc/classes/LongDecimalBase.src/M000106.html +4 -4
  67. data/doc/classes/LongDecimalBase.src/M000107.html +4 -4
  68. data/doc/classes/LongDecimalBase.src/M000108.html +18 -0
  69. data/doc/classes/LongDecimalBase.src/M000109.html +4 -9
  70. data/doc/classes/LongDecimalBase.src/M000112.html +9 -4
  71. data/doc/classes/LongDecimalBase.src/M000113.html +19 -0
  72. data/doc/classes/LongDecimalBase.src/M000114.html +18 -0
  73. data/doc/classes/LongDecimalQuot.src/M000003.html +1 -1
  74. data/doc/classes/LongDecimalQuot.src/M000004.html +22 -5
  75. data/doc/classes/LongDecimalQuot.src/M000005.html +1 -1
  76. data/doc/classes/LongDecimalQuot.src/M000006.html +1 -1
  77. data/doc/classes/LongDecimalQuot.src/M000007.html +1 -1
  78. data/doc/classes/LongDecimalQuot.src/M000008.html +1 -1
  79. data/doc/classes/LongDecimalQuot.src/M000009.html +1 -1
  80. data/doc/classes/LongDecimalQuot.src/M000010.html +1 -1
  81. data/doc/classes/LongDecimalQuot.src/M000011.html +1 -1
  82. data/doc/classes/LongDecimalQuot.src/M000012.html +1 -1
  83. data/doc/classes/LongDecimalQuot.src/M000013.html +1 -1
  84. data/doc/classes/LongDecimalQuot.src/M000014.html +1 -1
  85. data/doc/classes/LongDecimalQuot.src/M000015.html +1 -1
  86. data/doc/classes/LongDecimalQuot.src/M000016.html +1 -1
  87. data/doc/classes/LongDecimalQuot.src/M000017.html +1 -1
  88. data/doc/classes/LongDecimalQuot.src/M000018.html +1 -1
  89. data/doc/classes/LongDecimalQuot.src/M000019.html +1 -1
  90. data/doc/classes/LongDecimalQuot.src/M000020.html +1 -1
  91. data/doc/classes/LongDecimalQuot.src/M000021.html +1 -1
  92. data/doc/classes/LongDecimalQuot.src/M000022.html +1 -1
  93. data/doc/classes/LongDecimalQuot.src/M000023.html +1 -1
  94. data/doc/classes/LongDecimalQuot.src/M000024.html +1 -1
  95. data/doc/classes/LongDecimalQuot.src/M000025.html +1 -1
  96. data/doc/classes/LongDecimalQuot.src/M000026.html +1 -1
  97. data/doc/classes/LongDecimalQuot.src/M000027.html +1 -1
  98. data/doc/classes/LongDecimalQuot.src/M000028.html +1 -1
  99. data/doc/classes/LongDecimalQuot.src/M000029.html +1 -1
  100. data/doc/classes/LongDecimalQuot.src/M000032.html +1 -1
  101. data/doc/classes/LongDecimalQuot.src/M000033.html +1 -1
  102. data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.html +10 -10
  103. data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000141.html +22 -0
  104. data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000142.html +18 -0
  105. data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000146.html +22 -0
  106. data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000147.html +18 -0
  107. data/doc/classes/LongMath.html +191 -137
  108. data/doc/classes/LongMath.src/M000115.html +5 -4
  109. data/doc/classes/LongMath.src/M000116.html +4 -5
  110. data/doc/classes/LongMath.src/M000117.html +4 -4
  111. data/doc/classes/LongMath.src/M000118.html +5 -18
  112. data/doc/classes/LongMath.src/M000119.html +4 -18
  113. data/doc/classes/LongMath.src/M000120.html +18 -5
  114. data/doc/classes/LongMath.src/M000121.html +16 -27
  115. data/doc/classes/LongMath.src/M000122.html +4 -4
  116. data/doc/classes/LongMath.src/M000123.html +17 -44
  117. data/doc/classes/LongMath.src/M000124.html +5 -21
  118. data/doc/classes/LongMath.src/M000125.html +49 -29
  119. data/doc/classes/LongMath.src/M000126.html +20 -47
  120. data/doc/classes/LongMath.src/M000127.html +36 -8
  121. data/doc/classes/LongMath.src/M000128.html +6 -4
  122. data/doc/classes/LongMath.src/M000129.html +33 -4
  123. data/doc/classes/LongMath.src/M000130.html +40 -56
  124. data/doc/classes/LongMath.src/M000131.html +8 -43
  125. data/doc/classes/LongMath.src/M000132.html +4 -10
  126. data/doc/classes/LongMath.src/M000133.html +4 -7
  127. data/doc/classes/LongMath.src/M000134.html +58 -15
  128. data/doc/classes/LongMath.src/M000135.html +39 -16
  129. data/doc/classes/LongMath.src/M000136.html +6 -39
  130. data/doc/classes/LongMath.src/M000137.html +5 -168
  131. data/doc/classes/LongMath.src/M000138.html +34 -0
  132. data/doc/classes/LongMath.src/M000139.html +34 -0
  133. data/doc/classes/LongMath.src/M000140.html +57 -0
  134. data/doc/classes/LongMath.src/M000141.html +219 -0
  135. data/doc/classes/LongMath.src/M000142.html +33 -0
  136. data/doc/classes/LongMath.src/M000143.html +70 -0
  137. data/doc/classes/LongMath.src/M000144.html +58 -0
  138. data/doc/classes/LongMath/CacheKey.html +164 -0
  139. data/doc/classes/LongMath/CacheKey.src/M000140.html +36 -0
  140. data/doc/classes/LongMath/CacheKey.src/M000145.html +36 -0
  141. data/doc/classes/Numeric.html +5 -5
  142. data/doc/classes/Numeric.src/M000102.html +23 -0
  143. data/doc/classes/Rational.html +5 -5
  144. data/doc/classes/Rational.src/M000103.html +23 -0
  145. data/doc/created.rid +1 -1
  146. data/doc/files/lib/long-decimal_rb.html +2 -2
  147. data/doc/files/lib/long-decimal_rb.src/M000001.html +1 -1
  148. data/doc/files/lib/long-decimal_rb.src/M000002.html +1 -1
  149. data/doc/fr_method_index.html +106 -101
  150. data/lib/long-decimal.rb +203 -85
  151. data/test/testlongdecimal.rb +372 -69
  152. metadata +28 -2
@@ -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.23 2006/04/01 08:52:06 bk1 Exp $
6
- # CVS-Label: $Name: PRE_ALPHA_0_19 $
5
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal.rb,v 1.25 2006/04/02 15:52:27 bk1 Exp $
6
+ # CVS-Label: $Name: PRE_ALPHA_0_20 $
7
7
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
8
  #
9
9
 
@@ -18,7 +18,29 @@ load "lib/long-decimal.rb"
18
18
  #
19
19
  class TestLongDecimal_class < RUNIT::TestCase
20
20
 
21
- @RCS_ID='-$Id: testlongdecimal.rb,v 1.23 2006/04/01 08:52:06 bk1 Exp $-'
21
+ @RCS_ID='-$Id: testlongdecimal.rb,v 1.25 2006/04/02 15:52:27 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
22
44
 
23
45
  #
24
46
  # helper method for test_split_merge_words
@@ -78,7 +100,7 @@ class TestLongDecimal_class < RUNIT::TestCase
78
100
  # compare y against z = exp(x) calculated using regular floating point arithmetic
79
101
  z = Math.exp(x.to_f)
80
102
  yf = y.to_f
81
- 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}")
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}")
82
104
 
83
105
  # check by taking log(exp(x))
84
106
  # we have to take into account that we might not have enough
@@ -149,7 +171,7 @@ class TestLongDecimal_class < RUNIT::TestCase
149
171
  yf = y.to_f
150
172
  yi = yf.round
151
173
  zi = z.round
152
- assert((yi-zi) / [yf.abs, z.abs, Float::MIN].max < 1e-9, "yi=#{yi} and zi=#{zi} should be equal x=#{x} y=#{y} z=#{z}")
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}")
153
175
 
154
176
  if (y > 1)
155
177
  w = LongMath.log(y, 0)
@@ -162,8 +184,9 @@ class TestLongDecimal_class < RUNIT::TestCase
162
184
  # test the calculation of the exponential function with precision 0
163
185
  #
164
186
  def test_exp_int
165
- xx = LongMath.log(10.to_ld, 10)*100
166
- pi = Math::PI.to_ld(10)
187
+
188
+ xx = LongMath.log(10, 10)*100
189
+ pi = LongMath.pi(10)
167
190
  sq = LongMath.sqrt(5, 20)
168
191
 
169
192
  check_exp_int(0)
@@ -219,9 +242,9 @@ class TestLongDecimal_class < RUNIT::TestCase
219
242
  #
220
243
  def test_lm_power_xint
221
244
 
222
- xx = Math.log(3).to_ld(40)
223
- pi = Math::PI.to_ld(40)
224
- sq = Math.sqrt(5).to_ld(40)
245
+ xx = LongMath.log(3, 40)
246
+ pi = LongMath.pi(40)
247
+ sq = LongMath.sqrt(5, 40)
225
248
 
226
249
  check_power_xint(2, 700.01, 10)
227
250
  check_power_xint(2, 100.001, 10)
@@ -336,9 +359,9 @@ class TestLongDecimal_class < RUNIT::TestCase
336
359
  #
337
360
  def test_lm_power_yint
338
361
 
339
- xx = Math.log(3).to_ld(40)
340
- pi = Math::PI.to_ld(40)
341
- sq = Math.sqrt(5).to_ld(40)
362
+ xx = LongMath.log(3, 40)
363
+ pi = LongMath.pi(40)
364
+ sq = LongMath.sqrt(5, 40)
342
365
 
343
366
  check_power_yint(xx, 400, 10)
344
367
  check_power_yint(xx, 100, 10)
@@ -414,9 +437,78 @@ class TestLongDecimal_class < RUNIT::TestCase
414
437
 
415
438
  end
416
439
 
417
- # TODO test_exp_non_ld
418
- # test_log_non_ld
419
- # test_power_non_ld
440
+ #
441
+ # test LongMath.exp with non-LongDecimal arguments
442
+ #
443
+ def test_non_ld_exp
444
+ xi = 77
445
+ yi = LongMath.exp(xi, 30)
446
+ zi = LongMath.log(yi, 30)
447
+ assert(zi.is_int?, "zi")
448
+ assert_equal(xi, zi.to_i, "zi")
449
+
450
+ xf = 77.0
451
+ yf = LongMath.exp(xf, 30)
452
+ zf = LongMath.log(yf, 30)
453
+ assert(zf.is_int?, "zf")
454
+ assert_equal(xf, zf.to_f, "zf")
455
+ assert_equal(yi, yf, "i-f")
456
+
457
+ xr = Rational(224, 225)
458
+ yr = LongMath.exp(xr, 30)
459
+ zr = LongMath.log(yr, 30)
460
+ assert((zr-xr).abs <= zr.unit, "zr-xr")
461
+ end
462
+
463
+ #
464
+ # test LongMath.log with non-LongDecimal arguments
465
+ #
466
+ def test_non_ld_log
467
+ xi = 77
468
+ yi = LongMath.log(xi, 35)
469
+ zi = LongMath.exp(yi, 30)
470
+ assert(zi.is_int?, "zi=#{zi}")
471
+ assert_equal(xi, zi.to_i, "zi")
472
+
473
+ xf = 77.0
474
+ yf = LongMath.log(xf, 35)
475
+ zf = LongMath.exp(yf, 30)
476
+ assert(zf.is_int?, "zf=#{zf}")
477
+ assert_equal(xf, zf.to_f, "zf")
478
+ assert_equal(yi, yf, "i-f")
479
+
480
+ xr = Rational(224, 225)
481
+ yr = LongMath.log(xr, 35)
482
+ zr = LongMath.exp(yr, 30)
483
+ assert((zr-xr).abs <= zr.unit, "zr-xr zr=#{zr}")
484
+ end
485
+
486
+ #
487
+ # test LongMath.power with non-LongDecimal arguments
488
+ #
489
+ def test_non_ld_power
490
+ xi = 77
491
+ yi = 88
492
+ zi = LongMath.power(xi, yi, 35)
493
+ wi = (LongMath.log(zi, 40) / LongMath.log(xi, 40)).round_to_scale(30, LongMath::ROUND_HALF_EVEN)
494
+ assert(wi.is_int?, "wi=#{wi} not int (zi=#{zi})")
495
+ assert_equal(yi, wi.to_i, "zi=#{zi} wi=#{wi}")
496
+ zj = LongMath.power_internal(xi, yi, 35)
497
+ assert_equal(zi, zj, "internal power should yield the same result zi=#{zi} zj=#{zj}")
498
+
499
+ xf = 77.0
500
+ yf = 88.0
501
+ zf = LongMath.power(xf, yf, 35)
502
+ wf = (LongMath.log(zf, 40) / LongMath.log(xf, 40)).round_to_scale(30, LongMath::ROUND_HALF_EVEN)
503
+ assert(wf.is_int?, "wf=#{wf} not int (zf=#{zf} wi=#{wi} zi=#{zi}")
504
+ assert_equal(yf, wf.to_i, "yf=#{yf} wf=#{yf}")
505
+
506
+ xr = Rational(224, 225)
507
+ yr = Rational(168, 169)
508
+ zr = LongMath.power(xr, yr, 35)
509
+ wr = (LongMath.log(zr, 40) / LongMath.log(xr, 40)).round_to_scale(30, LongMath::ROUND_HALF_EVEN)
510
+ assert((yr-wr).abs <= wr.unit, "wr-yr")
511
+ end
420
512
 
421
513
  #
422
514
  # helper method for test_log
@@ -437,7 +529,7 @@ class TestLongDecimal_class < RUNIT::TestCase
437
529
  if (xf > 0) then
438
530
  z = Math.log(x.to_f)
439
531
  yf = y.to_f
440
- 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}")
532
+ 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}")
441
533
  end
442
534
  end
443
535
 
@@ -511,7 +603,8 @@ class TestLongDecimal_class < RUNIT::TestCase
511
603
  # compare y against w = x**y calculated using regular floating point arithmetic
512
604
  w = (x.to_f) ** (y.to_f)
513
605
  zf = z.to_f
514
- assert((zf - w) / [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}")
606
+ # 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}")
607
+ 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}")
515
608
 
516
609
  # check by taking log(z) = y * log(x)
517
610
  # we have to take into account that we might not have enough
@@ -519,13 +612,17 @@ class TestLongDecimal_class < RUNIT::TestCase
519
612
  if (z > 0) then
520
613
  lprec = prec
521
614
  if (z < 1) then
522
- l10 = (Math.log(z.to_f) / Math.log(10)).round
615
+ l10 = (Math.log(z.to_f) / Math.log(10)).floor
523
616
  lprec += l10
524
617
  end
525
618
  if (x < 1) then
526
- l10 = (Math.log(x.to_f) / Math.log(10)).round
619
+ l10 = (Math.log(x.to_f) / Math.log(10)).floor
527
620
  lprec += l10
528
621
  end
622
+ unit = (10**(-lprec)).to_ld
623
+ if (lprec < 0)
624
+ lprec = 0
625
+ end
529
626
  l10y = 0
530
627
  if (y > 1) then
531
628
  l10y = (Math.log(y.to_f) / Math.log(10)).ceil
@@ -533,7 +630,7 @@ class TestLongDecimal_class < RUNIT::TestCase
533
630
  u = LongMath.log(z, lprec)
534
631
  v = LongMath.log(x, lprec+l10y)
535
632
  yv = (y*v).round_to_scale(lprec, LongDecimal::ROUND_HALF_DOWN)
536
- assert((u - yv).abs <= u.unit, "u=#{u} and y*v=#{yv} should be almost equal (x=#{x.to_s} y=#{y.to_s} z=#{z.to_s} u=#{u.to_s} v=#{v.to_s} lprec=#{lprec} prec=#{prec})")
633
+ 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})")
537
634
  end
538
635
  # puts("ok check_power_floated: x=#{x} y=#{y} prec=#{prec}\n")
539
636
 
@@ -543,13 +640,32 @@ class TestLongDecimal_class < RUNIT::TestCase
543
640
  # test the calculation of the power-function of LongMath
544
641
  #
545
642
  def test_lm_power
546
- check_power_floated(1, 1, 10)
547
- check_power_floated(1, 2, 10)
548
- check_power_floated(2, 1, 10)
549
- check_power_floated(2, 2, 10)
550
- check_power_floated(100, 10, 10)
551
- check_power_floated(10, 100, 10)
552
- check_power_floated(10, 100, 100)
643
+ check_power_floated(1.001, 1.001, 10)
644
+ check_power_floated(1.001, 2.001, 10)
645
+ check_power_floated(2.001, 1.001, 10)
646
+ check_power_floated(2.001, 2.001, 10)
647
+ check_power_floated(100.001, 10.001, 10)
648
+ check_power_floated(10.001, 100.001, 10)
649
+ check_power_floated(10.001, 100.001, 100)
650
+ check_power_floated(1e-20, 1.01, 19)
651
+ check_power_floated(1.01, 1e-20, 19)
652
+ check_power_floated(1e-20, 1.01, 20)
653
+ check_power_floated(1.01, 1e-20, 20)
654
+ check_power_floated(1e-20, 1.01, 21)
655
+ check_power_floated(1.01, 1e-20, 21)
656
+
657
+ check_power_floated(1.001, -1.001, 10)
658
+ check_power_floated(1.001, -2.001, 10)
659
+ check_power_floated(2.001, -1.001, 10)
660
+ check_power_floated(2.001, -2.001, 10)
661
+ check_power_floated(100.001, -10.001, 10)
662
+ check_power_floated(10.001, -100.001, 10)
663
+ check_power_floated(1e-20, -1.01, 19)
664
+ check_power_floated(1.01, -1e-20, 19)
665
+ check_power_floated(1e-20, -1.01, 20)
666
+ check_power_floated(1.01, -1e-20, 20)
667
+ check_power_floated(1e-20, -1.01, 21)
668
+ check_power_floated(1.01, -1e-20, 21)
553
669
  end
554
670
 
555
671
  #
@@ -571,7 +687,7 @@ class TestLongDecimal_class < RUNIT::TestCase
571
687
  if (xf > 0) then
572
688
  z = Math.log(x.to_f) / Math.log(10)
573
689
  yf = y.to_f
574
- 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}")
690
+ 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}")
575
691
  end
576
692
  end
577
693
 
@@ -653,7 +769,7 @@ class TestLongDecimal_class < RUNIT::TestCase
653
769
  if (xf > 0) then
654
770
  z = Math.log(x.to_f) / Math.log(2)
655
771
  yf = y.to_f
656
- 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}")
772
+ 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}")
657
773
  end
658
774
  end
659
775
 
@@ -718,6 +834,63 @@ class TestLongDecimal_class < RUNIT::TestCase
718
834
  end
719
835
 
720
836
 
837
+
838
+ #
839
+ # test calculation of pi
840
+ #
841
+ def test_pi
842
+ s = "3.14159265358979323846264338327950288419716939937510"
843
+ s += "58209749445923078164062862089986280348253421170679"
844
+ s += "82148086513282306647093844609550582231725359408128"
845
+ s += "48111745028410270193852110555964462294895493038196"
846
+ s += "44288109756659334461284756482337867831652712019091"
847
+ s += "45648566923460348610454326648213393607260249141273"
848
+ s += "72458700660631558817488152092096282925409171536436"
849
+ s += "78925903600113305305488204665213841469519415116094"
850
+ s += "33057270365759591953092186117381932611793105118548"
851
+ s += "07446237996274956735188575272489122793818301194912"
852
+ s += "98336733624406566430860213949463952247371907021798"
853
+ s += "60943702770539217176293176752384674818467669405132"
854
+ s += "00056812714526356082778577134275778960917363717872"
855
+ s += "14684409012249534301465495853710507922796892589235"
856
+ s += "42019956112129021960864034418159813629774771309960"
857
+ s += "51870721134999999837297804995105973173281609631859"
858
+ s += "50244594553469083026425223082533446850352619311881"
859
+ s += "71010003137838752886587533208381420617177669147303"
860
+ s += "59825349042875546873115956286388235378759375195778"
861
+ s += "18577805321712268066130019278766111959092164201989"
862
+ s += "38095257201065485863278865936153381827968230301952"
863
+ s += "03530185296899577362259941389124972177528347913151"
864
+ s += "55748572424541506959508295331168617278558890750983"
865
+ s += "81754637464939319255060400927701671139009848824012"
866
+ s += "85836160356370766010471018194295559619894676783744"
867
+ s += "94482553797747268471040475346462080466842590694912"
868
+ s += "93313677028989152104752162056966024058038150193511"
869
+ s += "25338243003558764024749647326391419927260426992279"
870
+ s += "67823547816360093417216412199245863150302861829745"
871
+ s += "55706749838505494588586926995690927210797509302955"
872
+ s += "32116534498720275596023648066549911988183479775356"
873
+ s += "63698074265425278625518184175746728909777727938000"
874
+ s += "81647060016145249192173217214772350141441973568548"
875
+ s += "16136115735255213347574184946843852332390739414333"
876
+ s += "45477624168625189835694855620992192221842725502542"
877
+ s += "56887671790494601653466804988627232791786085784383"
878
+ s += "82796797668145410095388378636095068006422512520511"
879
+ s += "73929848960841284886269456042419652850222106611863"
880
+ s += "06744278622039194945047123713786960956364371917287"
881
+ s += "46776465757396241389086583264599581339047802759010"
882
+
883
+ l = LongDecimal(s)
884
+ pi = LongMath.pi 200
885
+ assert_equal(l.round_to_scale(200, LongMath::ROUND_HALF_EVEN), pi, "200 digits")
886
+ pi = LongMath.pi 201
887
+ assert_equal(l.round_to_scale(201, LongMath::ROUND_HALF_EVEN), pi, "201 digits")
888
+ pi = LongMath.pi 199
889
+ assert_equal(l.round_to_scale(199, LongMath::ROUND_HALF_EVEN), pi, "199 digits")
890
+ pi = LongMath.pi 201
891
+ assert_equal(l.round_to_scale(201, LongMath::ROUND_HALF_EVEN), pi, "201 digits")
892
+ end
893
+
721
894
  #
722
895
  # helper method for test_int_sqrtb
723
896
  #
@@ -1048,14 +1221,22 @@ class TestLongDecimal_class < RUNIT::TestCase
1048
1221
  # test construction of LongDecimal from Integer
1049
1222
  #
1050
1223
  def test_int_init
1051
- l = LongDecimal(224)
1052
- assert_equal(224, l.to_i, "no loss of information for integers allowed")
1053
- l = LongDecimal(-333)
1054
- assert_equal(-333, l.to_i, "no loss of information for integers allowed")
1055
- l = LongDecimal(1000000000000000000000000000000000000000000000000)
1056
- assert_equal(1000000000000000000000000000000000000000000000000, l.to_i, "no loss of information for integers allowed")
1057
- l = LongDecimal(19, 1)
1224
+ i = 224
1225
+ l = LongDecimal(i)
1226
+ assert_equal(i, l.to_i, "no loss of information for integers allowed")
1227
+ assert_equal(l, i.to_ld(0), "to_ld")
1228
+ i = -333
1229
+ l = LongDecimal(i)
1230
+ assert_equal(i, l.to_i, "no loss of information for integers allowed")
1231
+ assert_equal(l, i.to_ld(0), "to_ld")
1232
+ i = 1000000000000000000000000000000000000000000000000
1233
+ l = LongDecimal(i)
1234
+ assert_equal(i, l.to_i, "no loss of information for integers allowed")
1235
+ assert_equal(l, i.to_ld(0), "to_ld")
1236
+ i = 19
1237
+ l = LongDecimal(i, 1)
1058
1238
  assert_equal(1, l.to_i, "loss of information 1.9->1")
1239
+ assert_equal(LongDecimal(190, 1), i.to_ld(1))
1059
1240
  end
1060
1241
 
1061
1242
  #
@@ -1065,11 +1246,14 @@ class TestLongDecimal_class < RUNIT::TestCase
1065
1246
  r = Rational(227, 100)
1066
1247
  l = LongDecimal(r)
1067
1248
  assert_equal(r, l.to_r, "no loss of information for rationals with denominator power of 10 allowed l=#{l.inspect}")
1249
+ assert_equal(l, r.to_ld, "to_ld")
1068
1250
  l = LongDecimal(r, 3)
1069
1251
  assert_equal(r, l.to_r * 1000, "scaling for rationals")
1252
+ assert_equal(l, (r/1000).to_ld(5), "to_ld")
1070
1253
  r = Rational(224, 225)
1071
1254
  l = LongDecimal(r)
1072
1255
  assert((r - l.to_r).to_f.abs < 0.01, "difference of #{r.inspect} and #{l.inspect} must be less 0.01 but is #{(r - l.to_r).to_f.abs}")
1256
+ assert_equal(l, r.to_ld, "to_ld")
1073
1257
  end
1074
1258
 
1075
1259
  #
@@ -1079,12 +1263,19 @@ class TestLongDecimal_class < RUNIT::TestCase
1079
1263
  s = "5.32"
1080
1264
  l = LongDecimal(s)
1081
1265
  assert_equal(s, l.to_s, "l=#{l.inspect}")
1266
+ assert_equal(l, s.to_f.to_ld, "to_ld")
1082
1267
  f = 2.24
1083
1268
  l = LongDecimal(f)
1084
1269
  assert_equal(f.to_s, l.to_s, "l=#{l.inspect} f=#{f.inspect}")
1270
+ assert_equal(l, f.to_ld, "to_ld")
1085
1271
  f = 2.71E-4
1086
1272
  l = LongDecimal(f)
1087
1273
  assert_equal("0.000271", l.to_s, "l=#{l.inspect} f=#{f.inspect}")
1274
+ assert_equal(l, f.to_ld, "to_ld")
1275
+ f = 224.225
1276
+ l = LongDecimal(f, 4)
1277
+ assert_equal("0.0224225", l.to_s, "l=#{l.inspect} f=#{f.inspect}")
1278
+ assert_equal(l, (f/10000).to_ld(7), "to_ld")
1088
1279
  end
1089
1280
 
1090
1281
  #
@@ -1094,12 +1285,19 @@ class TestLongDecimal_class < RUNIT::TestCase
1094
1285
  b = BigDecimal("5.32")
1095
1286
  l = LongDecimal(b)
1096
1287
  assert_equal(b, l.to_bd, "l=#{l.inspect}")
1288
+ assert_equal(l, b.to_ld, "to_ld")
1097
1289
  b = BigDecimal("2.24")
1098
1290
  l = LongDecimal(b)
1099
1291
  assert((b.to_f - l.to_f).abs < 1e-9, "l=#{l.inspect} b=#{b.inspect}")
1292
+ assert_equal(l, b.to_ld, "to_ld")
1100
1293
  b = BigDecimal("2.71E-4")
1101
1294
  l = LongDecimal(b)
1102
1295
  assert_equal("0.000271", l.to_s, "l=#{l.inspect} b=#{b.inspect}")
1296
+ assert_equal(l, b.to_ld, "to_ld")
1297
+ b = BigDecimal("224.225")
1298
+ l = LongDecimal(b, 4)
1299
+ assert_equal("0.0224225", l.to_s, "l=#{l.inspect} b=#{b.inspect}")
1300
+ assert_equal(l, (b/10000).to_ld(7), "to_ld")
1103
1301
  end
1104
1302
 
1105
1303
  #
@@ -1794,44 +1992,93 @@ class TestLongDecimal_class < RUNIT::TestCase
1794
1992
  # test division of LongDecimal
1795
1993
  #
1796
1994
  def test_div
1797
- x = LongDecimal(224, 2)
1995
+ x = LongDecimal(224, 2) # 2.24 dx=1 sx=2
1798
1996
 
1799
- y = LongDecimal(3, 1)
1997
+ y = LongDecimal(3, 1) # 0.3 dy=0 sy=1
1998
+ z = x / y
1999
+ # 2dy+sy+sx-max(dx+sx,dy+sy)-3 = -3 -> use 0
2000
+ zz = LongDecimalQuot(Rational(224, 30), 0)
2001
+ assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
2002
+ assert_equal(zz, z, "z=#{z.inspect}")
2003
+ z = y / x
2004
+ # 2dx+sx+sy-max(dx+sx,dy+sy)-3 = -1 -> use 0
2005
+ zz = LongDecimalQuot(Rational(30, 224), 0)
2006
+ assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
2007
+ assert_equal(zz, z, "z=#{z.inspect}")
2008
+
2009
+ # x= 2.24 dx=1 sx=2
2010
+ y = LongDecimal(30000000, 8) # 0.30000000 dy=0 sy=8
1800
2011
  z = x / y
1801
- zz = LongDecimalQuot(Rational(224, 30), 2)
2012
+ # 2dy+sy+sx-max(dx+sx,dy+sy)-3 = -1 -> use 0
2013
+ zz = LongDecimalQuot(Rational(224, 30), 0)
1802
2014
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
1803
2015
  assert_equal(zz, z, "z=#{z.inspect}")
1804
2016
  z = y / x
2017
+ # 2dx+sx+sy-max(dx+sx,dy+sy)-3 = 1
1805
2018
  zz = LongDecimalQuot(Rational(30, 224), 1)
1806
2019
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
1807
2020
  assert_equal(zz, z, "z=#{z.inspect}")
1808
2021
 
1809
- y = 5
2022
+ # x= 2.24 dx=1 sx=2
2023
+ y = LongDecimal(3, 4) # 0.0003 dy=-4 sy=4
1810
2024
  z = x / y
1811
- zz = LongDecimalQuot(Rational(224, 500), 2)
2025
+ # 2dy+sy+sx-max(dx+sx,dy+sy)-3 = -8 -> use 0
2026
+ zz = LongDecimalQuot(Rational(22400, 3), 0)
1812
2027
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
1813
2028
  assert_equal(zz, z, "z=#{z.inspect}")
1814
2029
  z = y / x
2030
+ # 2dx+sx+sy-max(dx+sx,dy+sy)-3 = 2
2031
+ zz = LongDecimalQuot(Rational(3, 22400), 2)
2032
+ assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
2033
+ assert_equal(zz, z, "z=#{z.inspect}")
2034
+
2035
+ # x= 2.24 dx=1 sx=2
2036
+ y = LongDecimal(3333, 2) # 33.33 dy=2 sy=2
2037
+ z = x / y
2038
+ # 2dy+sy+sx-max(dx+sx,dy+sy)-3 = 1
2039
+ zz = LongDecimalQuot(Rational(224, 3333), 1)
2040
+ assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
2041
+ assert_equal(zz, z, "z=#{z.inspect}")
2042
+ z = y / x
2043
+ # 2dx+sx+sy-max(dx+sx,dy+sy)-3 = -1 -> use 0
2044
+ zz = LongDecimalQuot(Rational(3333, 224), 0)
2045
+ assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
2046
+ assert_equal(zz, z, "z=#{z.inspect}")
2047
+
2048
+ # x= 2.24 dx=1 sx=2
2049
+ y = 5 # 5 dy=1 sy=0
2050
+ z = x / y
2051
+ # 2dy+sy+sx-max(dx+sx,dy+sy)-3 = -2 -> use 0
2052
+ zz = LongDecimalQuot(Rational(224, 500), 0)
2053
+ assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
2054
+ assert_equal(zz, z, "z=#{z.inspect}")
2055
+ z = y / x
2056
+ # 2dx+sx+sy-max(dx+sx,dy+sy)-3 = -2 -> use 0
1815
2057
  zz = LongDecimalQuot(Rational(500, 224), 0)
1816
2058
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
1817
2059
  assert_equal(zz, z, "z=#{z.inspect}")
1818
2060
 
1819
- y = 5.001
2061
+ # x= 2.24 dx=1 sx=2
2062
+ y = 5.001 # dy=1 sy=3
1820
2063
  z = x / y
1821
- zz = LongDecimalQuot(Rational(224, 500), 2)
2064
+ # 2dy+sy+sx-max(dx+sx,dy+sy)-3 = 0
2065
+ zz = LongDecimalQuot(Rational(224, 500), 0)
1822
2066
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
1823
2067
  assert_equal(zz, z, "z=#{z.inspect}")
1824
2068
  z = y / x
1825
- zz = LongDecimalQuot(Rational(500, 224), 2)
2069
+ # 2dx+sx+sy-max(dx+sx,dy+sy)-3 = 0
2070
+ zz = LongDecimalQuot(Rational(500, 224), 0)
1826
2071
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
1827
2072
  assert_equal(zz, z, "z=#{z.inspect}")
1828
2073
 
1829
2074
  y = Rational(5, 3)
1830
2075
  z = x / y
2076
+ # y is has no scale, use scale of x
1831
2077
  zz = LongDecimalQuot(Rational(224*3, 500), 2)
1832
2078
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
1833
2079
  assert_equal(zz, z, "z=#{z.inspect}")
1834
2080
  z = y / x
2081
+ # y is has no scale, use scale of x
1835
2082
  zz = LongDecimalQuot(Rational(500, 224*3), 2)
1836
2083
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
1837
2084
  assert_equal(zz, z, "z=#{z.inspect}")
@@ -1930,42 +2177,70 @@ class TestLongDecimal_class < RUNIT::TestCase
1930
2177
  assert_kind_of(Integer, q, "q must be integer")
1931
2178
  assert_kind_of(LongDecimal, r, "r must be LongDecimalQuot")
1932
2179
  assert(r.abs < y.abs, "remainder must be less then divisor")
1933
- zz = LongDecimalQuot(Rational(224, 30), 2)
1934
- assert_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
2180
+ zz = LongDecimalQuot(Rational(224, 30), 0)
2181
+ assert_val_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
1935
2182
  q, r = y.divmod x
1936
2183
  assert_kind_of(Integer, q, "q must be integer")
1937
2184
  assert_kind_of(LongDecimal, r, "r must be LongDecimal")
1938
2185
  assert(r.abs < x.abs, "remainder must be less then divisor")
1939
- zz = LongDecimalQuot(Rational(30, 224), 2)
1940
- assert_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
2186
+ zz = LongDecimalQuot(Rational(30, 224), 0)
2187
+ assert_val_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
2188
+
2189
+ y = LongDecimal(30000000, 8)
2190
+ q, r = x.divmod y
2191
+ assert_kind_of(Integer, q, "q must be integer")
2192
+ assert_kind_of(LongDecimal, r, "r must be LongDecimalQuot")
2193
+ assert(r.abs < y.abs, "remainder must be less then divisor")
2194
+ zz = LongDecimalQuot(Rational(224, 30), 0)
2195
+ assert_val_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
2196
+ q, r = y.divmod x
2197
+ assert_kind_of(Integer, q, "q must be integer")
2198
+ assert_kind_of(LongDecimal, r, "r must be LongDecimal")
2199
+ assert(r.abs < x.abs, "remainder must be less then divisor")
2200
+ zz = LongDecimalQuot(Rational(30, 224), 0)
2201
+ assert_val_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
2202
+
2203
+ y = LongDecimal(3330000000, 8)
2204
+ q, r = x.divmod y
2205
+ assert_kind_of(Integer, q, "q must be integer")
2206
+ assert_kind_of(LongDecimal, r, "r must be LongDecimalQuot")
2207
+ assert(r.abs < y.abs, "remainder must be less then divisor")
2208
+ zz = LongDecimalQuot(Rational(224, 3330), 1)
2209
+ assert_val_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
2210
+ q, r = y.divmod x
2211
+ assert_kind_of(Integer, q, "q must be integer")
2212
+ assert_kind_of(LongDecimal, r, "r must be LongDecimal")
2213
+ assert(r.abs < x.abs, "remainder must be less then divisor")
2214
+ zz = LongDecimalQuot(Rational(3330, 224), 0)
2215
+ assert_val_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
1941
2216
 
1942
2217
  y = 5
1943
2218
  q, r = x.divmod y
1944
2219
  assert_kind_of(Integer, q, "q must be integer")
1945
2220
  assert_kind_of(LongDecimal, r, "r must be LongDecimal")
1946
2221
  assert(r.abs < y.abs, "remainder must be less then divisor")
1947
- zz = LongDecimalQuot(Rational(224, 500), 2)
1948
- assert_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
2222
+ zz = LongDecimalQuot(Rational(224, 500), 0)
2223
+ assert_val_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
1949
2224
  q, r = y.divmod x
1950
2225
  assert_kind_of(Integer, q, "q must be integer")
1951
2226
  assert_kind_of(LongDecimal, r, "r must be LongDecimal")
1952
2227
  assert(r.abs < x.abs, "remainder must be less then divisor")
1953
- zz = LongDecimalQuot(Rational(500, 224), 2)
1954
- assert_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
2228
+ zz = LongDecimalQuot(Rational(500, 224), 0)
2229
+ assert_val_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
1955
2230
 
1956
2231
  y = 5.001
1957
2232
  q, r = x.divmod y
1958
2233
  assert_kind_of(Integer, q, "q must be integer")
1959
2234
  assert_kind_of(LongDecimal, r, "r must be LongDecimal")
1960
2235
  assert(r.abs < y.abs, "remainder must be less then divisor")
1961
- zz = LongDecimalQuot(Rational(224, 500), 2)
1962
- assert_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
2236
+ zz = LongDecimalQuot(Rational(224, 500), 0)
2237
+ assert_val_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
1963
2238
  q, r = y.divmod x
1964
2239
  assert_kind_of(Integer, q, "q must be integer")
1965
2240
  assert_kind_of(LongDecimal, r, "r must be LongDecimal")
1966
2241
  assert(r.abs < x.abs, "remainder must be less then divisor")
1967
- zz = LongDecimalQuot(Rational(500, 224), 2)
1968
- assert_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
2242
+ zz = LongDecimalQuot(Rational(500, 224), 3)
2243
+ assert_val_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
1969
2244
 
1970
2245
  y = Rational(5, 3)
1971
2246
  q, r = x.divmod y
@@ -1973,13 +2248,13 @@ class TestLongDecimal_class < RUNIT::TestCase
1973
2248
  assert_kind_of(LongDecimalQuot, r, "r must be LongDecimal")
1974
2249
  assert(r.abs < y.abs, "remainder must be less then divisor")
1975
2250
  zz = LongDecimalQuot(Rational(224*3, 500), 2)
1976
- assert_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
2251
+ assert_val_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
1977
2252
  q, r = y.divmod x
1978
2253
  assert_kind_of(Integer, q, "q must be integer")
1979
2254
  assert_kind_of(LongDecimalQuot, r, "r must be LongDecimal")
1980
2255
  assert(r.abs < x.abs, "remainder must be less then divisor")
1981
2256
  zz = LongDecimalQuot(Rational(500, 224*3), 2)
1982
- assert_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
2257
+ assert_val_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
1983
2258
 
1984
2259
  y = LongDecimalQuot(Rational(5, 3), 3)
1985
2260
  q, r = x.divmod y
@@ -1987,13 +2262,13 @@ class TestLongDecimal_class < RUNIT::TestCase
1987
2262
  assert_kind_of(LongDecimalQuot, r, "r must be LongDecimal")
1988
2263
  assert(r.abs < y.abs, "remainder must be less then divisor")
1989
2264
  zz = LongDecimalQuot(Rational(224*3, 500), 6)
1990
- assert_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
2265
+ assert_val_equal(zz, q + r / y, "z=q=#{q.inspect} r=#{r.inspect}")
1991
2266
  q, r = y.divmod x
1992
2267
  assert_kind_of(Integer, q, "q must be integer")
1993
2268
  assert_kind_of(LongDecimalQuot, r, "r must be LongDecimal")
1994
2269
  assert(r.abs < x.abs, "remainder must be less then divisor")
1995
2270
  zz = LongDecimalQuot(Rational(500, 224*3), 3)
1996
- assert_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
2271
+ assert_val_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
1997
2272
 
1998
2273
  y = Complex(5, 3)
1999
2274
  begin
@@ -2536,11 +2811,17 @@ class TestLongDecimal_class < RUNIT::TestCase
2536
2811
  # test construction of LongDecimalQuot from LongDecimal
2537
2812
  #
2538
2813
  def test_ldq_ld_init
2539
- x = LongDecimal(224, 2)
2540
- y = LongDecimal(225, 3)
2814
+ x = LongDecimal(224, 2) # 2.24 dx=1 sx=2
2815
+ y = LongDecimal(225, 3) # 0.225 dy=0 sy=3
2541
2816
  z = LongDecimalQuot(x, y)
2542
- zz = LongDecimalQuot(Rational(2240, 225), 2)
2543
- assert_equal(zz, z, "224/225")
2817
+ # 2dy+sy+sx-max(dx+sx,dy+sy)-3 = -1 -> use 0
2818
+ zz = LongDecimalQuot(Rational(2240, 225), 0)
2819
+ assert_equal(zz, z, "2240/225")
2820
+
2821
+ z = LongDecimalQuot(y, x)
2822
+ # 2dx+sx+sy-max(dx+sx,dy+sy)-3 = 1
2823
+ zz = LongDecimalQuot(Rational(225, 2240), 1)
2824
+ assert_equal(zz, z, "225/2240")
2544
2825
  end
2545
2826
 
2546
2827
  #
@@ -2884,6 +3165,32 @@ class TestLongDecimal_class < RUNIT::TestCase
2884
3165
  assert_equal(ff, f, "must be equal")
2885
3166
  end
2886
3167
 
3168
+ #
3169
+ # test conversion to BigDecimal
3170
+ #
3171
+ def test_ldq_to_bd
3172
+ rr = Rational(224, 225)
3173
+ l = LongDecimalQuot(rr, 22)
3174
+ b = l.to_bd
3175
+ bb = BigDecimal(rr.to_f.to_s)
3176
+ assert_kind_of(BigDecimal, b, "must be bd")
3177
+ assert((b - bb).abs < 0.000001, "l=#{l.inspect}")
3178
+
3179
+ rr = Rational(-224, 225)
3180
+ l = LongDecimalQuot(rr, 22)
3181
+ b = l.to_bd
3182
+ bb = BigDecimal(rr.to_f.to_s)
3183
+ assert_kind_of(BigDecimal, b, "must be bd")
3184
+ assert((b - bb).abs < 0.000001, "l=#{l.inspect}")
3185
+
3186
+ rr = Rational(0, 225)
3187
+ l = LongDecimalQuot(rr, 22)
3188
+ b = l.to_bd
3189
+ bb = BigDecimal(rr.to_f.to_s)
3190
+ assert_kind_of(BigDecimal, b, "must be bd")
3191
+ assert((b - bb).abs < 0.000001, "l=#{l.inspect}")
3192
+ end
3193
+
2887
3194
  #
2888
3195
  # test to_i of LongDecimalQuot
2889
3196
  #
@@ -2939,10 +3246,6 @@ class TestLongDecimal_class < RUNIT::TestCase
2939
3246
  assert_equal(LongDecimal("3.5"), y, "3.5")
2940
3247
  end
2941
3248
 
2942
- # TODO
2943
- # def test_to_bd
2944
- # def test_to_ld_with_parms
2945
-
2946
3249
  #
2947
3250
  # test negation operator (unary -) of LongDecimalQuot
2948
3251
  #