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.
@@ -1,21 +1,33 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # library for testlongdecimal.rb
3
+ # library for tests for long-decimal.rb and long-decimal-extra.rb
4
4
  #
5
- # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdeclib.rb,v 1.19 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/testlongdeclib.rb,v 1.29 2009/04/21 16:56:49 bk1 Exp $
8
+ # CVS-Label: $Name: BETA_02_01 $
7
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
10
  #
9
11
 
10
12
  # load "lib/long-decimal.rb"
11
13
 
14
+ class Integer
15
+ def cube
16
+ self*self*self
17
+ end
18
+
19
+ def square
20
+ self*self
21
+ end
22
+ end
23
+
24
+
12
25
  #
13
26
  # test class for LongDecimal and LongDecimalQuot
14
27
  #
15
28
  module TestLongDecHelper
16
29
 
17
- @RCS_ID='-$Id: testlongdeclib.rb,v 1.19 2007/08/19 19:25:59 bk1 Exp $-'
18
-
30
+ @RCS_ID='-$Id: testlongdeclib.rb,v 1.29 2009/04/21 16:56:49 bk1 Exp $-'
19
31
 
20
32
  #
21
33
  # convenience method for comparing two numbers. true if and only if
@@ -405,7 +417,6 @@ module TestLongDecHelper
405
417
  v = y.unit
406
418
  # delta = (u + u.move_point_left(1)) * df
407
419
  delta = [ v * z, u * df ].max
408
- # puts("x=#{x.to_s} and z=#{z.to_s} should be almost equal (#{(x-z).abs} < d=#{delta} y=#{y.to_s} eprec=#{eprec} prec=#{prec} u=#{u.inspect} v=#{v.inspect} df=#{df})")
409
420
  assert((x - z).abs <= delta, "x=#{x.to_s} and z=#{z.to_s} should be almost equal (#{(x-z).abs} < d=#{delta} y=#{y.to_s} eprec=#{eprec} prec=#{prec})")
410
421
  end
411
422
 
@@ -428,7 +439,6 @@ module TestLongDecHelper
428
439
 
429
440
  print "."
430
441
  t0 = Time.new
431
- # print("\nstart: check_power_floated: x=#{x} y=#{y} prec=#{prec} t0=#{t0} ")
432
442
  $stdout.flush
433
443
 
434
444
  # make sure x and y are LongDecimal
@@ -438,24 +448,31 @@ module TestLongDecHelper
438
448
  y = y.to_ld
439
449
  # calculate z = x**y
440
450
  z = LongMath.power(x, y, prec)
441
- # puts("z=#{z}")
442
451
 
443
- if (z.abs < LongMath::MAX_FLOATABLE && (x - 1).abs*1000000000 > 1)
452
+ corr2 = (x - 1).abs*1000000000
453
+ if (z.abs < LongMath::MAX_FLOATABLE && corr2 > 1)
444
454
  # compare y against w = x**y calculated using regular floating point arithmetic
445
455
  xf = x.to_f
446
456
  yf = y.to_f
447
457
  wf = (xf) ** (yf)
448
458
  zf = z.to_f
449
- # puts("zf=#{zf} w=#{w}")
450
- # 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} prec=#{prec}")
451
459
  qf = 1e9
452
- delta = [ z.unit, zf.abs / qf ].max
453
- if (yf.abs > 1)
454
- l = Math.log(yf.abs)
455
- if (l > 1)
456
- delta *= l
460
+ delta = [ z.unit.to_f, zf.abs / qf ].max
461
+ # puts "delta=#{delta} z=#{z} zu=#{z.unit} zuf=#{z.unit.to_f} zf=#{zf} |zf/qf|=#{zf.abs/qf}"
462
+ if (yf.abs > 1)
463
+ l = Math.log(yf.abs)
464
+ if (l > 1)
465
+ delta *= l
457
466
  end
467
+ # puts "delta=#{delta} l=#{l}"
458
468
  end
469
+ corr = corr2 * 0.5
470
+ if corr > 1
471
+ corr_f = [ corr.to_f, 2 ].min.to_f
472
+ delta *= corr_f
473
+ end
474
+ # puts "delta=#{delta} corr_f=#{corr_f} corr=#{corr}"
475
+
459
476
  diff = (zf - wf).abs
460
477
  assert(diff <= delta, "zf=#{zf.to_s} and wf=#{wf.to_s} should be almost equal x=#{x} y=#{y} delta=#{delta} l=#{l} diff=#{diff} prec=#{prec}")
461
478
  end
@@ -504,7 +521,6 @@ module TestLongDecHelper
504
521
  # calculate y = log10(x)
505
522
  y = LongMath.log10(x, prec)
506
523
  yy = LongMath.log10(x, prec+10)
