long-decimal 0.02.01 → 1.00.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.
@@ -4,8 +4,8 @@
4
4
  #
5
5
  # (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
6
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
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdeclib.rb,v 1.41 2011/01/16 21:12:42 bk1 Exp $
8
+ # CVS-Label: $Name: RELEASE_1_00_00 $
9
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
10
10
  #
11
11
 
@@ -27,19 +27,60 @@ end
27
27
  #
28
28
  module TestLongDecHelper
29
29
 
30
- @RCS_ID='-$Id: testlongdeclib.rb,v 1.29 2009/04/21 16:56:49 bk1 Exp $-'
30
+ @RCS_ID='-$Id: testlongdeclib.rb,v 1.41 2011/01/16 21:12:42 bk1 Exp $-'
31
+
32
+ def assert_equal_float(lhs, rhs, delta=0, msg="")
33
+ if ((lhs - rhs).abs >= delta)
34
+ msg2 = "delta=#{delta} #{msg}"
35
+ assert_equal(lhs, rhs, msg2)
36
+ end
37
+ end
38
+
39
+ def assert_equal_rbo(lhs, rhs, msg="", lhsname="lhs", rhsname="rhs", delta=0)
40
+ msg2 = "#{lhsname}=#{lhs} #{rhsname}=#{rhs} " + msg
41
+ if (lhs.kind_of? Rational) && (rhs.kind_of? BigDecimal) || (lhs.kind_of? BigDecimal) && (rhs.kind_of? Rational)
42
+ assert_equal(lhs.to_ld, rhs.to_ld, msg2)
43
+ elsif (delta > 0 && ((lhs.kind_of? Float) || (rhs.kind_of? Float)))
44
+ assert_equal_float(lhs, rhs, delta, msg2 + " d=#{delta}")
45
+ else
46
+ assert_equal(lhs, rhs, msg2)
47
+ end
48
+ end
49
+
50
+ def assert_equal_complex(lhs, rhs, msg="", delta=0)
51
+ msg2 = "lhs=#{lhs} rhs=#{rhs} " + msg
52
+ assert_equal_rbo(lhs.real, rhs.real, "real: #{lhs.real==rhs.real} " + msg2, "lhsr", "rhsr", delta)
53
+ assert_equal_rbo(lhs.image, rhs.image, "imag: #{lhs.image==rhs.image} " + msg2, "lhsi", "rhsi", delta)
54
+ end
55
+
56
+ #
57
+ # convenience method for comparing two numbers. true if and only if
58
+ # they express the same value
59
+ #
60
+ def assert_eql(expected, actual, message="")
61
+ full_message = build_message(message, "Expected <?> to match <?>", actual, expected)
62
+ assert((expected.eql? actual), full_message)
63
+ # _wrap_assertion {
64
+ # full_message = build_message(message, "Expected <?> to match <?>", actual, expected)
65
+ # assert_block(full_message) {
66
+ # (expected <=> actual).zero?
67
+ # }
68
+ # }
69
+ end
31
70
 
32
71
  #
33
72
  # convenience method for comparing two numbers. true if and only if
34
73
  # they express the same value
35
74
  #
36
75
  def assert_val_equal(expected, actual, message="")
37
- _wrap_assertion {
38
- full_message = build_message(message, "Expected <?> to match <?>", actual, expected)
39
- assert_block(full_message) {
40
- (expected <=> actual).zero?
41
- }
42
- }
76
+ full_message = build_message(message, "Expected <?> to match <?>", actual, expected)
77
+ assert((expected <=> actual).zero?, full_message)
78
+ # _wrap_assertion {
79
+ # full_message = build_message(message, "Expected <?> to match <?>", actual, expected)
80
+ # assert_block(full_message) {
81
+ # (expected <=> actual).zero?
82
+ # }
83
+ # }
43
84
  end
44
85
 
45
86
  #
@@ -53,22 +94,27 @@ module TestLongDecHelper
53
94
  # one of these is used.
54
95
  #
55
96
  def assert_equal_rounded(expected, actual, message="")
