long-decimal 0.01.03 → 0.02.01

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.
data/make_doc.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ #
4
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/make_doc.rb,v 1.3 2009/04/15 19:29:37 bk1 Exp $
5
+ # CVS-Label: $Name: BETA_02_01 $
6
+ # Author: $Author: bk1 $ (Karl Brodowsky)
7
+ #
8
+
3
9
  $outdir = 'doc/'
4
10
  puts "Creating documentation in '#$outdir'."
5
11
  system "rdoc -d -o #$outdir lib/long-decimal.rb"
@@ -2,8 +2,10 @@
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-extra.rb,v 1.1 2007/08/19 19:25:59 bk1 Exp $
6
- # CVS-Label: $Name: ALPHA_01_03 $
5
+ # (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
6
+ #
7
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal-extra.rb,v 1.6 2009/04/19 20:47:41 bk1 Exp $
8
+ # CVS-Label: $Name: BETA_02_01 $
7
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
10
  #
9
11
 
@@ -21,7 +23,7 @@ load "test/testlongdeclib.rb"
21
23
  class TestLongDecimalExtra_class < RUNIT::TestCase
22
24
  include TestLongDecHelper
23
25
 
24
- @RCS_ID='-$Id: testlongdecimal-extra.rb,v 1.1 2007/08/19 19:25:59 bk1 Exp $-'
26
+ @RCS_ID='-$Id: testlongdecimal-extra.rb,v 1.6 2009/04/19 20:47:41 bk1 Exp $-'
25
27
 
26
28
  #
27
29
  # test exp2 of LongMath
@@ -388,7 +390,6 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
388
390
  check_power_floated(1.01, 1e-20, 20)
389
391
  check_power_floated(1e-20, 1.01, 21)
390
392
  check_power_floated(1.01, 1e-20, 21)
391
- puts "done (1.01, 1e-20, 21)"
392
393
 
393
394
  check_power_floated(1.001, -1.001, 10)
394
395
  check_power_floated(1.001, -2.001, 10)
@@ -402,9 +403,9 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
402
403
  check_power_floated(1.01, -1e-20, 20)
403
404
  check_power_floated(1e-20, -1.01, 21)
404
405
  check_power_floated(1.01, -1e-20, 21)
405
- puts "done (1.01, -1e-20, 21)"
406
406
 
407
407
  # random tests that have failed
408
+
408
409
  check_power_floated(LongDecimal("0.000000000077517987624900000000000000000000000000000000000000000000000000000000000000000000000000000014809051260000000000000000000000000000000000000000000000000000000000000000000000000000000000707281"),
409
410
  LongDecimal("26.627053911388694974442854299008649887946027550330988420533923061901183724914978160564862753777080769340"),
410
411
  29)
@@ -484,7 +485,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
484
485
  check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000000000000000000000000000002777290000000006513720000000003819240000000000000000000000000000100340800000000117667200000000000000000000000000000000000000000000906304"),
485
486
  LongDecimal("-0.5773502691896257645091447198050641552797247036332110311421498194545129249630222981047763195372146430879281215100223411775138874331819083544781222838698051829302865547075365868655847179043571799566074987574406310154782766513220296853158689786573196010629608653145605201822170964422894732870490642190250948498852022304300879727510280657218553"),
486
487
  23)
487
- puts "s"
488
+ puts "t"
488
489
  check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000007350000295000915"),
489
490
  LongDecimal("-1.000002193000861"),
490
491
  2)
@@ -548,7 +549,19 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
548
549
  check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
549
550
  LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
550
551
  23)