507
- # assert_equal(yy.round_to_scale(y.scale, LongDecimal::ROUND_HALF_DOWN), y, "x=#{x} y=#{y} yy=#{yy}")
508
524
  assert_equal_rounded(yy, y, "x=#{x} y=#{y} yy=#{yy}")
509
525
 
510
526
  # compare y against z = log10(x) calculated using regular floating
@@ -519,7 +535,6 @@ module TestLongDecHelper
519
535
  df = [ 1e-13, z.abs / 1e10 ].max
520
536
  dl = y.unit
521
537
  delta = [ df, dl ].max
522
- # 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}")
523
538
  assert((yf - z).abs < delta, "y=#{yf.to_s} and z=#{z.to_s} should be almost equal (x=#{x} delta=#{delta}")
524
539
  end
525
540
  end
@@ -548,7 +563,6 @@ module TestLongDecHelper
548
563
  assert((zz - z).abs <= u, "zz=#{zz.to_s} and z=#{z.to_s} should be almost equal (y=#{y.to_s} eprec=#{eprec} prec=#{prec})")
549
564
  delta = [ v*z*LongMath::LOG10*1.2, u * 1.1 ].max
550
565
  assert((x - z).abs <= delta, "x=#{x.to_s} and z=#{z.to_s} should be almost equal (y=#{y.to_s} eprec=#{eprec} prec=#{prec} delta=#{delta})")
551
- # 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})")
552
566
  end
553
567
 
554
568
  return y
@@ -600,7 +614,6 @@ module TestLongDecHelper
600
614
  df = [ 1e-13, z.abs / 1e10 ].max
601
615
  dl = y.unit.abs
602
616
  delta = [ df, dl ].max
603
- # 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}")
604
617
  assert((yf - z).abs < delta.to_f, "y=#{yf.to_s} and z=#{z.to_s} should be almost equal (x=#{x} delta=#{delta}")
605
618
  end
606
619
  end
@@ -654,8 +667,8 @@ module TestLongDecHelper
654
667
  #
655
668
  def check_sqrtb(x, s)
656
669
  y = LongMath.sqrtb(x)
657
- z = y * y
658
- zz = (y+1)*(y+1)
670
+ z = y.square
671
+ zz = (y+1).square
659
672
  assert(0 <= y, "sqrt must be >= 0" + s)
660
673
  assert(z <= x && x < zz, "y=#{y}=sqrt(#{x}) and x in [#{z}, #{zz})" + s)
661
674
  y
@@ -730,6 +743,62 @@ module TestLongDecHelper
730
743
  r
731
744
  end
732
745
 
746
+ #
747
+ # helper method for test_int_cbrtb
748
+ #
749
+ def check_cbrtb(x, s)
750
+ y = LongMath.cbrtb(x)
751
+ z = y.cube
752
+ zz = (y+1).cube
753
+ assert(0 <= y, "cbrt must be >= 0" + s)
754
+ assert(z <= x && x < zz, "y=#{y}=cbrt(#{x}) and x in [#{z}, #{zz})" + s)
755
+ y
756
+ end
757
+
758
+ #
759
+ # helper method for test_int_cbrtb_with_remainder
760
+ #
761
+ def check_cbrtb_with_remainder(x, s)
762
+ y, r = LongMath.cbrtb_with_remainder(x)
763
+ z0 = y.cube
764
+ # puts "x=#{x} y=#{y} z0=#{z0} r=#{r}"
765
+ z1 = z0 + r
766
+ z2 = (y+1).cube
767
+ assert(0 <= y, "cbrt _with_remainder must be >= 0" + s)
768
+ assert_equal(z1, x, "x=#{x} y=#{y} r=#{r} z0=#{z0} z1=#{z1} z2=#{z2}" + s)
769
+ assert(z0 <= x && x < z2, "y=#{y}=cbrt(_with_remainder#{x}) and x in [#{z0}, #{z2}) r=#{r} z0=#{z0} z1=#{z1} z2=#{z2}" + s)
770
+ y
771
+ end
772
+
773
+ #
774
+ # helper method of test_cbrt
775
+ #
776
+ def check_cbrt(x, scale, mode, su0, su1, str)
777
+ y = x.cbrt(scale, mode)
778
+ if (mode == LongMath::ROUND_HALF_UP || mode == LongMath::ROUND_HALF_DOWN || mode == LongMath::ROUND_HALF_EVEN)
779
+ yy = x.cbrt(scale+10, mode)
780
+ assert_equal(yy.round_to_scale(y.scale, mode), y, "x=#{x} y=#{y} yy=#{yy}")
781
+ end
782
+ z0 = (y+su0*y.unit).cube
783
+ z1 = (y+su1*y.unit).cube
784
+ assert(0 <= y.sign, "cbrt must be >= 0" + str)
785
+ assert(z0 <= x && x <= z1, "y=#{y}=cbrt(#{x}) and x in [#{z0}, #{z1}) su0=#{su0} su1=#{su1}" + str)
786
+ y
787
+ end
788
+
789
+ #
790
+ # helper method of test_cbrt_with_remainder
791
+ #
792
+ def check_cbrt_with_remainder(x, scale, str)
793
+ y, r = x.cbrt_with_remainder(scale)
794
+ z0 = y.cube
795
+ z1 = y.succ.cube
796
+ assert(0 <= y.sign, "cbrt must be >= 0" + str)
797
+ assert(z0 <= x && x < z1, "y=#{y}=cbrt(#{x}) and x in [#{z0}, #{z1}) " + str)
798
+ assert((x - z0 - r).zero?, "x=y**3+r x=#{x} z0=#{z0} z1=#{z1} y=#{y} r=#{r} total=#{x - z0 - r} " + str)
799
+ r
800
+ end
801
+
733
802
  end