56
- _wrap_assertion {
57
- lhs = (expected - actual).abs()*2000
58
- rhs = actual.unit.abs()*1001
59
- full_message = build_message(message, "Expected <?> to match <?> (lhs=#{lhs} rhs=#{rhs})", actual, expected)
60
- assert_block(full_message) {
61
- # prec = actual.scale
62
- # ed = expected.round_to_scale(prec, LongMath::ROUND_HALF_FLOOR)
63
- # eu = expected.round_to_scale(prec, LongMath::ROUND_HALF_CEILING)
64
- # # puts("ed=#{ed} eu=#{eu} e=#{expected} a=#{actual}")
65
- # ed <= actual && actual <= eu
66
-
67
- # (expected - actual).abs < (actual.unit()/2)*(1001/1000)
68
- # (expected - actual).abs()*2000 < actual.unit()*1001
69
- lhs < rhs
70
- }
71
- }
97
+ lhs = (expected - actual).abs()*2000
98
+ rhs = actual.unit.abs()*1001
99
+ full_message = build_message(message, "Expected <?> to match <?> (lhs=#{lhs} rhs=#{rhs})", actual, expected)
100
+ assert(lhs < rhs, full_message)
101
+
102
+ # _wrap_assertion {
103
+ # lhs = (expected - actual).abs()*2000
104
+ # rhs = actual.unit.abs()*1001
105
+ # full_message = build_message(message, "Expected <?> to match <?> (lhs=#{lhs} rhs=#{rhs})", actual, expected)
106
+ # assert_block(full_message) {
107
+ # # prec = actual.scale
108
+ # # ed = expected.round_to_scale(prec, LongMath::ROUND_HALF_FLOOR)
109
+ # # eu = expected.round_to_scale(prec, LongMath::ROUND_HALF_CEILING)
110
+ # # # puts("ed=#{ed} eu=#{eu} e=#{expected} a=#{actual}")
111
+ # # ed <= actual && actual <= eu
112
+
113
+ # # (expected - actual).abs < (actual.unit()/2)*(1001/1000)
114
+ # # (expected - actual).abs()*2000 < actual.unit()*1001
115
+ # lhs < rhs
116
+ # }
117
+ # }
72
118
  end
73
119
 
74
120
  #
@@ -77,16 +123,22 @@ module TestLongDecHelper
77
123
  # interval is a unit at most.
78
124
  #
79
125
  def assert_small_interval(yd, yu, y, message="")
80
- _wrap_assertion {
81
- if (yu < yd) then
82
- yd, yu = yu, yd
83
- end
84
- full_message = build_message(message, "Expected interval [<?>, <?>] to be one unit at most and to contain <?>", yd, yu, y)
85
- assert_block(full_message) {
86
- prec = y.scale
87
- yd <= y && y <= yu && yu - yd <= y.unit
88
- }
89
- }
126
+ if (yu < yd) then
127
+ yd, yu = yu, yd
128
+ end
129
+ full_message = build_message(message, "Expected interval [<?>, <?>] to be one unit at most and to contain <?>", yd, yu, y)
130
+ prec = y.scale
131
+ assert(yd <= y && y <= yu && yu - yd <= y.unit, full_message)
132
+ # _wrap_assertion {
133
+ # if (yu < yd) then
134
+ # yd, yu = yu, yd
135
+ # end
136
+ # full_message = build_message(message, "Expected interval [<?>, <?>] to be one unit at most and to contain <?>", yd, yu, y)
137
+ # assert_block(full_message) {
138
+ # prec = y.scale
139
+ # yd <= y && y <= yu && yu - yd <= y.unit
140
+ # }
141
+ # }
90
142
  end
91
143
 
92
144
  #
@@ -131,7 +183,7 @@ module TestLongDecHelper
131
183
  # compare y against z = exp(x) calculated using regular floating point arithmetic
132
184
  z = Math.exp(x.to_f)
133
185
  yf = y.to_f
134
- 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}")
186
+ 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} d=#{yf - z}")
135
187
 
136
188
  # check by taking log(exp(x))
137
189
  # we have to take into account that we might not have enough
@@ -373,7 +425,7 @@ module TestLongDecHelper
373
425
  # assert_equal(yy.round_to_scale(y.scale, LongDecimal::ROUND_HALF_DOWN), y, "x=#{x} y=#{y} yy=#{yy}")
374
426
  assert_equal_rounded(yy, y, "x=#{x} y=#{y} yy=#{yy}")
375
427
 
376
- # compare y against z = exp(x) calculated using regular floating
428
+ # compare y against z = log(x) calculated using regular floating
377
429
  # point arithmetic
378
430
  if (x <= LongMath::MAX_FLOATABLE) then
379
431
  xf = x.to_f
@@ -385,7 +437,7 @@ module TestLongDecHelper
385
437
  dl = y.unit
386
438
  # delta = [ y.unit, z.abs / divisor + summand ].max
387
439
  delta = [ df, dl ].max
388
- 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.inspect} x=#{x} y=#{y})")
440
+ assert((y - zl).abs <= delta, "y=#{y.to_s} (#{y.to_f}) and z=#{z.to_s} (#{zl}=#{zl.to_f}) should be almost equal (delta=#{delta.inspect} d=#{y - zl}=#{(y - zl).to_f} x=#{x} y=#{y}=#{y.to_f})")
389
441
  end
390
442
  end
391
443
 
@@ -438,7 +490,6 @@ module TestLongDecHelper
438
490
  def check_power_floated(x, y, prec)