551
-
552
+ puts "j"
553
+ check_power_floated(LongDecimal("0.999999955000001687499940937501993359309219142762877860969997307557898777919131305606255214050322693251861572813240921773249050643887299214365089256902862200379712695062301304665207421015981915226866332635406597037254705387928614026219686983926304930980563519261869550253533841712248417739856791299844197817284010721773168197981077997089850680475101280715114294984559298890080189837019"),
554
+ LongDecimal("1152073732.71889400921658986175115207373271889400921658986175115207373271192582125814946165771199218501136146446091443861623733780713117713266372156187325484891985619348320999757983534072600830"),
555
+ 34)
556
+ puts "k"
557
+ check_power_floated(LongDecimal("0.9999999999999999790000000000000003307499999999999953571199999534000611652825014678992260416924691741095240984082153184971715719141172674714489939586322093325704050326051366867179642182008596501250357001333611677371975442553576183439891558582498678369021915"),
558
+ LongDecimal("723078346985052524411124.9942153732241195797916759141992675639370468905781573122561996247342863251769951237981444054472420932945762836317152649920140953979776753551488373967949714070011978110437743347922047335540909708006357292133505068791464115479823527616"),
559
+ 12);
560
+ puts "l"
561
+ check_power_floated(LongDecimal("0.0000000496000000000000000000000005130181"),
562
+ LongDecimal("4.481689070338064822602055460119275819005749868369667078288462665422608992659321754902779723364868999617977618563052671037918163226699981361015453605440282335627715767767332447975568034896269722320687889640"),
563
+ 53)
564
+
552
565
  end
553
566
 
554
567
  #
@@ -2,8 +2,10 @@
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.63 2007/08/19 19:25:59 bk1 Exp $
6
- # CVS-Label: $Name: ALPHA_01_03 $
5
+ # (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
6
+ #
7
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal.rb,v 1.68 2009/04/21 04:27:39 bk1 Exp $
8
+ # CVS-Label: $Name: BETA_02_01 $
7
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
10
  #
9
11
 
@@ -20,7 +22,7 @@ load "test/testlongdeclib.rb"
20
22
  class TestLongDecimal_class < RUNIT::TestCase
21
23
  include TestLongDecHelper
22
24
 
23
- @RCS_ID='-$Id: testlongdecimal.rb,v 1.63 2007/08/19 19:25:59 bk1 Exp $-'
25
+ @RCS_ID='-$Id: testlongdecimal.rb,v 1.68 2009/04/21 04:27:39 bk1 Exp $-'
24
26
 
25
27
  #
26
28
  # test split_to_words and merge_from_words
@@ -485,6 +487,86 @@ class TestLongDecimal_class < RUNIT::TestCase
485
487
  end
486
488
  end
487
489
 