734
803
 
735
804
  # end of file testlongdecimal.rb
data/test/testrandlib.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # testrandlib.rb -- runit test for long-decimal.rb
3
+ # testrandlib.rb -- library for random tests for long-decimal.rb and long-decimal-extra.rb
4
4
  #
5
- # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testrandlib.rb,v 1.7 2006/05/07 20:00:24 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/testrandlib.rb,v 1.9 2009/04/15 19:29:38 bk1 Exp $
8
+ # CVS-Label: $Name: BETA_02_01 $
7
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
10
  #
9
11
 
12
+ #require "rubygems"
10
13
  require "crypt/ISAAC"
11
14
 
12
15
  #
@@ -14,7 +17,7 @@ require "crypt/ISAAC"
14
17
  #
15
18
  module TestRandomHelper
16
19
 
17
- @RCS_ID='-$Id: testrandlib.rb,v 1.7 2006/05/07 20:00:24 bk1 Exp $-'
20
+ @RCS_ID='-$Id: testrandlib.rb,v 1.9 2009/04/15 19:29:38 bk1 Exp $-'
18
21
 
19
22
  @@r1 = Crypt::ISAAC.new
20
23
  @@r2 = Crypt::ISAAC.new
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # testrandom.rb -- runit test for long-decimal.rb
3
+ # testrandom-extra.rb -- randem tests for long-decimal-extra.rb
4
4
  #
5
- # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testrandom-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/testrandom-extra.rb,v 1.2 2009/04/15 19:29:38 bk1 Exp $
8
+ # CVS-Label: $Name: BETA_02_01 $
7
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
10
  #
9
11
 
@@ -25,7 +27,7 @@ class TestRandom_class < RUNIT::TestCase
25
27
  include TestLongDecHelper
26
28
  include TestRandomHelper
27
29
 
28
- @RCS_ID='-$Id: testrandom-extra.rb,v 1.1 2007/08/19 19:25:59 bk1 Exp $-'
30
+ @RCS_ID='-$Id: testrandom-extra.rb,v 1.2 2009/04/15 19:29:38 bk1 Exp $-'
29
31
 
30
32
  # for how many seconds should this test run? change to different
31
33
  # value on demand
data/test/testrandom.rb CHANGED
@@ -1,15 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # testrandom.rb -- runit test for long-decimal.rb
3
+ # testrandom.rb -- random tests for long-decimal.rb
4
4
  #
5
- # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testrandom.rb,v 1.13 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/testrandom.rb,v 1.15 2009/04/15 19:29:38 bk1 Exp $
8
+ # CVS-Label: $Name: BETA_02_01 $
7
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
10
  #
9
11
 
10
12
  require "runit/testcase"
11
13
  require "runit/cui/testrunner"
12
14
  require "runit/testsuite"
15
+
16
+ #require "rubygems"
13
17
  require "crypt/ISAAC"
14
18
 
15
19
  load "lib/long-decimal.rb"
@@ -23,7 +27,7 @@ class TestRandom_class < RUNIT::TestCase
23
27
  include TestLongDecHelper
24
28
  include TestRandomHelper
25
29
 
26
- @RCS_ID='-$Id: testrandom.rb,v 1.13 2007/08/19 19:25:59 bk1 Exp $-'
30
+ @RCS_ID='-$Id: testrandom.rb,v 1.15 2009/04/15 19:29:38 bk1 Exp $-'
27
31
 
28
32
  # for how many seconds should this test run? change to different
29
33
  # value on demand
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # testrandpower.rb -- runit test for long-decimal.rb
3
+ # testrandpower.rb -- random tests for power-method from long-decimal-extra.rb
4
4
  #
5
- # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testrandpower.rb,v 1.10 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/testrandpower.rb,v 1.12 2009/04/18 05:51:14 bk1 Exp $
8
+ # CVS-Label: $Name: BETA_02_01 $
7
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
10
  #