439
491
 
440
492
  print "."
441
- t0 = Time.new
442
493
  $stdout.flush
443
494
 
444
495
  # make sure x and y are LongDecimal
@@ -449,7 +500,7 @@ module TestLongDecHelper
449
500
  # calculate z = x**y
450
501
  z = LongMath.power(x, y, prec)
451
502
 
452
- corr2 = (x - 1).abs*1000000000
503
+ corr2 = (x - 1).abs*1000000000 # 10**9
453
504
  if (z.abs < LongMath::MAX_FLOATABLE && corr2 > 1)
454
505
  # compare y against w = x**y calculated using regular floating point arithmetic
455
506
  xf = x.to_f
@@ -468,13 +519,13 @@ module TestLongDecHelper
468
519
  end
469
520
  corr = corr2 * 0.5
470
521
  if corr > 1
471
- corr_f = [ corr.to_f, 2 ].min.to_f
522
+ corr_f = [ corr.to_f, 5.0 ].min
472
523
  delta *= corr_f
473
524
  end
474
525
  # puts "delta=#{delta} corr_f=#{corr_f} corr=#{corr}"
475
526
 
476
527
  diff = (zf - wf).abs
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}")
528
+ assert_equal_float(zf, wf, delta, "z=#{z}=#{zf} and wf=#{wf.to_s} should be almost equal x=#{x}=#{xf} y=#{y}=#{yf} delta=#{delta} l=#{l} diff=#{diff} prec=#{prec} corr=#{corr}=#{corr.to_f} corr2=#{corr2}=#{corr2.to_f} corr_f=#{corr_f}")
478
529
  end
479
530
 
480
531
  # check by taking log(z) = y * log(x)
@@ -501,7 +552,7 @@ module TestLongDecHelper
501
552
  u = LongMath.log(z, lprec)
502
553
  v = LongMath.log(x, lprec+l10y)
503
554
  yv = (y*v).round_to_scale(lprec, LongDecimal::ROUND_HALF_DOWN)
504
- 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})")
555
+ assert((u - yv).abs <= unit, "u=log(z,#{lprec})=#{u} and yv=y*v=y*log(x,#{lprec+l10y})=#{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})")
505
556
  end
506
557
 
507
558
  end
@@ -5,7 +5,7 @@
5
5
  # (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
6
6
  #
7
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 $
8
+ # CVS-Label: $Name: RELEASE_1_00_00 $
9
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
10
10
  #
11
11
 
@@ -4,8 +4,8 @@
4
4
  #
5
5
  # (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
6
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
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testrandom-extra.rb,v 1.4 2009/05/09 15:37:00 bk1 Exp $
8
+ # CVS-Label: $Name: RELEASE_1_00_00 $
9
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
10
10
  #
11
11
 
@@ -20,6 +20,8 @@ load "lib/long-decimal-extra.rb"
20
20
  load "test/testlongdeclib.rb"
21
21
  load "test/testrandlib.rb"
22
22
 
23
+ LongMath.prec_overflow_handling = :warn_use_max
24
+
23
25
  #
24
26
  # test class for LongDecimal and LongDecimalQuot
25
27
  #
@@ -27,7 +29,7 @@ class TestRandom_class < RUNIT::TestCase
27
29
  include TestLongDecHelper
28
30
  include TestRandomHelper
29
31
 
30
- @RCS_ID='-$Id: testrandom-extra.rb,v 1.2 2009/04/15 19:29:38 bk1 Exp $-'
32
+ @RCS_ID='-$Id: testrandom-extra.rb,v 1.4 2009/05/09 15:37:00 bk1 Exp $-'
31
33
 
32
34
  # for how many seconds should this test run? change to different
33
35
  # value on demand
@@ -4,8 +4,8 @@
4
4
  #
5
5
  # (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
6
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
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testrandom.rb,v 1.17 2009/05/09 15:37:00 bk1 Exp $
8
+ # CVS-Label: $Name: RELEASE_1_00_00 $
9
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
10
10
  #
11
11
 
@@ -20,6 +20,8 @@ load "lib/long-decimal.rb"
20
20
  load "test/testlongdeclib.rb"
21
21
  load "test/testrandlib.rb"
22
22
 
23
+ LongMath.prec_overflow_handling = :warn_use_max
24
+
23
25
  #
24
26
  # test class for LongDecimal and LongDecimalQuot
25
27
  #
@@ -27,7 +29,7 @@ class TestRandom_class < RUNIT::TestCase
27
29
  include TestLongDecHelper
28
30
  include TestRandomHelper
29
31
 
30
- @RCS_ID='-$Id: testrandom.rb,v 1.15 2009/04/15 19:29:38 bk1 Exp $-'
32
+ @RCS_ID='-$Id: testrandom.rb,v 1.17 2009/05/09 15:37:00 bk1 Exp $-'
31
33
 