490
+ #
491
+ # test method cbrtb for calculating cbrt of short integers
492
+ #
493
+ def test_int_cbrtb
494
+ assert_equal(-1, LongMath.cbrtb(-1), "cbrt(-1)=i")
495
+ 4096.times do |x|
496
+ check_cbrtb(x, " loop x=#{x}")
497
+ end
498
+ 512.times do |i|
499
+ x1 = i*i*i
500
+ y = check_cbrtb(x1, " i*i i=#{i}")
501
+ assert_equal(i, y, "i=#{i} y=#{y}")
502
+ if (i > 0) then
503
+ x2 = x1 + 1
504
+ y = check_cbrtb(x2, " i*i+1 i=#{i}")
505
+ assert_equal(i, y, "i=#{i} y=#{y}")
506
+ x0 = x1 - 1
507
+ y = check_cbrtb(x0, " i*i-1 i=#{i}")
508
+ assert_equal(i-1, y, "i=#{i} y=#{y}")
509
+ end
510
+
511
+ x1 = 1 << i
512
+ y = check_cbrtb(x1, " 2**i i=#{i}")
513
+ if (i % 3 == 0)
514
+ assert_equal(1 << (i / 3), y, "2^(i/3) i=#{i} y=#{y}")
515
+ end
516
+ if (i > 0) then
517
+ check_cbrtb(x1-1, " 2**i-1 i=#{i}")
518
+ check_cbrtb(x1+1, " 2**i+1 i=#{i}")
519
+ end
520
+
521
+ x1 = 3 << i
522
+ check_cbrtb(x1, " 3*2**i i=#{i}")
523
+ check_cbrtb(x1-1, " 3*2**i-1 i=#{i}")
524
+ check_cbrtb(x1+1, " 3*2**i+1 i=#{i}")
525
+ end
526
+ end
527
+
528
+ #
529
+ # test method cbrtb_with_remainder for calculating cbrt _with_remainderof short integers
530
+ #
531
+ def test_int_cbrtb_with_remainder
532
+ 10.times do |x|
533
+ check_cbrtb_with_remainder(x, " loop x=#{x}")
534
+ end
535
+ 100.times do |i|
536
+ x = 10 * i + 10
537
+ check_cbrtb_with_remainder(x, " loop x=#{x}")
538
+ end
539
+ 50.times do |j|
540
+ i = 10 * j
541
+ x1 = i * i * i
542
+ y = check_cbrtb_with_remainder(x1, " i**3 i=#{i}")
543
+ assert_equal(i, y, "i=#{i} y=#{y}")
544
+ if (i > 0) then
545
+ x2 = x1 + 1
546
+ y = check_cbrtb_with_remainder(x2, " i**3+1 i=#{i}")
547
+ assert_equal(i, y, "i=#{i} y=#{y}")
548
+ x0 = x1 - 1
549
+ y = check_cbrtb_with_remainder(x0, " i**3-1 i=#{i}")
550
+ assert_equal(i-1, y, "i=#{i} y=#{y}")
551
+ end
552
+
553
+ x1 = 1 << i
554
+ y = check_cbrtb_with_remainder(x1, " 2**i i=#{i}")
555
+ if (i % 3 == 0)
556
+ assert_equal(1 << (i/3), y, "2^(i/3) i=#{i} y=#{y}")
557
+ end
558
+ if (i > 0) then
559
+ check_cbrtb_with_remainder(x1-1, " 2**i-1 i=#{i}")
560
+ check_cbrtb_with_remainder(x1+1, " 2**i+1 i=#{i}")
561
+ end
562
+
563
+ x1 = 3 << i
564
+ check_cbrtb_with_remainder(x1, " 3*2**i i=#{i}")
565
+ check_cbrtb_with_remainder(x1-1, " 3*2**i-1 i=#{i}")
566
+ check_cbrtb_with_remainder(x1+1, " 3*2**i+1 i=#{i}")
567
+ end
568
+ end
569
+
488
570
  #
489
571
  # test gcd_with_high_power
490
572
  #
@@ -1346,7 +1428,6 @@ class TestLongDecimal_class < RUNIT::TestCase
1346
1428
 
1347
1429
  def check_round_to_one_remainder(i, r, modulus, rounding_mode, zero_rounding_mode)
1348
1430
 