9
11
 
@@ -25,7 +27,7 @@ class TestRandomPower_class < RUNIT::TestCase
25
27
  include TestLongDecHelper
26
28
  include TestRandomHelper
27
29
 
28
- @RCS_ID='-$Id: testrandpower.rb,v 1.10 2007/08/19 19:25:59 bk1 Exp $-'
30
+ @RCS_ID='-$Id: testrandpower.rb,v 1.12 2009/04/18 05:51:14 bk1 Exp $-'
29
31
 
30
32
  # for how many seconds should this test run? change to different
31
33
  # value on demand
@@ -49,13 +51,9 @@ class TestRandomPower_class < RUNIT::TestCase
49
51
  xarr.each do |x|
50
52
  puts(" t=#{Time.new-t1} x=#{x}: ")
51
53
  next if x <= 0
52
- # next if (x < 1.1)
53
- # next if (x < 1)
54
- # next if (x < 0.99)
55
54
  next if x.abs > LongMath::MAX_FLOATABLE || (1/x).abs > LongMath::MAX_FLOATABLE
56
55
  yarr.each do |y|
57
56
  puts("\ncnt=#{cnt} scnt=#{scnt} x=#{x} y=#{y} scx=#{x.scale} scy=#{y.scale} prec=#{prec}")
58
- # next if x < 0.001 && y < 0
59
57
  next if x > 1 && y > LongMath::MAX_EXP_ABLE * 2
60
58
  next if x < 1 && y < -LongMath::MAX_EXP_ABLE * 2
61
59
  next if Math.log(1+x.to_i) * y.to_i > LongMath::MAX_EXP_ABLE
data/version.rb CHANGED
@@ -3,8 +3,10 @@
3
3
  #
4
4
  # version.rb -- extract version information from files
5
5
  #
6
- # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/version.rb,v 1.6 2006/04/11 19:45:40 bk1 Exp $
7
- # CVS-Label: $Name: ALPHA_01_03 $
6
+ # (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
7
+ #
8
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/version.rb,v 1.8 2009/04/18 05:51:14 bk1 Exp $
9
+ # CVS-Label: $Name: BETA_02_01 $
8
10
  # Author: $Author: bk1 $ (Karl Brodowsky)
9
11
  #
10
12
 
@@ -29,7 +31,6 @@ ARGV.each do |file|
29
31
  str = version
30
32
  end
31
33
 
32
- # print "file=#{file}\nstr=#{str}\nversion=#{version}\nname=#{name}\n";
33
34
  print str,"\n"
34
35
  end
35
36
 
metadata CHANGED
@@ -1,62 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: long-decimal
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.01.03
7
- date: 2007-08-28 00:00:00 +02:00
8
- summary: LongDecimal for numbers with fixed point
9
- require_paths:
10
- - lib
11
- email: http://www.velofahren.de/mail.html
12
- homepage: http://long-decimal.rubyforge.org/
13
- rubyforge_project: long-decimal
14
- description: ""
15
- autorequire: long-decimal
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.02.01
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Karl Brodowsky
8
+ autorequire: long-decimal
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-21 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ""
17
+ email: http://www.velofahren.de/mail.html
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
31
24
  files:
32
- - lib
33
25
  - test
34
- - Rakefile
35
- - README
36
- - install.rb
37
- - VERSION
38
- - make_doc.rb
39
- - version.rb
40
- - lib/long-decimal-extra.rb
41
- - lib/long-decimal.rb
42
- - test/testlongdecimal.rb
43
- - test/testrandpower.rb
44
- - test/testlongdecimal-extra.rb
45
26
  - test/testlongdeclib.rb
46
- - test/testrandom-extra.rb
47
27
  - test/testrandlib.rb
28
+ - test/testrandom-extra.rb
29
+ - test/testlongdecimal-extra.rb
48
30
  - test/testrandom.rb
49
- test_files:
50
31
  - test/testlongdecimal.rb
32
+ - test/testrandpower.rb
33
+ - Rakefile
34
+ - install.rb
35
+ - lib
36
+ - lib/long-decimal.rb
37
+ - lib/long-decimal-extra.rb
38
+ - VERSION
39
+ - version.rb
40
+ - make_doc.rb
41
+ - README
42
+ has_rdoc: true
43
+ homepage: http://long-decimal.rubyforge.org/
44
+ post_install_message:
51
45
  rdoc_options: []
52
46
 
53
- extra_rdoc_files: []
54
-
55
- executables: []
56
-
57
- extensions: []
58
-
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
59
61
  requirements: []
60
62
 
61
- dependencies: []
62
-
63
+ rubyforge_project: long-decimal
64
+ rubygems_version: 1.3.1
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: LongDecimal for numbers with fixed point
68
+ test_files:
69
+ - test/testlongdecimal.rb