32
34
  # for how many seconds should this test run? change to different
33
35
  # value on demand
@@ -4,8 +4,8 @@
4
4
  #
5
5
  # (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
6
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
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testrandpower.rb,v 1.14 2009/05/09 15:37:00 bk1 Exp $
8
+ # CVS-Label: $Name: RELEASE_1_00_00 $
9
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
10
10
  #
11
11
 
@@ -20,6 +20,8 @@ load "lib/long-decimal-extra.rb"
20
20
  load "test/testlongdeclib.rb"
21
21
  load "test/testrandlib.rb"
22
22
 
23
+ LongMath.prec_overflow_handling = :warn_use_max
24
+
23
25
  #
24
26
  # test class for LongDecimal and LongDecimalQuot
25
27
  #
@@ -27,7 +29,7 @@ class TestRandomPower_class < RUNIT::TestCase
27
29
  include TestLongDecHelper
28
30
  include TestRandomHelper
29
31
 
30
- @RCS_ID='-$Id: testrandpower.rb,v 1.12 2009/04/18 05:51:14 bk1 Exp $-'
32
+ @RCS_ID='-$Id: testrandpower.rb,v 1.14 2009/05/09 15:37:00 bk1 Exp $-'
31
33
 
32
34
  # for how many seconds should this test run? change to different
33
35
  # value on demand
data/version.rb CHANGED
@@ -5,8 +5,8 @@
5
5
  #
6
6
  # (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
7
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
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/version.rb,v 1.9 2011/01/22 12:34:39 bk1 Exp $
9
+ # CVS-Label: $Name: RELEASE_1_00_00 $
10
10
  # Author: $Author: bk1 $ (Karl Brodowsky)
11
11
  #
12
12
 
@@ -27,6 +27,8 @@ ARGV.each do |file|
27
27
  str = ""
28
28
  if name =~ /(PRE_ALPHA|ALPHA|BETA)_(\d+)_(\d+)/ then
29
29
  str = sprintf("0.%02d.%02d", $2.to_i, $3.to_i)
30
+ elsif name =~ /RELEASE_(\d+)_(\d+)_(\d+)/
31
+ str = sprintf("%d.%02d.%02d", $1.to_i, $2.to_i, $3.to_i)
30
32
  else
31
33
  str = version
32
34
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: long-decimal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.02.01
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.00.01
5
10
  platform: ruby
6
11
  authors:
7
12
  - Karl Brodowsky
@@ -9,7 +14,7 @@ autorequire: long-decimal
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-04-21 00:00:00 +02:00
17
+ date: 2011-01-23 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -22,48 +27,53 @@ extensions: []
22
27
  extra_rdoc_files: []
23
28
 
24
29
  files:
25
- - test
26
- - test/testlongdeclib.rb
27
- - test/testrandlib.rb
30
+ - version.rb
31
+ - README
32
+ - lib/long-decimal.rb
33
+ - lib/long-decimal-extra.rb
28
34
  - test/testrandom-extra.rb
29
- - test/testlongdecimal-extra.rb
30
- - test/testrandom.rb
31
35
  - test/testlongdecimal.rb
36
+ - test/testlongdecimal-performance.rb
37
+ - test/testrandom.rb
32
38
  - test/testrandpower.rb
33
- - Rakefile
34
- - install.rb
35
- - lib
36
- - lib/long-decimal.rb
37
- - lib/long-decimal-extra.rb
39
+ - test/testrandlib.rb
40
+ - test/testlongdeclib.rb
41
+ - test/testlongdecimal-extra.rb
38
42
  - VERSION
39
- - version.rb
43
+ - install.rb
40
44
  - make_doc.rb
41
- - README
45
+ - Rakefile
42
46
  has_rdoc: true
43
47
  homepage: http://long-decimal.rubyforge.org/
48
+ licenses: []
49
+
44
50
  post_install_message:
45
51
  rdoc_options: []
46
52
 
47
53
  require_paths:
48
54
  - lib
49
55
  required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
50
57
  requirements:
51
58
  - - ">="
52
59
  - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
53
62
  version: "0"
54
- version:
55
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
56
65
  requirements:
57
66
  - - ">="
58
67
  - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
59
70
  version: "0"
60
- version:
61
71
  requirements: []
62
72
 
63
73
  rubyforge_project: long-decimal
64
- rubygems_version: 1.3.1
74
+ rubygems_version: 1.3.7
65
75
  signing_key:
66
- specification_version: 2
76
+ specification_version: 3
67
77
  summary: LongDecimal for numbers with fixed point
68
78
  test_files:
69
79
  - test/testlongdecimal.rb