1349
- # puts("i=#{i} r=#{r} m=#{modulus}")
1350
1431
  zero_modes = [ LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS,\
1351
1432
  LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS,\
1352
1433
  LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS,\
@@ -1786,7 +1867,9 @@ class TestLongDecimal_class < RUNIT::TestCase
1786
1867
  assert(((-l).to_f + 1e-281).abs < 1e-282, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
1787
1868
 
1788
1869
  l = LongDecimal("0.00000000000000000000000000000000000000000000000000002090000000000000000000000000332000042999999999999999934478499999999999999999999979183597303900000000000002280678889571719972270000000870125632696979999999999928587104894304210318436999963636067429710015568287618182130517226303011944557351440293760289098908449297658922618709026683663019359834144789263320")
1789
- assert((l.to_f - 0.0000000000000000000000000000000000000000000000000000209).abs < 1e-60, "l=#{l.inspect}")
1870
+ delta1 = (l - LongDecimal("0.0000000000000000000000000000000000000000000000000000209"))
1871
+ delta2 = delta1.to_f.abs
1872
+ assert(delta2 < 1e-60, "l=#{l.inspect}=#{l.to_s} delta1=#{delta1} delta2=#{delta2}")
1790
1873
  assert(((-l).to_f + 0.0000000000000000000000000000000000000000000000000000209).abs < 1e-60, "l=#{l.inspect}")
1791
1874
  end
1792
1875
 
@@ -2024,6 +2107,71 @@ class TestLongDecimal_class < RUNIT::TestCase
2024
2107
  assert_equal(zz, z, "z=#{z.inspect}")
2025
2108
  end
2026
2109
 
2110
+ #
2111
+ # test multiplication of fixnum, which is buggy in JRuby and has been fixed here.
2112
+ #
2113
+ def test_int_mul
2114
+ 65.times do |i|
2115
+ x0 = (1<<i)-1
2116
+ 3.times do |k|
2117
+ x = x0+k
2118
+ 65.times do |j|
2119
+ y0 = (1<<j)-1
2120
+ 3.times do |l|
2121
+ y = y0+l
2122
+ z = x*y
2123
+ if (x == 0 || y == 0)
2124
+ assert_equal(0, z)
2125
+ next
2126
+ end
2127
+ assert_equal(0, z%x)
2128
+ assert_equal(0, z%y)
2129
+ assert_equal(y, z/x)
2130
+ assert_equal(x, z/y)
2131
+ end
2132
+ end
2133
+ end
2134
+ end
2135
+ end
2136
+
2137
+ #
2138
+ # test multiplication of fixnum, which is buggy in JRuby and has been fixed here.
2139
+ #
2140
+ def test_mul2
2141
+ map = {}
2142
+ 65.times do |i|
2143
+ x0 = (1<<i)-1
2144
+ 3.times do |k|
2145
+ x1 = x0+k
2146
+ 4.times do |s|
2147
+ x = LongDecimal(x1, s)
2148
+ map[x] = x1
2149
+ end
2150
+ end
2151
+ end
2152
+ map.each do |x, x1|
2153
+ # puts "x=#{x} x1=#{x1}"
2154
+ print ":"
2155
+ $stdout.flush
2156
+ map.each do |y, y1|
2157
+ z = x*y
2158
+ z1 = x1*y1
2159
+ zz = LongDecimal(z1, x.scale + y.scale)
2160
+ assert_equal(zz, z)
2161
+ if (x.zero? || y.zero?)
2162
+ assert(z.zero?)
2163
+ next
2164
+ end
2165
+ rx = z%x
2166
+ ry = z%y
2167
+ assert "x=#{x} y=#{y} z=#{z} rx=#{rx}", (z%x).zero?
2168
+ assert "x=#{x} y=#{y} z=#{z} rx=#{ry}", (z%y).zero?
2169
+ assert_equal(y, (z/x).round_to_scale(y.scale))
2170
+ assert_equal(x, (z/y).round_to_scale(x.scale))
2171
+ end
2172
+ end
2173
+ end
2174
+
2027
2175
  #
2028
2176
  # test multiplication of LongDecimal
2029
2177
  #
@@ -2864,6 +3012,19 @@ class TestLongDecimal_class < RUNIT::TestCase
2864
3012
  end
2865
3013
  end
2866
3014
 
3015
+ #
3016
+ # test cube of LongDecimal
3017
+ #
3018
+ def test_cube
3019
+ 10.times do |i|
3020
+ n = (i*i+i)/2
3021
+ x = LongDecimal(n, i)
3022
+ y = x.cube
3023
+ z = LongDecimal(n*n*n, 3*i)
3024
+ assert_equal(y, z, "cube i=#{i}")
3025
+ end
3026
+ end
3027
+
2867
3028
  #
2868
3029
  # test reciprocal of LongDecimal
2869
3030
  #
@@ -3416,7 +3577,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3416
3577
  assert(y0.succ.square > x, "(y0.succ).square")
3417
3578
  y1 = check_sqrt(x, 120, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
3418
3579
  y2 = check_sqrt(x, 120, LongDecimal::ROUND_UP, -1, 0, "two")
3419
- assert(y2.pred.square < x, "y2.pred.squre")
3580
+ assert(y2.pred.square < x, "y2.pred.square")
3420
3581
  assert(y2.square > x, "y2*y2")
3421
3582
  assert(y0 <= y1, "y0 y1")
3422
3583
  assert(y1 <= y2, "y1 y2")
@@ -3426,7 +3587,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3426
3587
  assert(y0.succ.square > x, "(y0.succ).square")
3427
3588
  y1 = check_sqrt(x, 140, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
3428
3589
  y2 = check_sqrt(x, 140, LongDecimal::ROUND_UP, -1, 0, "two")
3429
- assert(y2.pred.square < x, "y2.pred.squre")
3590
+ assert(y2.pred.square < x, "y2.pred.square")
3430
3591
  assert(y2.square > x, "y2*y2")
3431
3592
  assert(y0 <= y1, "y0 y1")
3432
3593
  assert(y1 <= y2, "y1 y2")
@@ -3436,7 +3597,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3436
3597
  assert(y0.succ.square > x, "(y0.succ).square")
3437
3598
  y1 = check_sqrt(x, 160, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
3438
3599
  y2 = check_sqrt(x, 160, LongDecimal::ROUND_UP, -1, 0, "two")
3439
- assert(y2.pred.square < x, "y2.pred.squre")
3600
+ assert(y2.pred.square < x, "y2.pred.square")
3440
3601
  assert(y2.square > x, "y2*y2")
3441
3602
  assert(y0 <= y1, "y0 y1")
3442
3603
  assert(y1 <= y2, "y1 y2")
@@ -3446,7 +3607,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3446
3607
  assert(y0.succ.square > x, "(y0.succ).square")
3447
3608
  y1 = check_sqrt(x, 120, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
3448
3609
  y2 = check_sqrt(x, 120, LongDecimal::ROUND_UP, -1, 0, "two")
3449
- assert(y2.pred.square < x, "y2.pred.squre")
3610
+ assert(y2.pred.square < x, "y2.pred.square")
3450
3611
  assert(y2.square > x, "y2*y2")
3451
3612
  assert(y0 <= y1, "y0 y1")
3452
3613
  assert(y1 <= y2, "y1 y2")
@@ -3456,7 +3617,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3456
3617
  assert(y0.succ.square > x, "(y0.succ).square")
3457
3618
  y1 = check_sqrt(x, 100, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
3458
3619
  y2 = check_sqrt(x, 100, LongDecimal::ROUND_UP, -1, 0, "two")
3459
- assert(y2.pred.square < x, "y2.pred.squre")
3620
+ assert(y2.pred.square < x, "y2.pred.square")
3460
3621
  assert(y2.square > x, "y2*y2")
3461
3622
  assert(y0 <= y1, "y0 y1")
3462
3623
  assert(y1 <= y2, "y1 y2")
@@ -3467,7 +3628,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3467
3628
  assert(y0.succ.square > x, "(y0.succ).square")
3468
3629
  y1 = check_sqrt(x, 120, LongDecimal::ROUND_HALF_EVEN, -1, 1, "three")
3469
3630
  y2 = check_sqrt(x, 120, LongDecimal::ROUND_UP, -1, 0, "three")
3470
- assert(y2.pred.square < x, "y2.pred.squre")
3631
+ assert(y2.pred.square < x, "y2.pred.square")
3471
3632
  assert(y2.square > x, "y2*y2")
3472
3633
  assert(y0 <= y1, "y0 y1")
3473
3634
  assert(y1 <= y2, "y1 y2")
@@ -3535,6 +3696,143 @@ class TestLongDecimal_class < RUNIT::TestCase
3535
3696
  assert((zr-xr).abs <= zr.unit, "zr-xr")
3536
3697
  end
3537
3698
 
3699
+ #
3700
+ # test cbrt of LongDecimal
3701
+ #
3702
+ def test_cbrt
3703
+ x = LongDecimal.zero!(101)
3704
+ y = check_cbrt(x, 120, LongDecimal::ROUND_UNNECESSARY, 0, 0, "zero")
3705
+ assert(y.zero?, "cbrt(0)")
3706
+
3707
+ x = LongDecimal.one!(101)
3708
+ y = check_cbrt(x, 120, LongDecimal::ROUND_UNNECESSARY, 0, 0, "one")
3709
+ assert(y.one?, "cbrt(1)")
3710
+
3711
+ x = LongDecimal.two!(101)
3712
+ y0 = check_cbrt(x, 120, LongDecimal::ROUND_DOWN, 0, 1, "two")
3713
+ assert(y0.cube < x, "y0**3")
3714
+ assert(y0.succ.cube > x, "(y0.succ).cube")
3715
+ y1 = check_cbrt(x, 120, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
3716
+ y2 = check_cbrt(x, 120, LongDecimal::ROUND_UP, -1, 0, "two")
3717
+ assert(y2.pred.cube < x, "y2.pred.cube")
3718
+ assert(y2.cube > x, "y2**3")
3719
+ assert(y0 <= y1, "y0 y1")
3720
+ assert(y1 <= y2, "y1 y2")
3721
+
3722
+ y0 = check_cbrt(x, 140, LongDecimal::ROUND_DOWN, 0, 1, "two")
3723
+ assert(y0.cube < x, "y0**3")
3724
+ assert(y0.succ.cube > x, "(y0.succ).cube")
3725
+ y1 = check_cbrt(x, 140, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
3726
+ y2 = check_cbrt(x, 140, LongDecimal::ROUND_UP, -1, 0, "two")
3727
+ assert(y2.pred.cube < x, "y2.pred.cube")
3728
+ assert(y2.cube > x, "y2**3")
3729
+ assert(y0 <= y1, "y0 y1")
3730
+ assert(y1 <= y2, "y1 y2")
3731
+
3732
+ y0 = check_cbrt(x, 160, LongDecimal::ROUND_DOWN, 0, 1, "two")
3733
+ assert(y0.cube < x, "y0**3")
3734
+ assert(y0.succ.cube > x, "(y0.succ).cube")
3735
+ y1 = check_cbrt(x, 160, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
3736
+ y2 = check_cbrt(x, 160, LongDecimal::ROUND_UP, -1, 0, "two")
3737
+ assert(y2.pred.cube < x, "y2.pred.cube")
3738
+ assert(y2.cube > x, "y2**3")
3739
+ assert(y0 <= y1, "y0 y1")
3740
+ assert(y1 <= y2, "y1 y2")
3741
+
3742
+ y0 = check_cbrt(x, 120, LongDecimal::ROUND_DOWN, 0, 1, "two")
3743
+ assert(y0.cube < x, "y0**3")
3744
+ assert(y0.succ.cube > x, "(y0.succ).cube")
3745
+ y1 = check_cbrt(x, 120, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
3746
+ y2 = check_cbrt(x, 120, LongDecimal::ROUND_UP, -1, 0, "two")
3747
+ assert(y2.pred.cube < x, "y2.pred.cube")
3748
+ assert(y2.cube > x, "y2**3")
3749
+ assert(y0 <= y1, "y0 y1")
3750
+ assert(y1 <= y2, "y1 y2")
3751
+
3752
+ y0 = check_cbrt(x, 100, LongDecimal::ROUND_DOWN, 0, 1, "two")
3753
+ assert(y0.cube < x, "y0**3")
3754
+ assert(y0.succ.cube > x, "(y0.succ).cube")
3755
+ y1 = check_cbrt(x, 100, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
3756
+ y2 = check_cbrt(x, 100, LongDecimal::ROUND_UP, -1, 0, "two")
3757
+ assert(y2.pred.cube < x, "y2.pred.cube")
3758
+ assert(y2.cube > x, "y2**3")
3759
+ assert(y0 <= y1, "y0 y1")
3760
+ assert(y1 <= y2, "y1 y2")
3761
+
3762
+ x = 3.to_ld
3763
+ y0 = check_cbrt(x, 120, LongDecimal::ROUND_DOWN, 0, 1, "three")
3764
+ assert(y0.cube < x, "y0**3")
3765
+ assert(y0.succ.cube > x, "(y0.succ).cube")
3766
+ y1 = check_cbrt(x, 120, LongDecimal::ROUND_HALF_EVEN, -1, 1, "three")
3767
+ y2 = check_cbrt(x, 120, LongDecimal::ROUND_UP, -1, 0, "three")
3768
+ assert(y2.pred.cube < x, "y2.pred.cube")
3769
+ assert(y2.cube > x, "y2**3")
3770
+ assert(y0 <= y1, "y0 y1")
3771
+ assert(y1 <= y2, "y1 y2")
3772
+
3773
+ x = 8.to_ld(101)
3774
+ y0 = check_cbrt(x, 120, LongDecimal::ROUND_DOWN, 0, 0, "eight")
3775
+ y1 = check_cbrt(x, 120, LongDecimal::ROUND_HALF_EVEN, 0, 0, "eight")
3776
+ y2 = check_cbrt(x, 120, LongDecimal::ROUND_UP, 0, 0, "eight")
3777
+ assert_equal(y0, y1, "y0 y1")
3778
+ assert_equal(y1, y2, "y1 y2")
3779
+ end
3780
+
3781
+ #
3782
+ # test cbrt_with_remainder of LongDecimal
3783
+ #
3784
+ def test_cbrt_with_remainder
3785
+ x = LongDecimal.zero!(101)
3786
+ r = check_cbrt_with_remainder(x, 120, "zero")
3787
+ assert(r.zero?, "rcbrt(0)")
3788
+
3789
+ x = LongDecimal.one!(101)
3790
+ r = check_cbrt_with_remainder(x, 120, "one")
3791
+ assert(r.zero?, "rcbrt(1)")
3792
+
3793
+ x = LongDecimal.two!(101)
3794
+ check_cbrt_with_remainder(x, 120, "two")
3795
+ check_cbrt_with_remainder(x, 140, "two")
3796
+ check_cbrt_with_remainder(x, 160, "two")
3797
+ check_cbrt_with_remainder(x, 100, "two")
3798
+
3799
+ x = 3.to_ld
3800
+ check_cbrt_with_remainder(x, 120, "three")
3801
+ check_cbrt_with_remainder(x, 140, "three")
3802
+ check_cbrt_with_remainder(x, 160, "three")
3803
+ check_cbrt_with_remainder(x, 100, "three")
3804
+
3805
+ x = 8.to_ld.round_to_scale(101)
3806
+ r = check_cbrt_with_remainder(x, 120, "four")
3807
+ assert(r.zero?, "rcbrt(8)")
3808
+
3809
+ x = 5.to_ld
3810
+ check_cbrt_with_remainder(x, 120, "five")
3811
+ end
3812
+
3813
+ #
3814
+ # test LongMath.cbrt with non-LongDecimal arguments
3815
+ #
3816
+ def test_non_ld_cbrt
3817
+ xi = 77
3818
+ yi = LongMath.cbrt(xi, 32, LongMath::ROUND_HALF_EVEN)
3819
+ zi = yi.cube.round_to_scale(30, LongMath::ROUND_HALF_EVEN)
3820
+ assert(zi.is_int?, "zi=#{zi.to_s}")
3821
+ assert_equal(xi, zi.to_i, "zi")
3822
+
3823
+ xf = 77.0
3824
+ yf = LongMath.cbrt(xf, 32, LongMath::ROUND_HALF_EVEN)
3825
+ zf = yf.cube.round_to_scale(30, LongMath::ROUND_HALF_EVEN)
3826
+ assert(zf.is_int?, "zf")
3827
+ assert_equal(xf, zf.to_f, "zf")
3828
+ assert_equal(yi, yf, "i-f")
3829
+
3830
+ xr = Rational(224, 227)
3831
+ yr = LongMath.cbrt(xr, 32, LongMath::ROUND_HALF_EVEN)
3832
+ zr = yr.cube.round_to_scale(30, LongMath::ROUND_HALF_EVEN)
3833
+ assert((zr-xr).abs <= zr.unit, "zr-xr")
3834
+ end
3835
+
3538
3836
  #
3539
3837
  # test absolute value of LongDecimal
3540
3838
  #