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.
@@ -0,0 +1,357 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # testlongdecimal.rb -- runit test for long-decimal.rb
4
+ #
5
+ # (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
6
+ #
7
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal-performance.rb,v 1.2 2011/01/16 18:12:51 bk1 Exp $
8
+ # CVS-Label: $Name: RELEASE_1_00_00 $
9
+ # Author: $Author: bk1 $ (Karl Brodowsky)
10
+ #
11
+
12
+ require 'test/unit'
13
+
14
+ # require "runit/testcase"
15
+ # require "runit/cui/testrunner"
16
+ # require "runit/testsuite"
17
+
18
+ load "lib/long-decimal.rb"
19
+ load "lib/long-decimal-extra.rb"
20
+ load "test/testlongdeclib.rb"
21
+
22
+ LongMath.prec_overflow_handling = :warn_use_max
23
+
24
+ #
25
+ # test class for LongDecimal and LongDecimalQuot
26
+ #
27
+ class TestLongDecimalExtra_class < Test::Unit::TestCase # RUNIT::TestCase
28
+ include TestLongDecHelper
29
+
30
+ @RCS_ID='-$Id: testlongdecimal-performance.rb,v 1.2 2011/01/16 18:12:51 bk1 Exp $-'
31
+
32
+ MAX_FLOAT_I = (Float::MAX).to_i
33
+
34
+ #
35
+ # compare sqrt-methods
36
+ #
37
+ def test_sqrtx
38
+ print "\ntest_sqrtx [#{Time.now}]: "
39
+ n = 100000
40
+ y1 = []
41
+ y2 = []
42
+ y3 = []
43
+ t1 = Time.new
44
+ n.times do |i|
45
+ y1[i] = LongMath.sqrtb(i)
46
+ end
47
+ puts "sqrtb done"
48
+ t2 = Time.new
49
+ n.times do |i|
50
+ y2[i] = LongMath.sqrtw(i)
51
+ end
52
+ puts "sqrtw done"
53
+ t3 = Time.new
54
+ n.times do |i|
55
+ y3[i] = LongMath.sqrtn(i)
56
+ end
57
+ puts "sqrtn done"
58
+ t4 = Time.new
59
+ t4-=t3
60
+ t3-=t2
61
+ t2-=t1
62
+ puts "t2=#{t2} t3=#{t3} t4=#{t4}"
63
+ n.times do |i|
64
+ assert_equal(y1[i], y2[i], "i=#{i}")
65
+ assert_equal(y2[i], y3[i], "i=#{i}")
66
+ assert_equal(y3[i], y1[i], "i=#{i}")
67
+ end
68
+ puts "test_sqrtx done"
69
+ end
70
+
71
+ def fsqrtx2(i)
72
+ 1001+i**3+202*i**2+603*i
73
+ end
74
+
75
+ #
76
+ # compare sqrt-methods
77
+ #
78
+ def test_sqrtx2
79
+ print "\ntest_sqrtx [#{Time.now}]: "
80
+ n = 100000
81
+ y1 = []
82
+ y2 = []
83
+ y3 = []
84
+ t1 = Time.new
85
+ n.times do |i|
86
+ x = fsqrtx2(i)
87
+ y1[i] = LongMath.sqrtb(x)
88
+ end
89
+ puts "sqrtb done"
90
+ t2 = Time.new
91
+ n.times do |i|
92
+ x = fsqrtx2(i)
93
+ y2[i] = LongMath.sqrtw(x)
94
+ end
95
+ puts "sqrtw done"
96
+ t3 = Time.new
97
+ n.times do |i|
98
+ x = fsqrtx2(i)
99
+ y3[i] = LongMath.sqrtn(x)
100
+ end
101
+ puts "sqrtn done"
102
+ t4 = Time.new
103
+ t4-=t3
104
+ t3-=t2
105
+ t2-=t1
106
+ puts "t2=#{t2} t3=#{t3} t4=#{t4}"
107
+ n.times do |i|
108
+ assert_equal(y1[i], y2[i], "i=#{i}")
109
+ assert_equal(y2[i], y3[i], "i=#{i}")
110
+ assert_equal(y3[i], y1[i], "i=#{i}")
111
+ end
112
+ puts "test_sqrtx done"
113
+ end
114
+
115
+ #
116
+ # test sint_digits10_2 of LongDecimal
117
+ #
118
+ def _test_int_log2
119
+ print "\ntest_int_log2 [#{Time.now}]: "
120
+ $stdout.flush
121
+ n = 10000
122
+ m = 10**200
123
+ t0 = Time.new
124
+ a1 = (1..n).collect do |r|
125
+ x = m*r+7
126
+ LongMath.log2int(x)
127
+ end
128
+ t1 = Time.new
129
+ puts "t=#{t1-t0}"
130
+ $stdout.flush
131
+ a2 = (1..n).collect do |r|
132
+ x = m*r+7
133
+ Math.log(x)/Math.log(2)
134
+ end
135
+ t2 = Time.new
136
+ puts "t=#{t2-t1}"
137
+ $stdout.flush
138
+ a3 = (1..n).collect do |r|
139
+ x = m*r+7
140
+ LongMath.log2(x, 1).to_f
141
+ end
142
+ t3 = Time.new
143
+ puts "t=#{t3-t2}"
144
+ $stdout.flush
145
+ t3 -= t2
146
+ t2 -= t1
147
+ t1 -= t0
148
+ puts "t0=#{t0} t1=#{t1} t2=#{t2} t3=#{t3}"
149
+ n.times do |i|
150
+ unless (a1[i] <= a2[i] && a2[i] <= a1[i] + 0.1)
151
+ r = i+1
152
+ x = m*r+7
153
+ assert_equal(a1[i], a2[i], "i=#{i} x=#{x}")
154
+ end
155
+ assert((a2[i] - a3[i]).abs <= 0.01)
156
+ assert((a3[i] - a1[i]).abs <= 0.1)
157
+ end
158
+ puts Time.new - t0
159
+ end
160
+
161
+ #
162
+ # test sint_digits10_2 of LongDecimal
163
+ #
164
+ def _test_sint_digits10_1
165
+ print "\ntest_sint_digits10_1 [#{Time.now}]: "
166
+ t0 = Time.new
167
+ assert_equal(-4, LongDecimal("0.0000").sint_digits10, "0.0000")
168
+ assert_equal(-3, LongDecimal("0.0009").sint_digits10, "0.0009")
169
+ assert_equal(-2, LongDecimal("0.0099").sint_digits10, "0.0099")
170
+ assert_equal(-1, LongDecimal("0.0999").sint_digits10, "0.0999")
171
+ assert_equal(0, LongDecimal("0.9999").sint_digits10, "0.9999")
172
+ assert_equal(1, LongDecimal("1.0000").sint_digits10, "1.0000")
173
+ assert_equal(1, LongDecimal("9.9999").sint_digits10, "9.9999")
174
+ assert_equal(2, LongDecimal("10.0000").sint_digits10, "10.0000")
175
+ assert_equal(2, LongDecimal("99.9999").sint_digits10, "99.9999")
176
+ assert_equal(3, LongDecimal("100.0000").sint_digits10, "100.0000")
177
+ assert_equal(3, LongDecimal("999.9999").sint_digits10, "999.9999")
178
+
179
+ assert_equal(-4, LongDecimal("-0.0000").sint_digits10, "-0.0000")
180
+ assert_equal(0, LongDecimal("-0.9999").sint_digits10, "-0.9999")
181
+ assert_equal(1, LongDecimal("-1.0000").sint_digits10, "-1.0000")
182
+ assert_equal(1, LongDecimal("-9.9999").sint_digits10, "-9.9999")
183
+ assert_equal(2, LongDecimal("-10.0000").sint_digits10, "-10.0000")
184
+ assert_equal(2, LongDecimal("-99.9999").sint_digits10, "-99.9999")
185
+ assert_equal(3, LongDecimal("-100.0000").sint_digits10, "-100.0000")
186
+ assert_equal(3, LongDecimal("-999.9999").sint_digits10, "-999.9999")
187
+ x = 1234.to_ld
188
+ assert_equal(4, x.sint_digits10, "1234")
189
+ assert_equal(4, x.sint_digits10, "1234")
190
+ x = 1234.to_ld(10)
191
+ assert_equal(4, x.sint_digits10, "1234")
192
+ assert_equal(4, x.sint_digits10, "1234")
193
+
194
+ x = (10**400).to_ld(10)
195
+ assert_equal(401, (x+1).sint_digits10, "1e400+1")
196
+ assert_equal(401, x.sint_digits10, "1e400")
197
+ assert_equal(400, (x-1).sint_digits10, "1e400-1")
198
+ x = (10**200).to_ld(10)
199
+ assert_equal(201, (x+1).sint_digits10, "1e200+1")
200
+ assert_equal(201, x.sint_digits10, "1e200")
201
+ assert_equal(200, (x-1).sint_digits10, "1e200-1")
202
+ x = (10**100).to_ld(10)
203
+ assert_equal(101, (x+1).sint_digits10, "1e100+1")
204
+ assert_equal(101, x.sint_digits10, "1e100")
205
+ assert_equal(100, (x-1).sint_digits10, "1e100-1")
206
+ puts Time.new - t0
207
+ end
208
+
209
+ #
210
+ # test sint_digits10_2 of LongDecimal
211
+ #
212
+ def _test_sint_digits10_2
213
+ print "\ntest_sint_digits10_2 [#{Time.now}]: "
214
+ t0 = Time.new
215
+ assert_equal(-4, LongDecimal("0.0000").sint_digits10_2, "0.0000")
216
+ assert_equal(-3, LongDecimal("0.0009").sint_digits10_2, "0.0009")
217
+ assert_equal(-2, LongDecimal("0.0099").sint_digits10_2, "0.0099")
218
+ assert_equal(-1, LongDecimal("0.0999").sint_digits10_2, "0.0999")
219
+ assert_equal(0, LongDecimal("0.9999").sint_digits10_2, "0.9999")
220
+ assert_equal(1, LongDecimal("1.0000").sint_digits10_2, "1.0000")
221
+ assert_equal(1, LongDecimal("9.9999").sint_digits10_2, "9.9999")
222
+ assert_equal(2, LongDecimal("10.0000").sint_digits10_2, "10.0000")
223
+ assert_equal(2, LongDecimal("99.9999").sint_digits10_2, "99.9999")
224
+ assert_equal(3, LongDecimal("100.0000").sint_digits10_2, "100.0000")
225
+ assert_equal(3, LongDecimal("999.9999").sint_digits10_2, "999.9999")
226
+
227
+ assert_equal(-4, LongDecimal("-0.0000").sint_digits10_2, "-0.0000")
228
+ assert_equal(0, LongDecimal("-0.9999").sint_digits10_2, "-0.9999")
229
+ assert_equal(1, LongDecimal("-1.0000").sint_digits10_2, "-1.0000")
230
+ assert_equal(1, LongDecimal("-9.9999").sint_digits10_2, "-9.9999")
231
+ assert_equal(2, LongDecimal("-10.0000").sint_digits10_2, "-10.0000")
232
+ assert_equal(2, LongDecimal("-99.9999").sint_digits10_2, "-99.9999")
233
+ assert_equal(3, LongDecimal("-100.0000").sint_digits10_2, "-100.0000")
234
+ assert_equal(3, LongDecimal("-999.9999").sint_digits10_2, "-999.9999")
235
+ x = 1234.to_ld
236
+ assert_equal(4, x.sint_digits10_2, "1234")
237
+ assert_equal(4, x.sint_digits10_2, "1234")
238
+ x = 1234.to_ld(10)
239
+ assert_equal(4, x.sint_digits10_2, "1234")
240
+ assert_equal(4, x.sint_digits10_2, "1234")
241
+
242
+ x = (10**400).to_ld(10)
243
+ assert_equal(401, (x+1).sint_digits10_2, "1e400+1")
244
+ assert_equal(401, x.sint_digits10_2, "1e400")
245
+ assert_equal(400, (x-1).sint_digits10_2, "1e400-1")
246
+ x = (10**200).to_ld(10)
247
+ assert_equal(201, (x+1).sint_digits10_2, "1e200+1")
248
+ assert_equal(201, x.sint_digits10_2, "1e200")
249
+ assert_equal(200, (x-1).sint_digits10_2, "1e200-1")
250
+ x = (10**100).to_ld(10)
251
+ assert_equal(101, (x+1).sint_digits10_2, "1e100+1")
252
+ assert_equal(101, x.sint_digits10_2, "1e100")
253
+ assert_equal(100, (x-1).sint_digits10_2, "1e100-1")
254
+ puts Time.new - t0
255
+ end
256
+
257
+ #
258
+ # test sint_digits10_3 of LongDecimal
259
+ #
260
+ def _test_sint_digits10_3
261
+ print "\ntest_sint_digits10_3 [#{Time.now}]: "
262
+ t0 = Time.new
263
+ assert_equal(-4, LongDecimal("0.0000").sint_digits10_3, "0.0000")
264
+ assert_equal(-3, LongDecimal("0.0009").sint_digits10_3, "0.0009")
265
+ assert_equal(-2, LongDecimal("0.0099").sint_digits10_3, "0.0099")
266
+ assert_equal(-1, LongDecimal("0.0999").sint_digits10_3, "0.0999")
267
+ assert_equal(0, LongDecimal("0.9999").sint_digits10_3, "0.9999")
268
+ assert_equal(1, LongDecimal("1.0000").sint_digits10_3, "1.0000")
269
+ assert_equal(1, LongDecimal("9.9999").sint_digits10_3, "9.9999")
270
+ assert_equal(2, LongDecimal("10.0000").sint_digits10_3, "10.0000")
271
+ assert_equal(2, LongDecimal("99.9999").sint_digits10_3, "99.9999")
272
+ assert_equal(3, LongDecimal("100.0000").sint_digits10_3, "100.0000")
273
+ assert_equal(3, LongDecimal("999.9999").sint_digits10_3, "999.9999")
274
+
275
+ assert_equal(-4, LongDecimal("-0.0000").sint_digits10_3, "-0.0000")
276
+ assert_equal(0, LongDecimal("-0.9999").sint_digits10_3, "-0.9999")
277
+ assert_equal(1, LongDecimal("-1.0000").sint_digits10_3, "-1.0000")
278
+ assert_equal(1, LongDecimal("-9.9999").sint_digits10_3, "-9.9999")
279
+ assert_equal(2, LongDecimal("-10.0000").sint_digits10_3, "-10.0000")
280
+ assert_equal(2, LongDecimal("-99.9999").sint_digits10_3, "-99.9999")
281
+ assert_equal(3, LongDecimal("-100.0000").sint_digits10_3, "-100.0000")
282
+ assert_equal(3, LongDecimal("-999.9999").sint_digits10_3, "-999.9999")
283
+ x = 1234.to_ld
284
+ assert_equal(4, x.sint_digits10_3, "1234")
285
+ assert_equal(4, x.sint_digits10_3, "1234")
286
+ x = 1234.to_ld(10)
287
+ assert_equal(4, x.sint_digits10_3, "1234")
288
+ assert_equal(4, x.sint_digits10_3, "1234")
289
+
290
+ x = (10**400).to_ld(10)
291
+ assert_equal(401, (x+1).sint_digits10_3, "1e400+1")
292
+ assert_equal(401, x.sint_digits10_3, "1e400")
293
+ assert_equal(400, (x-1).sint_digits10_3, "1e400-1")
294
+ x = (10**200).to_ld(10)
295
+ assert_equal(201, (x+1).sint_digits10_3, "1e200+1")
296
+ assert_equal(201, x.sint_digits10_3, "1e200")
297
+ assert_equal(200, (x-1).sint_digits10_3, "1e200-1")
298
+ x = (10**100).to_ld(10)
299
+ assert_equal(101, (x+1).sint_digits10_3, "1e100+1")
300
+ assert_equal(101, x.sint_digits10_3, "1e100")
301
+ assert_equal(100, (x-1).sint_digits10_3, "1e100-1")
302
+ puts Time.new - t0
303
+ end
304
+
305
+ #
306
+ # test sint_digits10_4 of LongDecimal
307
+ #
308
+ def _test_sint_digits10_4
309
+ print "\ntest_sint_digits10_4 [#{Time.now}] (7 min): "
310
+ t0 = Time.new
311
+ assert_equal(-4, LongDecimal("0.0000").sint_digits10_4, "0.0000")
312
+ assert_equal(-3, LongDecimal("0.0009").sint_digits10_4, "0.0009")
313
+ assert_equal(-2, LongDecimal("0.0099").sint_digits10_4, "0.0099")
314
+ assert_equal(-1, LongDecimal("0.0999").sint_digits10_4, "0.0999")
315
+ assert_equal(0, LongDecimal("0.9999").sint_digits10_4, "0.9999")
316
+ assert_equal(1, LongDecimal("1.0000").sint_digits10_4, "1.0000")
317
+ assert_equal(1, LongDecimal("9.9999").sint_digits10_4, "9.9999")
318
+ assert_equal(2, LongDecimal("10.0000").sint_digits10_4, "10.0000")
319
+ assert_equal(2, LongDecimal("99.9999").sint_digits10_4, "99.9999")
320
+ assert_equal(3, LongDecimal("100.0000").sint_digits10_4, "100.0000")
321
+ assert_equal(3, LongDecimal("999.9999").sint_digits10_4, "999.9999")
322
+
323
+ assert_equal(-4, LongDecimal("-0.0000").sint_digits10_4, "-0.0000")
324
+ assert_equal(0, LongDecimal("-0.9999").sint_digits10_4, "-0.9999")
325
+ assert_equal(1, LongDecimal("-1.0000").sint_digits10_4, "-1.0000")
326
+ assert_equal(1, LongDecimal("-9.9999").sint_digits10_4, "-9.9999")
327
+ assert_equal(2, LongDecimal("-10.0000").sint_digits10_4, "-10.0000")
328
+ assert_equal(2, LongDecimal("-99.9999").sint_digits10_4, "-99.9999")
329
+ assert_equal(3, LongDecimal("-100.0000").sint_digits10_4, "-100.0000")
330
+ assert_equal(3, LongDecimal("-999.9999").sint_digits10_4, "-999.9999")
331
+ x = 1234.to_ld
332
+ assert_equal(4, x.sint_digits10_4, "1234")
333
+ assert_equal(4, x.sint_digits10_4, "1234")
334
+ x = 1234.to_ld(10)
335
+ assert_equal(4, x.sint_digits10_4, "1234")
336
+ assert_equal(4, x.sint_digits10_4, "1234")
337
+
338
+ x = (10**400).to_ld(10)
339
+ assert_equal(401, (x+1).sint_digits10_4, "1e400+1")
340
+ assert_equal(401, x.sint_digits10_4, "1e400")
341
+ assert_equal(400, (x-1).sint_digits10_4, "1e400-1")
342
+ x = (10**200).to_ld(10)
343
+ assert_equal(201, (x+1).sint_digits10_4, "1e200+1")
344
+ assert_equal(201, x.sint_digits10_4, "1e200")
345
+ assert_equal(200, (x-1).sint_digits10_4, "1e200-1")
346
+ x = (10**100).to_ld(10)
347
+ assert_equal(101, (x+1).sint_digits10_4, "1e100+1")
348
+ assert_equal(101, x.sint_digits10_4, "1e100")
349
+ assert_equal(100, (x-1).sint_digits10_4, "1e100-1")
350
+ puts Time.new - t0
351
+ end
352
+
353
+ end
354
+
355
+ # RUNIT::CUI::TestRunner.run(TestLongDecimalExtra_class.suite)
356
+
357
+ # end of file testlongdecimal.rb
@@ -4,30 +4,35 @@
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/testlongdecimal.rb,v 1.68 2009/04/21 04:27:39 bk1 Exp $
8
- # CVS-Label: $Name: BETA_02_01 $
7
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal.rb,v 1.86 2011/01/16 22:16:59 bk1 Exp $
8
+ # CVS-Label: $Name: RELEASE_1_00_00 $
9
9
  # Author: $Author: bk1 $ (Karl Brodowsky)
10
10
  #
11
11
 
12
- require "runit/testcase"
13
- require "runit/cui/testrunner"
14
- require "runit/testsuite"
12
+ require 'test/unit'
13
+
14
+ # require "runit/testcase"
15
+ # require "runit/cui/testrunner"
16
+ # require "runit/testsuite"
15
17
 
16
18
  load "lib/long-decimal.rb"
17
19
  load "test/testlongdeclib.rb"
18
20
 
21
+ LongMath.prec_overflow_handling = :warn_use_max
22
+
19
23
  #
20
24
  # test class for LongDecimal and LongDecimalQuot
21
25
  #
22
- class TestLongDecimal_class < RUNIT::TestCase
26
+ class TestLongDecimal_class < Test::Unit::TestCase # RUNIT::TestCase
23
27
  include TestLongDecHelper
24
28
 
25
- @RCS_ID='-$Id: testlongdecimal.rb,v 1.68 2009/04/21 04:27:39 bk1 Exp $-'
29
+ @RCS_ID='-$Id: testlongdecimal.rb,v 1.86 2011/01/16 22:16:59 bk1 Exp $-'
26
30
 
27
31
  #
28
32
  # test split_to_words and merge_from_words
29
33
  #
30
34
  def test_split_merge_words
35
+ print "\ntest_split_merge_words [#{Time.now}]: "
31
36
  check_split_merge_words(0, 1, 1)
32
37
  check_split_merge_words(0, 10, 1)
33
38
  check_split_merge_words(0, 100, 1)
@@ -60,6 +65,8 @@ class TestLongDecimal_class < RUNIT::TestCase
60
65
  # test the calculation of the exponential function
61
66
  #
62
67
  def test_exp
68
+ print "\ntest_exp [#{Time.now}] (60 sec): "
69
+ $stdout.flush
63
70
  xx = LongMath.log(10.to_ld, 10)*100
64
71
  check_exp_floated(700, 10)
65
72
  check_exp_floated(100, 10)
@@ -102,6 +109,7 @@ class TestLongDecimal_class < RUNIT::TestCase
102
109
  # near zero
103
110
  #
104
111
  def test_exp_near_zero
112
+ print "\ntest_exp_near_zero [#{Time.now}]: "
105
113
 
106
114
  x = LongDecimal(1, 100)
107
115
  y = LongMath.log(x, 100)
@@ -118,6 +126,7 @@ class TestLongDecimal_class < RUNIT::TestCase
118
126
  # test the calculation of the exponential function with precision 0
119
127
  #
120
128
  def test_exp_int
129
+ print "\ntest_exp_int [#{Time.now}]: "
121
130
 
122
131
  xx = LongMath.log(10, 10)*100
123
132
  pi = LongMath.pi(10)
@@ -157,6 +166,7 @@ class TestLongDecimal_class < RUNIT::TestCase
157
166
  # test LongMath.exp with non-LongDecimal arguments
158
167
  #
159
168
  def test_non_ld_exp
169
+ print "\ntest_non_ld_exp [#{Time.now}]: "
160
170
  xi = 77
161
171
  yi = LongMath.exp(xi, 30)
162
172
  zi = LongMath.log(yi, 30)
@@ -180,6 +190,7 @@ class TestLongDecimal_class < RUNIT::TestCase
180
190
  # test LongMath.log with non-LongDecimal arguments
181
191
  #
182
192
  def test_non_ld_log
193
+ print "\ntest_non_ld_log [#{Time.now}]: "
183
194
  xi = 77
184
195
  yi = LongMath.log(xi, 35)
185
196
  zi = LongMath.exp(yi, 30)
@@ -203,6 +214,8 @@ class TestLongDecimal_class < RUNIT::TestCase
203
214
  # test the calculation of the logarithm function
204
215
  #
205
216
  def test_log
217
+ print "\ntest_log [#{Time.now}] (120 sec): "
218
+ $stdout.flush
206
219
 
207
220
  check_log_floated(10**2000, 10)
208
221
  check_log_floated(100, 10)
@@ -253,6 +266,7 @@ class TestLongDecimal_class < RUNIT::TestCase
253
266
  # test the calculation of the base-x-logarithm of sqrt(x)
254
267
  #
255
268
  def test_log_of_sqrt
269
+ print "\ntest_log_of_sqrt [#{Time.now}]: "
256
270
  # n = 125
257
271
  n = 30
258
272
  m = 5
@@ -273,6 +287,7 @@ class TestLongDecimal_class < RUNIT::TestCase
273
287
  # test calculation of pi
274
288
  #
275
289
  def test_pi
290
+ print "\ntest_pi [#{Time.now}]: "
276
291
  s = "3.14159265358979323846264338327950288419716939937510"
277
292
  s += "58209749445923078164062862089986280348253421170679"
278
293
  s += "82148086513282306647093844609550582231725359408128"
@@ -331,6 +346,8 @@ class TestLongDecimal_class < RUNIT::TestCase
331
346
  # test method sqrtb for calculating sqrt of short integers
332
347
  #
333
348
  def test_int_sqrtb
349
+ print "\ntest_int_sqrtb [#{Time.now}] (120 sec): "
350
+ $stdout.flush
334
351
  assert_equal(Complex(0,1), LongMath.sqrtb(-1), "sqrt(-1)=i")
335
352
  1024.times do |x|
336
353
  check_sqrtb(x, " loop x=#{x}")
@@ -369,6 +386,8 @@ class TestLongDecimal_class < RUNIT::TestCase
369
386
  # test method sqrtb for calculating sqrt of long integers
370
387
  #
371
388
  def test_int_sqrtw
389
+ print "\ntest_int_sqrtw [#{Time.now}] (90 sec): "
390
+ $stdout.flush
372
391
  assert_equal(Complex(0,1), LongMath.sqrtw(-1), "sqrt(-1)=i")
373
392
  1024.times do |x|
374
393
  check_sqrtw(x, " loop x=#{x}")
@@ -407,6 +426,7 @@ class TestLongDecimal_class < RUNIT::TestCase
407
426
  # test method sqrtb_with_remainder for calculating sqrt _with_remainderof short integers
408
427
  #
409
428
  def test_int_sqrtb_with_remainder
429
+ print "\ntest_int_sqrtb_with_remainder [#{Time.now}]: "
410
430
  10.times do |x|
411
431
  check_sqrtb_with_remainder(x, " loop x=#{x}")
412
432
  end
@@ -449,6 +469,7 @@ class TestLongDecimal_class < RUNIT::TestCase
449
469
  # test method sqrtb_with_remainder for calculating sqrt _with_remainderof long integers
450
470
  #
451
471
  def test_int_sqrtw_with_remainder
472
+ print "\ntest_int_sqrtw_with_remainder [#{Time.now}]: "
452
473
  10.times do |x|
453
474
  check_sqrtw_with_remainder(x, " loop x=#{x}")
454
475
  end
@@ -491,6 +512,8 @@ class TestLongDecimal_class < RUNIT::TestCase
491
512
  # test method cbrtb for calculating cbrt of short integers
492
513
  #
493
514
  def test_int_cbrtb
515
+ print "\ntest_int_cbrtb [#{Time.now}] (120 sec): "
516
+ $stdout.flush
494
517
  assert_equal(-1, LongMath.cbrtb(-1), "cbrt(-1)=i")
495
518
  4096.times do |x|
496
519
  check_cbrtb(x, " loop x=#{x}")
@@ -529,6 +552,7 @@ class TestLongDecimal_class < RUNIT::TestCase
529
552
  # test method cbrtb_with_remainder for calculating cbrt _with_remainderof short integers
530
553
  #
531
554
  def test_int_cbrtb_with_remainder
555
+ print "\ntest_int_cbrtb_with_remainder [#{Time.now}]: "
532
556
  10.times do |x|
533
557
  check_cbrtb_with_remainder(x, " loop x=#{x}")
534
558
  end
@@ -571,6 +595,7 @@ class TestLongDecimal_class < RUNIT::TestCase
571
595
  # test gcd_with_high_power
572
596
  #
573
597
  def test_gcd_with_high_power
598
+ print "\ntest_gcd_with_high_power [#{Time.now}]: "
574
599
  n = 224
575
600
  assert_equal(32, LongMath.gcd_with_high_power(n, 2), "2-part of 224 is 32")
576
601
  assert_equal(7, LongMath.gcd_with_high_power(n, 7), "7-part of 224 is 7")
@@ -581,16 +606,171 @@ class TestLongDecimal_class < RUNIT::TestCase
581
606
  # test multiplicity_of_factor for integers
582
607
  #
583
608
  def test_multiplicity_of_factor
609
+ print "\ntest_multiplicity_of_factor [#{Time.now}]: "
584
610
  n = 224
585
611
  assert_equal(5, LongMath.multiplicity_of_factor(n, 2), "ny_2(224) is 5")
586
612
  assert_equal(1, LongMath.multiplicity_of_factor(n, 7), "ny_7(224) is 1")
587
613
  assert_equal(0, LongMath.multiplicity_of_factor(n, 3), "ny_3(224) is 0")
588
614
  end
589
615
 
616
+ #
617
+ # test division of Complex, which is overriden in long-decimal.rb
618
+ # due to bug 1454/1455 (redmine.ruby-lang.org) mixing of BigDecimal with Rational won't work.
619
+ #
620
+ def test_complex_div
621
+ print "\ntest_complex_div [#{Time.now}]: "
622
+ twenties = [ 20, 20.0, BigDecimal("20.0"), Rational(20, 1), LongDecimal("20.0"), LongDecimalQuot(20, 1) ]
623
+ fifteens = [ 15, 15.0, BigDecimal("15.0"), Rational(15, 1), LongDecimal("15.0"), LongDecimalQuot(15, 1) ]
624
+ threes = [ 3, 3.0, BigDecimal("3.0"), Rational(3, 1), LongDecimal("3.0"), LongDecimalQuot(3, 1) ]
625
+ fours = [ 4, 4.0, BigDecimal("4.0"), Rational(4, 1), LongDecimal("4.0"), LongDecimalQuot(4, 1) ]
626
+ zr = Complex(Rational(24, 5),-Rational(7, 5))
627
+ zb = Complex(BigDecimal("4.8"),-BigDecimal("1.4"))
628
+ zf = Complex(4.8,-1.4)
629
+ zl = Complex(LongDecimal("4.8"),-LongDecimal("1.4"))
630
+ tw_c = 0
631
+ twenties.each do |xr|
632
+ tw_c += 1
633
+ fi_c = 0
634
+ fifteens.each do |xi|
635
+ fi_c += 1
636
+ x = Complex(xr, xi)
637
+ th_c = 0
638
+ threes.each do |yr|
639
+ th_c += 1
640
+ fo_c = 0
641
+ fours.each do |yi|
642
+ fo_c += 1
643
+ has_rational = (xr.kind_of? Rational) || (xi.kind_of? Rational) || (yr.kind_of? Rational) || (yi.kind_of? Rational)
644
+ has_bigdecimal = (xr.kind_of? BigDecimal) || (xi.kind_of? BigDecimal) || (yr.kind_of? BigDecimal) || (yi.kind_of? BigDecimal)
645
+ if (has_rational && has_bigdecimal)
646
+ # these won't go together well
647
+ next
648
+ end
649
+ y = Complex(yr, yi)
650
+ z = x/y
651
+ msg = "x=#{x} y=#{y} z=#{z} xr=#{xr.inspect} (#{tw_c}) xi=#{xi.inspect} (#{fi_c}) yr=#{yr.inspect} (#{th_c}) yi=#{yi.inspect} (#{fo_c})"
652
+ # puts msg
653
+ if (xr.kind_of? Integer) && (xi.kind_of? Integer) && (yr.kind_of? Integer) && (yi.kind_of? Integer) # && ! LongDecimal::RUNNING_19
654
+ # ruby 1.9 creates rational result even from integers, ruby 1.8 uses integers as results.
655
+ zc = (x.cdiv y)
656
+ assert_equal_complex(zc, z, "all int zc=#{zc} " + msg)
657
+ next
658
+ end
659
+ unless has_bigdecimal
660
+ assert_equal_complex(zr, z, msg)
661
+ end
662
+ unless has_rational
663
+ assert_equal_complex(zb, z, msg)
664
+ end
665
+ assert_equal_complex(zf, z, msg)
666
+ assert_equal_complex(zl, z, msg)
667
+ unless (xr.kind_of? LongDecimalBase) || (xi.kind_of? LongDecimalBase) || (yr.kind_of? LongDecimalBase) || (yi.kind_of? LongDecimalBase)
668
+ zc = x.cdiv(y)
669
+ assert_equal_complex(z, zc, msg, 1.0e-15)
670
+ end
671
+ end
672
+ end
673
+ end
674
+ end
675
+ end
676
+
677
+ #
678
+ # test division of Complex, which is overriden in long-decimal.rb
679
+ # due to bug 1454/1455 (redmine.ruby-lang.org) mixing of BigDecimal with Complex won't work.
680
+ #
681
+ def test_complex_by_real_div
682
+ print "\ntest_complex_by_real_div [#{Time.now}]: "
683
+ twenties = [ 20, 20.0, BigDecimal("20.0"), Rational(20, 1), LongDecimal("20.0"), LongDecimalQuot(20, 1) ]
684
+ fifteens = [ 15, 15.0, BigDecimal("15.0"), Rational(15, 1), LongDecimal("15.0"), LongDecimalQuot(15, 1) ]
685
+ fives = [ 5, 5.0, Rational(5, 1), LongDecimal("5.0"), LongDecimalQuot(5, 1) ]
686
+ zr = Complex(Rational(4,1),Rational(3,1))
687
+ zb = Complex(BigDecimal("4.0"),BigDecimal("3.0"))
688
+ zf = Complex(4.0,3.0)
689
+ zl = Complex(LongDecimal("4.0"),LongDecimal("3.0"))
690
+ twenties.each do |xr|
691
+ fifteens.each do |xi|
692
+ x = Complex(xr, xi)
693
+ fives.each do |y|
694
+ has_rational = (xr.kind_of? Rational) || (xi.kind_of? Rational) || (y.kind_of? Rational)
695
+ has_bigdecimal = (xr.kind_of? BigDecimal) || (xi.kind_of? BigDecimal) || (y.kind_of? BigDecimal)
696
+ if (has_rational && has_bigdecimal)
697
+ # these won't go together well
698
+ next
699
+ end
700
+ z = x / y
701
+ msg = "x=#{x} y=#{y} z=#{z} xr=#{xr.inspect} xi=#{xi.inspect} y=#{y.inspect}"
702
+ if (xr.kind_of? Integer) && (xi.kind_of? Integer) && (y.kind_of? Integer)
703
+ assert_equal_complex((x.cdiv y), z, "all int")
704
+ next
705
+ end
706
+ unless has_bigdecimal
707
+ assert_equal_complex(zr, z, msg)
708
+ end
709
+ unless has_rational
710
+ assert_equal_complex(zb, z, msg)
711
+ end
712
+ assert_equal_complex(zf, z, msg)
713
+ assert_equal_complex(zl, z, msg)
714
+ unless (xr.kind_of? LongDecimalBase) || (xi.kind_of? LongDecimalBase) || (y.kind_of? LongDecimalBase)
715
+ zc = x.cdiv(y)
716
+ assert_equal_complex(z, zc, msg)
717
+ end
718
+ end
719
+ end
720
+ end
721
+ end
722
+
723
+ #
724
+ # test division of Complex, which is overriden in long-decimal.rb
725
+ # due to bug 1454/1455 (redmine.ruby-lang.org) mixing of BigDecimal with Rational or Complex won't work.
726
+ #
727
+ def test_real_by_complex_div
728
+ print "\ntest_real_by_complex_div [#{Time.now}]: "
729
+ twenties = [ 20, 20.0, Rational(20, 1), LongDecimal("20.0"), LongDecimalQuot(20, 1) ]
730
+ threes = [ 3, 3.0, BigDecimal("3.0"), Rational(3, 1), LongDecimal("3.0"), LongDecimalQuot(3, 1) ]
731
+ fours = [ 4, 4.0, BigDecimal("4.0"), Rational(4, 1), LongDecimal("4.0"), LongDecimalQuot(4, 1) ]
732
+ zr = Complex(Rational(24,10),Rational(-32,10))
733
+ zb = Complex(BigDecimal("2.4"),BigDecimal("-3.2"))
734
+ zf = Complex(2.4,-3.2)
735
+ zl = Complex(LongDecimal("2.4"),LongDecimal("-3.2"))
736
+ zi = Complex(2, -4)
737
+ twenties.each do |x|
738
+ threes.each do |yr|
739
+ fours.each do |yi|
740
+ has_rational = (x.kind_of? Rational) || (yr.kind_of? Rational) || (yi.kind_of? Rational)
741
+ has_bigdecimal = (x.kind_of? BigDecimal) || (yr.kind_of? BigDecimal) || (yi.kind_of? BigDecimal)
742
+ if (has_rational && has_bigdecimal)
743
+ # these won't go together well
744
+ next
745
+ end
746
+ y = Complex(yr, yi)
747
+ z = x/y
748
+ msg = "x=#{x} y=#{y} z=#{z} yr=#{yr.inspect} yi=#{yi.inspect} x=#{x.inspect}"
749
+ if (x.kind_of? Integer) && (yr.kind_of? Integer) && (yi.kind_of? Integer) && LongDecimal::RUNNING_19
750
+ has_rational # quotients of ints within Complex are Rational in 1.9
751
+ end
752
+ if (x.kind_of? Integer) && (yr.kind_of? Integer) && (yi.kind_of? Integer) && ! LongDecimal::RUNNING_19
753
+ assert_equal_complex(zi, z, msg)
754
+ next
755
+ end
756
+ # unless has_bigdecimal
757
+ assert_equal_complex(zr, z, msg)
758
+ # end
759
+ # unless has_rational
760
+ assert_equal_complex(zb, z, msg)
761
+ # end
762
+ assert_equal_complex(zf, z, msg)
763
+ assert_equal_complex(zl, z, msg)
764
+ end
765
+ end
766
+ end
767
+ end
768
+
590
769
  #
591
770
  # test multiplicity_of_factor for rationals
592
771
  #
593
772
  def test_rat_multiplicity_of_factor
773
+ print "\ntest_rat_multiplicity_of_factor [#{Time.now}]: "
594
774
  n = Rational(224, 225)
595
775
  assert_equal(5, LongMath.multiplicity_of_factor(n, 2), "ny_2(n) is 5")
596
776
  assert_equal(1, LongMath.multiplicity_of_factor(n, 7), "ny_7(n) is 1")
@@ -604,6 +784,7 @@ class TestLongDecimal_class < RUNIT::TestCase
604
784
  # denominator exceeding Float
605
785
  #
606
786
  def test_rat_long_multiplicity_of_factor
787
+ print "\ntest_rat_long_multiplicity_of_factor [#{Time.now}]: "
607
788
  n = Rational(224*(10**600+1), 225*(5**800))
608
789
  assert_equal(5, LongMath.multiplicity_of_factor(n, 2), "ny_2(n) is 5")
609
790
  assert_equal(1, LongMath.multiplicity_of_factor(n, 7), "ny_7(n) is 1")
@@ -616,6 +797,7 @@ class TestLongDecimal_class < RUNIT::TestCase
616
797
  # test multiplicity_of_factor for LongDecimal
617
798
  #
618
799
  def test_ld_multiplicity_of_factor
800
+ print "\ntest_ld_multiplicity_of_factor [#{Time.now}]: "
619
801
  # 0.729
620
802
  n = LongDecimal(729, 3)
621
803
  assert_equal(-3, LongMath.multiplicity_of_factor(n, 2), "ny_2(n) is -3")
@@ -629,6 +811,7 @@ class TestLongDecimal_class < RUNIT::TestCase
629
811
  # test creation of 0 with given number of digits after the decimal point
630
812
  #
631
813
  def test_zero_init
814
+ print "\ntest_zero_init [#{Time.now}]: "
632
815
  l = LongDecimal.zero!(224)
633
816
  assert_equal(l.to_r, 0, "to_r")
634
817
  assert_equal(l.scale, 224, "scale")
@@ -638,6 +821,7 @@ class TestLongDecimal_class < RUNIT::TestCase
638
821
  # test creation of 1 with given number of digits after the decimal point
639
822
  #
640
823
  def test_one_init
824
+ print "\ntest_one_init [#{Time.now}]: "
641
825
  l = LongDecimal.one!(224)
642
826
  assert_equal(l.to_r, 1, "to_r")
643
827
  assert_equal(l.scale, 224, "scale")
@@ -647,6 +831,7 @@ class TestLongDecimal_class < RUNIT::TestCase
647
831
  # test creation of 2 with given number of digits after the decimal point
648
832
  #
649
833
  def test_two_init
834
+ print "\ntest_two_init [#{Time.now}]: "
650
835
  l = LongDecimal.two!(224)
651
836
  assert_equal(l.to_r, 2, "to_r")
652
837
  assert_equal(l.scale, 224, "scale")
@@ -656,6 +841,7 @@ class TestLongDecimal_class < RUNIT::TestCase
656
841
  # test creation of 10 with given number of digits after the decimal point
657
842
  #
658
843
  def test_ten_init
844
+ print "\ntest_ten_init [#{Time.now}]: "
659
845
  l = LongDecimal.ten!(224)
660
846
  assert_equal(l.to_r, 10, "to_r")
661
847
  assert_equal(l.scale, 224, "scale")
@@ -665,6 +851,7 @@ class TestLongDecimal_class < RUNIT::TestCase
665
851
  # test creation of -1 with given number of digits after the decimal point
666
852
  #
667
853
  def test_minus_one_init
854
+ print "\ntest_minus_one_init [#{Time.now}]: "
668
855
  l = LongDecimal.minus_one!(224)
669
856
  assert_equal(l.to_r, -1, "to_r")
670
857
  assert_equal(l.scale, 224, "scale")
@@ -674,6 +861,7 @@ class TestLongDecimal_class < RUNIT::TestCase
674
861
  # test creation of 10**e with given number of digits after the decimal point
675
862
  #
676
863
  def test_power_of_ten_init
864
+ print "\ntest_power_of_ten_init [#{Time.now}]: "
677
865
  20.times do |e|
678
866
  l = LongDecimal.power_of_ten!(e, 224)
679
867
  assert_equal(l.to_r, 10**e, "to_r e=#{e}")
@@ -685,6 +873,7 @@ class TestLongDecimal_class < RUNIT::TestCase
685
873
  # test construction of LongDecimal from Integer
686
874
  #
687
875
  def test_int_init
876
+ print "\ntest_int_init [#{Time.now}]: "
688
877
  i = 224
689
878
  l = LongDecimal(i)
690
879
  assert_equal(i, l.to_i, "no loss of information for integers allowed")
@@ -707,6 +896,7 @@ class TestLongDecimal_class < RUNIT::TestCase
707
896
  # test construction from Rational
708
897
  #
709
898
  def test_rat_init
899
+ print "\ntest_rat_init [#{Time.now}]: "
710
900
  r = Rational(227, 100)
711
901
  l = LongDecimal(r)
712
902
  assert_equal(r, l.to_r, "no loss of information for rationals with denominator power of 10 allowed l=#{l.inspect}")
@@ -724,6 +914,7 @@ class TestLongDecimal_class < RUNIT::TestCase
724
914
  # test construction from Float
725
915
  #
726
916
  def test_float_init
917
+ print "\ntest_float_init [#{Time.now}]: "
727
918
  s = "5.32"
728
919
  l = LongDecimal(s)
729
920
  assert_equal(s, l.to_s, "l=#{l.inspect}")
@@ -746,6 +937,7 @@ class TestLongDecimal_class < RUNIT::TestCase
746
937
  # test construction from BigDecimal
747
938
  #
748
939
  def test_bd_init
940
+ print "\ntest_bd_init [#{Time.now}]: "
749
941
  b = BigDecimal("5.32")
750
942
  l = LongDecimal(b)
751
943
  assert_equal(b, l.to_bd, "l=#{l.inspect}")
@@ -768,6 +960,7 @@ class TestLongDecimal_class < RUNIT::TestCase
768
960
  # test int_digits2 of LongDecimal
769
961
  #
770
962
  def test_int_digits2
963
+ print "\ntest_int_digits2 [#{Time.now}]: "
771
964
  assert_equal(0, LongDecimal("0.0000").int_digits2, "0.0000")
772
965
  assert_equal(0, LongDecimal("0.9999").int_digits2, "0.9999")
773
966
  assert_equal(1, LongDecimal("1.0000").int_digits2, "1.0000")
@@ -793,6 +986,7 @@ class TestLongDecimal_class < RUNIT::TestCase
793
986
  # test int_digits10 of LongDecimal
794
987
  #
795
988
  def test_int_digits10
989
+ print "\ntest_int_digits10 [#{Time.now}]: "
796
990
  assert_equal(0, LongDecimal("0.0000").int_digits10, "0.0000")
797
991
  assert_equal(0, LongDecimal("0.0009").int_digits10, "0.0009")
798
992
  assert_equal(0, LongDecimal("0.0099").int_digits10, "0.0099")
@@ -825,6 +1019,7 @@ class TestLongDecimal_class < RUNIT::TestCase
825
1019
  # test sint_digits10 of LongDecimal
826
1020
  #
827
1021
  def test_sint_digits10
1022
+ print "\ntest_sint_digits10 [#{Time.now}]: "
828
1023
  assert_equal(-4, LongDecimal("0.0000").sint_digits10, "0.0000")
829
1024
  assert_equal(-3, LongDecimal("0.0009").sint_digits10, "0.0009")
830
1025
  assert_equal(-2, LongDecimal("0.0099").sint_digits10, "0.0099")
@@ -857,6 +1052,7 @@ class TestLongDecimal_class < RUNIT::TestCase
857
1052
  # test int_digits10 of LongMath
858
1053
  #
859
1054
  def test_lm_int_digits10
1055
+ print "\ntest_lm_int_digits10 [#{Time.now}]: "
860
1056
  assert_equal(0, LongMath.int_digits10(0), "0")
861
1057
  assert_equal(1, LongMath.int_digits10(1), "1")
862
1058
  assert_equal(1, LongMath.int_digits10(9), "9")
@@ -874,6 +1070,7 @@ class TestLongDecimal_class < RUNIT::TestCase
874
1070
  # test LongMath.multiplicity_of_10(n)
875
1071
  #
876
1072
  def test_lm_multiplicity_of_10
1073
+ print "\ntest_lm_multiplicity_of_10 [#{Time.now}]: "
877
1074
  assert_equal(0, LongMath.multiplicity_of_10(-999), "-999")
878
1075
  assert_equal(0, LongMath.multiplicity_of_10(-1), "-1")
879
1076
  assert_equal(0, LongMath.multiplicity_of_10(-5), "-5")
@@ -901,6 +1098,7 @@ class TestLongDecimal_class < RUNIT::TestCase
901
1098
  # test round_trailing_zeros of LongDecimal
902
1099
  #
903
1100
  def test_round_trailing_zeros
1101
+ print "\ntest_round_trailing_zeros [#{Time.now}]: "
904
1102
  x = LongDecimal.one!(100)
905
1103
  y = x.round_trailing_zeros
906
1104
  z = LongDecimal.one!(0)
@@ -918,6 +1116,7 @@ class TestLongDecimal_class < RUNIT::TestCase
918
1116
  # test rounding of LongDecimal with ROUND_UP
919
1117
  #
920
1118
  def test_round_to_scale_up
1119
+ print "\ntest_round_to_scale_up [#{Time.now}]: "
921
1120
  l = LongDecimal("2.21")
922
1121
  r = l.round_to_scale(1, LongDecimal::ROUND_UP)
923
1122
  assert_equal("2.3", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -943,6 +1142,7 @@ class TestLongDecimal_class < RUNIT::TestCase
943
1142
  # test rounding with ROUND_DOWN
944
1143
  #
945
1144
  def test_round_to_scale_down
1145
+ print "\ntest_round_to_scale_down [#{Time.now}]: "
946
1146
  l = LongDecimal("2.29")
947
1147
  r = l.round_to_scale(1, LongDecimal::ROUND_DOWN)
948
1148
  assert_equal("2.2", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -968,6 +1168,7 @@ class TestLongDecimal_class < RUNIT::TestCase
968
1168
  # test rounding with ROUND_CEILING
969
1169
  #
970
1170
  def test_round_to_scale_ceiling
1171
+ print "\ntest_round_to_scale_ceiling [#{Time.now}]: "
971
1172
  l = LongDecimal("2.21")
972
1173
  r = l.round_to_scale(1, LongDecimal::ROUND_CEILING)
973
1174
  assert_equal("2.3", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -993,6 +1194,7 @@ class TestLongDecimal_class < RUNIT::TestCase
993
1194
  # test rounding with ROUND_FLOOR
994
1195
  #
995
1196
  def test_round_to_scale_floor
1197
+ print "\ntest_round_to_scale_floor [#{Time.now}]: "
996
1198
  l = LongDecimal("2.29")
997
1199
  r = l.round_to_scale(1, LongDecimal::ROUND_FLOOR)
998
1200
  assert_equal("2.2", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -1018,6 +1220,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1018
1220
  # test rounding with ROUND_HALF_UP
1019
1221
  #
1020
1222
  def test_round_to_scale_half_up
1223
+ print "\ntest_round_to_scale_half_up [#{Time.now}]: "
1021
1224
  l = LongDecimal("2.20")
1022
1225
  r = l.round_to_scale(1, LongDecimal::ROUND_HALF_UP)
1023
1226
  assert_equal("2.2", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -1059,6 +1262,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1059
1262
  # test rounding with ROUND_HALF_DOWN
1060
1263
  #
1061
1264
  def test_round_to_scale_half_down
1265
+ print "\ntest_round_to_scale_half_down [#{Time.now}]: "
1062
1266
  l = LongDecimal("2.20")
1063
1267
  r = l.round_to_scale(1, LongDecimal::ROUND_HALF_DOWN)
1064
1268
  assert_equal("2.2", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -1100,6 +1304,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1100
1304
  # test rounding with ROUND_HALF_CEILING
1101
1305
  #
1102
1306
  def test_round_to_scale_half_up
1307
+ print "\ntest_round_to_scale_half_up [#{Time.now}]: "
1103
1308
  l = LongDecimal("2.20")
1104
1309
  r = l.round_to_scale(1, LongDecimal::ROUND_HALF_CEILING)
1105
1310
  assert_equal("2.2", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -1141,6 +1346,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1141
1346
  # test rounding with ROUND_HALF_FLOOR
1142
1347
  #
1143
1348
  def test_round_to_scale_half_down
1349
+ print "\ntest_round_to_scale_half_down [#{Time.now}]: "
1144
1350
  l = LongDecimal("2.20")
1145
1351
  r = l.round_to_scale(1, LongDecimal::ROUND_HALF_FLOOR)
1146
1352
  assert_equal("2.2", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -1182,6 +1388,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1182
1388
  # test rounding with ROUND_HALF_EVEN
1183
1389
  #
1184
1390
  def test_round_to_scale_half_even
1391
+ print "\ntest_round_to_scale_half_even [#{Time.now}]: "
1185
1392
  l = LongDecimal("2.20")
1186
1393
  r = l.round_to_scale(1, LongDecimal::ROUND_HALF_EVEN)
1187
1394
  assert_equal("2.2", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -1231,6 +1438,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1231
1438
  # test rounding with ROUND_UNNECESSARY
1232
1439
  #
1233
1440
  def test_round_to_scale_unnecessary
1441
+ print "\ntest_round_to_scale_unnecessary [#{Time.now}]: "
1234
1442
  l = LongDecimal("2.24")
1235
1443
  r = l.round_to_scale(4, LongDecimal::ROUND_UNNECESSARY)
1236
1444
  assert_equal("2.2400", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -1250,11 +1458,15 @@ class TestLongDecimal_class < RUNIT::TestCase
1250
1458
  # test rounding of int to remainder set
1251
1459
  #
1252
1460
  def test_int_round_to_one_allowed_remainder
1461
+ print "\ntest_int_round_to_one_allowed_remainder [#{Time.now}] (20min): "
1462
+ $stdout.flush
1253
1463
  2.upto 20 do |modulus|
1254
1464
  0.upto modulus-1 do |r|
1255
1465
  n = 3*modulus
1256
1466
  (-n).upto n do |i|
1257
1467
  text = "i=#{i} n=#{n} m=#{modulus} r=#{r}"
1468
+ print ":"
1469
+ $stdout.flush
1258
1470
 
1259
1471
  i_rounded = check_round_to_one_remainder(i, r, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
1260
1472
  assert(i_rounded.abs >= i.abs, "i_r=#{i_rounded} " + text)
@@ -1315,6 +1527,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1315
1527
  # test rounding of int to remainder set
1316
1528
  #
1317
1529
  def test_zero_round_to_one_allowed_remainder
1530
+ print "\ntest_zero_round_to_one_allowed_remainder [#{Time.now}]: "
1318
1531
  2.upto 20 do |modulus|
1319
1532
  0.upto modulus-1 do |r|
1320
1533
  text = "m=#{modulus} r=#{r}"
@@ -1450,12 +1663,17 @@ class TestLongDecimal_class < RUNIT::TestCase
1450
1663
  # test rounding of int to remainder set
1451
1664
  #
1452
1665
  def test_int_round_to_allowed_remainders
1453
- 2.upto 8 do |modulus|
1666
+ print "\ntest_int_round_to_allowed_remainders [#{Time.now}] (45 min): "
1667
+ $stdout.flush
1668
+ # 2.upto 8 do |modulus|
1669
+ 2.upto 7 do |modulus|
1454
1670
  xx = (1<< modulus) - 1
1455
1671
  xx.times do |x|
1456
1672
  remainders = make_set(x + 1, modulus)
1457
1673
  text0 = "m=#{modulus} x=#{x} s=#{remainders.inspect}"
1458
- puts text0
1674
+ # puts text0
1675
+ print ":"
1676
+ $stdout.flush
1459
1677
  n = 3*modulus
1460
1678
  (-n).upto n do |i|
1461
1679
  text = "i=#{i} n=#{n} " + text0
@@ -1542,12 +1760,17 @@ class TestLongDecimal_class < RUNIT::TestCase
1542
1760
  # test rounding of 0 to remainder set
1543
1761
  #
1544
1762
  def test_zero_round_to_allowed_remainders
1545
- 2.upto 8 do |modulus|
1763
+ print "\ntest_zero_round_to_allowed_remainders [#{Time.now}] (long): "
1764
+ $stdout.flush
1765
+
1766
+ 2.upto 7 do |modulus|
1546
1767
  xx = (1<< modulus) - 1
1547
1768
  xx.times do |x|
1548
1769
  remainders = make_set(x + 1, modulus)
1549
1770
  text = "m=#{modulus} x=#{x} s=#{remainders.inspect}"
1550
- puts text
1771
+ # puts text
1772
+ print "."
1773
+ $stdout.flush
1551
1774
 
1552
1775
  # ROUND_UP and ROUND_DOWN have the same effect for 0
1553
1776
  zero_r1, set1, above1, below1 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
@@ -1740,6 +1963,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1740
1963
  # test conversion to String
1741
1964
  #
1742
1965
  def test_to_s
1966
+ print "\ntest_to_s [#{Time.now}]: "
1743
1967
  l = LongDecimal(224, 0)
1744
1968
  assert_equal("224", l.to_s, "l=#{l.inspect}")
1745
1969
  l = LongDecimal(224, 1)
@@ -1767,6 +1991,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1767
1991
  # test conversion to String with extra parameters
1768
1992
  #
1769
1993
  def test_to_s_with_params
1994
+ print "\ntest_to_s_with_params [#{Time.now}]: "
1770
1995
  l = LongDecimal(224, 0)
1771
1996
  s = l.to_s(5)
1772
1997
  assert_equal("224.00000", s, "l=#{l.inspect} 5")
@@ -1824,6 +2049,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1824
2049
  # test conversion to Rational
1825
2050
  #
1826
2051
  def test_to_r
2052
+ print "\ntest_to_r [#{Time.now}]: "
1827
2053
  l = LongDecimal(224, 0)
1828
2054
  assert_equal(l, l.to_r.to_ld, "l=#{l.inspect}")
1829
2055
  l = LongDecimal(224, 1)
@@ -1836,47 +2062,13 @@ class TestLongDecimal_class < RUNIT::TestCase
1836
2062
  assert_equal(l, l.to_r.to_ld, "l=#{l.inspect}")
1837
2063
  end
1838
2064
 
1839
- #
1840
- # test conversion to Float
1841
- #
1842
- def test_to_f
1843
- l = LongDecimal(224, 0)
1844
- assert((l.to_f - 224).abs < 224 * 0.000001, "l=#{l.inspect}")
1845
- assert(((-l).to_f + 224).abs < 224 * 0.000001, "l=#{l.inspect}")
1846
- l = LongDecimal(224, 1)
1847
- assert((l.to_f - 22.4).abs < 22.4 * 0.000001, "l=#{l.inspect}")
1848
- assert(((-l).to_f + 22.4).abs < 22.4 * 0.000001, "l=#{l.inspect}")
1849
- l = LongDecimal(224, 2)
1850
- assert((l.to_f - 2.24).abs < 2.24 * 0.000001, "l=#{l.inspect}")
1851
- assert(((-l).to_f + 2.24).abs < 2.24 * 0.000001, "l=#{l.inspect}")
1852
- l = LongDecimal(224, 3)
1853
- assert((l.to_f - 0.224).abs < 0.224 * 0.000001, "l=#{l.inspect}")
1854
- assert(((-l).to_f + 0.224).abs < 0.224 * 0.000001, "l=#{l.inspect}")
1855
- l = LongDecimal(224, 4)
1856
- assert((l.to_f - 0.0224).abs < 0.0224 * 0.000001, "l=#{l.inspect}")
1857
- assert(((-l).to_f + 0.0224).abs < 0.0224 * 0.000001, "l=#{l.inspect}")
1858
-
1859
- l = LongDecimal("0." + ("0" * 30) + "1" + ("0" * 500))
1860
- assert((l.to_f - 1e-31).abs < 1e-32, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
1861
- assert(((-l).to_f + 1e-31).abs < 1e-32, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
1862
- l = LongDecimal("0." + ("0" * 200) + "1" + ("0" * 500))
1863
- assert((l.to_f - 1e-201).abs < 1e-202, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
1864
- assert(((-l).to_f + 1e-201).abs < 1e-202, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
1865
- l = LongDecimal("0." + ("0" * 280) + "1" + ("0" * 500))
1866
- assert((l.to_f - 1e-281).abs < 1e-282, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
1867
- assert(((-l).to_f + 1e-281).abs < 1e-282, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
1868
-
1869
- l = LongDecimal("0.00000000000000000000000000000000000000000000000000002090000000000000000000000000332000042999999999999999934478499999999999999999999979183597303900000000000002280678889571719972270000000870125632696979999999999928587104894304210318436999963636067429710015568287618182130517226303011944557351440293760289098908449297658922618709026683663019359834144789263320")
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}")
1873
- assert(((-l).to_f + 0.0000000000000000000000000000000000000000000000000000209).abs < 1e-60, "l=#{l.inspect}")
1874
- end
2065
+ #test_to_f
1875
2066
 
1876
2067
  #
1877
2068
  # test to_ld of Numeric
1878
2069
  #
1879
2070
  def test_to_ld
2071
+ print "\ntest_to_ld [#{Time.now}]: "
1880
2072
  x = LongDecimal(123, 100)
1881
2073
  y = x.to_ld(20, LongMath::ROUND_UP)
1882
2074
  z = LongDecimal(1, 20)
@@ -1898,6 +2090,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1898
2090
  # test conversion to BigDecimal
1899
2091
  #
1900
2092
  def test_to_bd
2093
+ print "\ntest_to_bd [#{Time.now}]: "
1901
2094
  l = LongDecimal(224, 0)
1902
2095
  assert((l.to_bd - 224).abs < 224 * 0.000001, "l=#{l.inspect}")
1903
2096
  l = LongDecimal(224, 1)
@@ -1914,6 +2107,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1914
2107
  # test conversion to Integer
1915
2108
  #
1916
2109
  def test_to_i
2110
+ print "\ntest_to_i [#{Time.now}]: "
1917
2111
  l = LongDecimal(224, 0)
1918
2112
  assert_equal(224, l.to_i, "l=#{l.inspect}")
1919
2113
  l = LongDecimal(224, 1)
@@ -1937,10 +2131,12 @@ class TestLongDecimal_class < RUNIT::TestCase
1937
2131
  # and subtraction
1938
2132
  #
1939
2133
  def test_equalize_scale
2134
+ print "\ntest_equalize_scale [#{Time.now}]: "
1940
2135
  x = LongDecimal(1, 0)
1941
2136
  y = LongDecimal(10, 1)
1942
2137
  assert_equal(0, (x - y).sgn, "difference must be 0")
1943
- assert(! (x == y), "x and y have the same value, but are not equal")
2138
+ assert(! (x.eql? y), "x and y have the same value, but are not equal")
2139
+ assert_equal(x, y)
1944
2140
  u, v = x.equalize_scale(y)
1945
2141
  assert_equal(u, v, "u and v must be equal")
1946
2142
  assert_equal(y, v, "y and v must be equal")
@@ -1957,6 +2153,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1957
2153
  # test adjustment of scale which is used as preparation for division
1958
2154
  #
1959
2155
  def test_anti_equalize_scale
2156
+ print "\ntest_anti_equalize_scale [#{Time.now}]: "
1960
2157
  x = LongDecimal(20, 3)
1961
2158
  y = LongDecimal(10, 1)
1962
2159
  u, v = x.anti_equalize_scale(y)
@@ -1970,6 +2167,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1970
2167
  # test unary minus operation (negation)
1971
2168
  #
1972
2169
  def test_negation
2170
+ print "\ntest_negation [#{Time.now}]: "
1973
2171
  x = LongDecimal(0, 5)
1974
2172
  assert_equal(-x, x, "x and -x are equal for negative x=#{x.inspect}")
1975
2173
  x = LongDecimal(224, 2)
@@ -1983,6 +2181,7 @@ class TestLongDecimal_class < RUNIT::TestCase
1983
2181
  # test addition of LongDecimal
1984
2182
  #
1985
2183
  def test_add
2184
+ print "\ntest_add [#{Time.now}]: "
1986
2185
  x = LongDecimal(224, 2)
1987
2186
 
1988
2187
  y = LongDecimal(3, 1)
@@ -2029,21 +2228,35 @@ class TestLongDecimal_class < RUNIT::TestCase
2029
2228
  z = y + x
2030
2229
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
2031
2230
  assert_equal(zz, z, "z=#{z.inspect}")
2231
+ end
2232
+
2233
+ #
2234
+ # test add_complexition of LongDecimal
2235
+ #
2236
+ def test_add_complex
2237
+ print "\ntest_add_complex [#{Time.now}]: "
2238
+ x = LongDecimal(224, 2)
2032
2239
 
2033
2240
  y = Complex(5, 3)
2034
2241
  z = x + y
2035
- zz = Complex(7.24, 3)
2242
+ # if (LongDecimalBase::RUNNING_19)
2243
+ zz = Complex(LongDecimal(724, 2), 3)
2244
+ # else
2245
+ # zz = Complex(7.24, 3)
2246
+ # end
2036
2247
  assert_kind_of(Complex, z, "z=#{z.inspect}")
2037
- assert_equal(zz, z, "z=#{z.inspect}")
2248
+ msg = "z=#{z.inspect} zz=#{zz.inspect} x=#{x.inspect} y=#{y.inspect}"
2249
+ assert_equal(zz, z, msg)
2038
2250
  z = y + x
2039
2251
  assert_kind_of(Complex, z, "z=#{z.inspect}")
2040
- assert_equal(zz, z, "z=#{z.inspect}")
2252
+ assert_equal(zz, z, msg);
2041
2253
  end
2042
2254
 
2043
2255
  #
2044
2256
  # test subtraction of LongDecimal
2045
2257
  #
2046
2258
  def test_sub
2259
+ print "\ntest_sub [#{Time.now}]: "
2047
2260
  x = LongDecimal(224, 2)
2048
2261
 
2049
2262
  y = LongDecimal(3, 1)
@@ -2095,14 +2308,27 @@ class TestLongDecimal_class < RUNIT::TestCase
2095
2308
  zz = LongDecimalQuot(Rational(-43, 75), 3)
2096
2309
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
2097
2310
  assert_equal(zz, z, "z=#{z.inspect}")
2311
+ end
2312
+
2313
+ #
2314
+ # test sub_complextraction of LongDecimal
2315
+ #
2316
+ def test_sub_complex
2317
+ print "\ntest_sub_complex [#{Time.now}]: "
2318
+ x = LongDecimal(224, 2)
2098
2319
 
2099
2320
  y = Complex(5, 3)
2100
2321
  z = x - y
2101
- zz = Complex(-2.76, -3)
2322
+ #if (LongDecimalBase::RUNNING_19)
2323
+ zz = Complex(LongDecimal(-276, 2), -3)
2324
+ #else
2325
+ # zz = Complex(-2.76, -3)
2326
+ #end
2102
2327
  assert_kind_of(Complex, z, "z=#{z.inspect}")
2103
2328
  assert_equal(zz, z, "z=#{z.inspect}")
2104
2329
  z = y - x
2105
- zz = Complex(2.76, 3)
2330
+ zz = Complex(LongDecimal(276, 2), 3)
2331
+ # zz = Complex(2.76, 3)
2106
2332
  assert_kind_of(Complex, z, "z=#{z.inspect}")
2107
2333
  assert_equal(zz, z, "z=#{z.inspect}")
2108
2334
  end
@@ -2111,6 +2337,8 @@ class TestLongDecimal_class < RUNIT::TestCase
2111
2337
  # test multiplication of fixnum, which is buggy in JRuby and has been fixed here.
2112
2338
  #
2113
2339
  def test_int_mul
2340
+ print "\ntest_int_mul [#{Time.now}] (90 sec): "
2341
+ $stdout.flush
2114
2342
  65.times do |i|
2115
2343
  x0 = (1<<i)-1
2116
2344
  3.times do |k|
@@ -2135,14 +2363,19 @@ class TestLongDecimal_class < RUNIT::TestCase
2135
2363
  end
2136
2364
 
2137
2365
  #
2138
- # test multiplication of fixnum, which is buggy in JRuby and has been fixed here.
2366
+ # test multiplication which uses internally multiplication of fixnum, which is buggy in JRuby and has been fixed here.
2139
2367
  #
2140
2368
  def test_mul2
2369
+ print "\ntest_mul2 [#{Time.now}] (25 min): "
2370
+ $stdout.flush
2371
+
2141
2372
  map = {}
2142
- 65.times do |i|
2143
- x0 = (1<<i)-1
2373
+ [0, 1, 2, 3, 4, 5, 7, 9, 11, 13, 17, 21, 25, 29, 31, 33, 34, 35].each do |i|
2374
+ next if i > 5 && (i & 0x1) == 0
2375
+ ii = i + 32
2376
+ x0 = (1 << ii) - 1
2144
2377
  3.times do |k|
2145
- x1 = x0+k
2378
+ x1 = x0 + k
2146
2379
  4.times do |s|
2147
2380
  x = LongDecimal(x1, s)
2148
2381
  map[x] = x1
@@ -2162,10 +2395,6 @@ class TestLongDecimal_class < RUNIT::TestCase
2162
2395
  assert(z.zero?)
2163
2396
  next
2164
2397
  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
2398
  assert_equal(y, (z/x).round_to_scale(y.scale))
2170
2399
  assert_equal(x, (z/y).round_to_scale(x.scale))
2171
2400
  end
@@ -2176,6 +2405,7 @@ class TestLongDecimal_class < RUNIT::TestCase
2176
2405
  # test multiplication of LongDecimal
2177
2406
  #
2178
2407
  def test_mul
2408
+ print "\ntest_mul [#{Time.now}]: "
2179
2409
  x = LongDecimal(224, 2)
2180
2410
 
2181
2411
  y = LongDecimal(3, 1)
@@ -2222,21 +2452,31 @@ class TestLongDecimal_class < RUNIT::TestCase
2222
2452
  z = y * x
2223
2453
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
2224
2454
  assert_equal(zz, z, "z=#{z.inspect}")
2455
+ end
2456
+
2457
+ #
2458
+ # test mul_complextiplication of LongDecimal
2459
+ #
2460
+ def test_mul_complex
2461
+ print "\ntest_mul_complex [#{Time.now}]: "
2462
+ x = LongDecimal(224, 2)
2225
2463
 
2226
2464
  y = Complex(5, 3)
2227
2465
  z = x * y
2228
- zz = Complex(11.20, 6.72)
2466
+ # zz = Complex(11.20, 6.72)
2467
+ zz = Complex(LongDecimal(1120, 2), LongDecimal(672, 2))
2229
2468
  assert_kind_of(Complex, z, "z=#{z.inspect}")
2230
- assert((zz-z).abs < 1e-9, "z=#{z.inspect}")
2469
+ assert_equal_complex(zz, z, "z=#{z.inspect}", 1e-9)
2231
2470
  z = y * x
2232
2471
  assert_kind_of(Complex, z, "z=#{z.inspect}")
2233
- assert((zz-z).abs < 1e-9, "z=#{z.inspect}")
2472
+ assert_equal_complex(zz, z, "z=#{z.inspect}", 1e-9)
2234
2473
  end
2235
2474
 
2236
2475
  #
2237
2476
  # test division of LongDecimal
2238
2477
  #
2239
2478
  def test_div
2479
+ print "\ntest_div [#{Time.now}]: "
2240
2480
  x = LongDecimal(224, 2) # 2.24 dx=1 sx=2
2241
2481
 
2242
2482
  y = LongDecimal(3, 1) # 0.3 dy=0 sy=1
@@ -2389,6 +2629,14 @@ class TestLongDecimal_class < RUNIT::TestCase
2389
2629
  zz = LongDecimalQuot(Rational(500, 224*3), 3)
2390
2630
  assert_kind_of(LongDecimalQuot, z, "z=#{z.inspect}")
2391
2631
  assert_equal(zz, z, "z=#{z.inspect}")
2632
+ end
2633
+
2634
+ #
2635
+ # test div_complexision of LongDecimal
2636
+ #
2637
+ def test_div_complex
2638
+ print "\ntest_div_complex [#{Time.now}]: "
2639
+ x = LongDecimal(224, 2) # 2.24 dx=1 sx=2
2392
2640
 
2393
2641
  y = Complex(5, 3)
2394
2642
  z = x / y
@@ -2405,6 +2653,7 @@ class TestLongDecimal_class < RUNIT::TestCase
2405
2653
  # test division of LongDecimal with Rational as result
2406
2654
  #
2407
2655
  def test_rdiv
2656
+ print "\ntest_rdiv [#{Time.now}]: "
2408
2657
  x = LongDecimal(224, 2)
2409
2658
 
2410
2659
  y = LongDecimal(3, 1)
@@ -2511,6 +2760,7 @@ class TestLongDecimal_class < RUNIT::TestCase
2511
2760
  # test division of LongDecimal
2512
2761
  #
2513
2762
  def test_divide
2763
+ print "\ntest_divide [#{Time.now}]: "
2514
2764
  x = LongDecimal(224, 2) # 2.24 dx=1 sx=2
2515
2765
 
2516
2766
  y = LongDecimal(3, 1) # 0.3 dy=0 sy=1
@@ -2759,8 +3009,17 @@ class TestLongDecimal_class < RUNIT::TestCase
2759
3009
  zz = Rational(500, 224*3).to_ld(0, LongMath::ROUND_UP)
2760
3010
  assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
2761
3011
  assert_equal(zz, z, "z=#{z.inspect}")
3012
+ end
3013
+
3014
+ #
3015
+ # test division of LongDecimal
3016
+ #
3017
+ def test_divide_complex
3018
+ print "\ntest_divide_complex [#{Time.now}]: "
3019
+ x = LongDecimal(224, 2) # 2.24 dx=1 sx=2
2762
3020
 
2763
3021
  y = Complex(5, 3)
3022
+ puts("x=#{x.inspect} y=#{y.inspect}")
2764
3023
  z = x.divide(y, LongMath::ROUND_DOWN)
2765
3024
  zz = 2.24 / Complex(5, 3)
2766
3025
  assert_kind_of(Complex, z, "z=#{z.inspect}")
@@ -2772,6 +3031,7 @@ class TestLongDecimal_class < RUNIT::TestCase
2772
3031
  # test division of LongDecimal
2773
3032
  #
2774
3033
  def test_divide_s
3034
+ print "\ntest_divide_s [#{Time.now}]: "
2775
3035
  x = LongDecimal(224, 2) # 2.24
2776
3036
 
2777
3037
  y = LongDecimal(3, 1) # 0.3
@@ -2990,6 +3250,14 @@ class TestLongDecimal_class < RUNIT::TestCase
2990
3250
  zz = Rational(1667, 2240).to_ld(224, LongMath::ROUND_UP)
2991
3251
  assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
2992
3252
  assert_equal(zz, z, "z=#{z.inspect}")
3253
+ end
3254
+
3255
+ #
3256
+ # test division of LongDecimal
3257
+ #
3258
+ def test_divide_s_complex
3259
+ print "\ntest_divide_s_complex [#{Time.now}]: "
3260
+ x = LongDecimal(224, 2) # 2.24
2993
3261
 
2994
3262
  y = Complex(5, 3)
2995
3263
  z = x.divide_s(y, 2, LongMath::ROUND_DOWN)
@@ -3003,6 +3271,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3003
3271
  # test square of LongDecimal
3004
3272
  #
3005
3273
  def test_square
3274
+ print "\ntest_square [#{Time.now}]: "
3006
3275
  10.times do |i|
3007
3276
  n = (i*i+i)/2
3008
3277
  x = LongDecimal(n, i)
@@ -3016,6 +3285,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3016
3285
  # test cube of LongDecimal
3017
3286
  #
3018
3287
  def test_cube
3288
+ print "\ntest_cube [#{Time.now}]: "
3019
3289
  10.times do |i|
3020
3290
  n = (i*i+i)/2
3021
3291
  x = LongDecimal(n, i)
@@ -3029,6 +3299,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3029
3299
  # test reciprocal of LongDecimal
3030
3300
  #
3031
3301
  def test_reciprocal
3302
+ print "\ntest_reciprocal [#{Time.now}]: "
3032
3303
  10.times do |i|
3033
3304
  k = 2*i+1
3034
3305
  n = (k*k+k)/2
@@ -3043,6 +3314,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3043
3314
  # test power (**) of LongDecimal
3044
3315
  #
3045
3316
  def test_pow
3317
+ print "\ntest_pow [#{Time.now}]: "
3046
3318
 
3047
3319
  x = LongDecimal(224, 2)
3048
3320
 
@@ -3105,6 +3377,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3105
3377
  # test division with remainder of LongDecimal
3106
3378
  #
3107
3379
  def test_divmod
3380
+ print "\ntest_divmod [#{Time.now}]: "
3108
3381
  x = LongDecimal(224, 2)
3109
3382
 
3110
3383
  y = LongDecimal(3, 1)
@@ -3218,6 +3491,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3218
3491
  # test dec, dec!, inc and inc! of LongDecimal
3219
3492
  #
3220
3493
  def test_inc_dec
3494
+ print "\ntest_inc_dec [#{Time.now}]: "
3221
3495
 
3222
3496
  x0 = LongDecimal(224, 1)
3223
3497
  x = LongDecimal(224, 1)
@@ -3242,6 +3516,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3242
3516
  # test pred and succ of LongDecimal
3243
3517
  #
3244
3518
  def test_pred_succ
3519
+ print "\ntest_pred_succ [#{Time.now}]: "
3245
3520
  x0 = LongDecimal(2245, 2)
3246
3521
  x = LongDecimal(2245, 2)
3247
3522
  ys = x.succ
@@ -3261,6 +3536,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3261
3536
  # test of &-operator of LongDecimal
3262
3537
  #
3263
3538
  def test_logand
3539
+ print "\ntest_logand [#{Time.now}]: "
3264
3540
  x = LongDecimal(224, 2) # 0x0e0 / 100
3265
3541
 
3266
3542
  y = LongDecimal(3, 1) # 0x01e / 100
@@ -3316,6 +3592,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3316
3592
  # test of |-operator of LongDecimal
3317
3593
  #
3318
3594
  def test_logior
3595
+ print "\ntest_logior [#{Time.now}]: "
3319
3596
  x = LongDecimal(224, 2) # 0x0e0 / 100
3320
3597
 
3321
3598
  y = LongDecimal(3, 1) # 0x01e / 100
@@ -3371,6 +3648,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3371
3648
  # test of ^-operator of LongDecimal
3372
3649
  #
3373
3650
  def test_logxor
3651
+ print "\ntest_logxor [#{Time.now}]: "
3374
3652
  x = LongDecimal(224, 2) # 0x0e0 / 100
3375
3653
 
3376
3654
  y = LongDecimal(3, 1) # 0x01e / 100
@@ -3426,6 +3704,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3426
3704
  # test of ^-operator of LongDecimal
3427
3705
  #
3428
3706
  def test_lognot
3707
+ print "\ntest_lognot [#{Time.now}]: "
3429
3708
  x = LongDecimal(224, 2) # 0x0e0 / 100
3430
3709
  y = ~x
3431
3710
  z = LongDecimal(-225, 2)
@@ -3442,6 +3721,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3442
3721
  # test << and >> of LongDecimal
3443
3722
  #
3444
3723
  def test_shift
3724
+ print "\ntest_shift [#{Time.now}]: "
3445
3725
  n = 12345678901234567890
3446
3726
  x = LongDecimal(n, 9)
3447
3727
  y = x << 5
@@ -3462,6 +3742,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3462
3742
  # test [] access to digits
3463
3743
  #
3464
3744
  def test_bin_digit
3745
+ print "\ntest_bin_digit [#{Time.now}]: "
3465
3746
  n = 12345678901234567890
3466
3747
  x = LongDecimal(n, 9)
3467
3748
  100.times do |i|
@@ -3478,6 +3759,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3478
3759
  # test move_point_left and move_point_right
3479
3760
  #
3480
3761
  def test_move_point
3762
+ print "\ntest_move_point [#{Time.now}]: "
3481
3763
  n = 12345678901234567890
3482
3764
  x = LongDecimal(n, 9)
3483
3765
 
@@ -3527,6 +3809,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3527
3809
  # test moving of decimal point of LongDecimal
3528
3810
  #
3529
3811
  def test_move_point2
3812
+ print "\ntest_move_point2 [#{Time.now}]: "
3530
3813
  x = LongDecimal(224, 2)
3531
3814
 
3532
3815
  y = x.move_point_left(0)
@@ -3563,6 +3846,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3563
3846
  # test sqrt of LongDecimal
3564
3847
  #
3565
3848
  def test_sqrt
3849
+ print "\ntest_sqrt [#{Time.now}]: "
3566
3850
  x = LongDecimal.zero!(101)
3567
3851
  y = check_sqrt(x, 120, LongDecimal::ROUND_UNNECESSARY, 0, 0, "zero")
3568
3852
  assert(y.zero?, "sqrt(0)")
@@ -3645,6 +3929,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3645
3929
  # test sqrt_with_remainder of LongDecimal
3646
3930
  #
3647
3931
  def test_sqrt_with_remainder
3932
+ print "\ntest_sqrt_with_remainder [#{Time.now}]: "
3648
3933
  x = LongDecimal.zero!(101)
3649
3934
  r = check_sqrt_with_remainder(x, 120, "zero")
3650
3935
  assert(r.zero?, "rsqrt(0)")
@@ -3677,6 +3962,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3677
3962
  # test LongMath.sqrt with non-LongDecimal arguments
3678
3963
  #
3679
3964
  def test_non_ld_sqrt
3965
+ print "\ntest_non_ld_sqrt [#{Time.now}]: "
3680
3966
  xi = 77
3681
3967
  yi = LongMath.sqrt(xi, 31, LongMath::ROUND_HALF_EVEN)
3682
3968
  zi = yi.square.round_to_scale(30, LongMath::ROUND_HALF_EVEN)
@@ -3700,6 +3986,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3700
3986
  # test cbrt of LongDecimal
3701
3987
  #
3702
3988
  def test_cbrt
3989
+ print "\ntest_cbrt [#{Time.now}]: "
3703
3990
  x = LongDecimal.zero!(101)
3704
3991
  y = check_cbrt(x, 120, LongDecimal::ROUND_UNNECESSARY, 0, 0, "zero")
3705
3992
  assert(y.zero?, "cbrt(0)")
@@ -3782,6 +4069,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3782
4069
  # test cbrt_with_remainder of LongDecimal
3783
4070
  #
3784
4071
  def test_cbrt_with_remainder
4072
+ print "\ntest_cbrt_with_remainder [#{Time.now}]: "
3785
4073
  x = LongDecimal.zero!(101)
3786
4074
  r = check_cbrt_with_remainder(x, 120, "zero")
3787
4075
  assert(r.zero?, "rcbrt(0)")
@@ -3814,6 +4102,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3814
4102
  # test LongMath.cbrt with non-LongDecimal arguments
3815
4103
  #
3816
4104
  def test_non_ld_cbrt
4105
+ print "\ntest_non_ld_cbrt [#{Time.now}]: "
3817
4106
  xi = 77
3818
4107
  yi = LongMath.cbrt(xi, 32, LongMath::ROUND_HALF_EVEN)
3819
4108
  zi = yi.cube.round_to_scale(30, LongMath::ROUND_HALF_EVEN)
@@ -3837,6 +4126,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3837
4126
  # test absolute value of LongDecimal
3838
4127
  #
3839
4128
  def test_abs
4129
+ print "\ntest_abs [#{Time.now}]: "
3840
4130
  x = LongDecimal(-224, 2)
3841
4131
  y = x.abs
3842
4132
  assert_equal(-x, y, "abs of negative")
@@ -3852,6 +4142,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3852
4142
  # test ufo-operator (<=>) of LongDecimal
3853
4143
  #
3854
4144
  def test_ufo
4145
+ print "\ntest_ufo [#{Time.now}]: "
3855
4146
  x = LongDecimal(224, 2)
3856
4147
 
3857
4148
  z = x <=> x
@@ -3908,6 +4199,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3908
4199
  # test is_int? of LongDecimal
3909
4200
  #
3910
4201
  def test_is_int
4202
+ print "\ntest_is_int [#{Time.now}]: "
3911
4203
  assert(LongDecimal(1, 0).is_int?, "1, 0")
3912
4204
  assert(LongDecimal(90, 1).is_int?, "90, 1")
3913
4205
  assert(LongDecimal(200, 2).is_int?, "200, 2")
@@ -3924,6 +4216,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3924
4216
  # test zero? of LongDecimal
3925
4217
  #
3926
4218
  def test_zero
4219
+ print "\ntest_zero [#{Time.now}]: "
3927
4220
  assert(LongDecimal(0, 1000).zero?, "0, 1000")
3928
4221
  assert(LongDecimal(0, 0).zero?, "0, 0")
3929
4222
  assert(LongDecimal.zero!(100).zero?, "0, 100")
@@ -3936,6 +4229,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3936
4229
  # test one? of LongDecimal
3937
4230
  #
3938
4231
  def test_one
4232
+ print "\ntest_one [#{Time.now}]: "
3939
4233
  assert(LongDecimal(10**1000, 1000).one?, "1, 1000")
3940
4234
  assert(LongDecimal(1, 0).one?, "1, 0")
3941
4235
  assert(LongDecimal.one!(100).one?, "1, 100")
@@ -3950,6 +4244,7 @@ class TestLongDecimal_class < RUNIT::TestCase
3950
4244
  # test sign-method of LongDecimal
3951
4245
  #
3952
4246
  def test_sgn
4247
+ print "\ntest_sgn [#{Time.now}]: "
3953
4248
  x = LongDecimal(0, 5)
3954
4249
  s = x.sgn
3955
4250
  assert_equal(0, s, "must be 0")
@@ -3965,11 +4260,19 @@ class TestLongDecimal_class < RUNIT::TestCase
3965
4260
  # test equality-comparison (==) of LongDecimal
3966
4261
  #
3967
4262
  def test_equal
4263
+ print "\ntest_equal [#{Time.now}]: "
3968
4264
  x = LongDecimal(224, 2)
3969
4265
  y = LongDecimal(2240, 3)
3970
4266
  assert((x <=> y) == 0, "diff is zero")
3971
- assert(x != y, "but not equal")
3972
- assert(! (x == y), "but not equal")
4267
+ assert_equal(x, y, "equal")
4268
+ assert(x == y, "equal ==")
4269
+ assert(x === y, "equal ===")
4270
+ assert(! (x.eql? y), "not eql?")
4271
+ assert((y <=> x) == 0, "diff is yero")
4272
+ assert_equal(y, x, "equal")
4273
+ assert(y == x, "equal ==")
4274
+ assert(y === x, "equal ===")
4275
+ assert(! (y.eql? x), "not eql?")
3973
4276
  assert_equal(x, x, "x equals x")
3974
4277
  assert_equal(y, y, "y equals y")
3975
4278
  end
@@ -3978,30 +4281,44 @@ class TestLongDecimal_class < RUNIT::TestCase
3978
4281
  # test value-equality-comparison (===) of LongDecimal
3979
4282
  #
3980
4283
  def test_val_equal
4284
+ print "\ntest_val_equal [#{Time.now}]: "
3981
4285
  x = LongDecimal(224, 2)
3982
4286
  y = LongDecimal(2240, 3)
3983
- assert((x === y), "value equal")
3984
- assert(x != y, "but not equal")
4287
+ assert(x === y, "value equal")
4288
+ assert(y === x, "value equal")
4289
+ assert(x == y, "but not equal")
4290
+ assert(y == x, "but not equal")
4291
+ assert_val_equal(x, y)
4292
+ assert_val_equal(y, x)
4293
+ assert_val_equal(x, x)
4294
+ assert_val_equal(y, y)
4295
+ assert(! (x.eql? y), "not eql?")
4296
+ assert(! (y.eql? x), "not eql?")
3985
4297
  assert(x === x, "x equals x")
3986
4298
  assert(y === y, "y equals y")
3987
4299
  x = 1.to_ld(100)
3988
4300
  y = 1
3989
- assert((x === y), "value equal")
3990
- assert(x != y, "but not equal")
4301
+ assert(x === y, "value equal")
4302
+ assert(x == y, "but not equal")
3991
4303
  assert(x === x, "x equals x")
3992
4304
  assert(y === y, "y equals y")
4305
+ assert(! (x.eql? y), "not eql?")
4306
+ assert(! (y.eql? x), "not eql?")
3993
4307
  x = LongDecimal(123456, 3)
3994
4308
  y = Rational(123456, 1000)
3995
- assert((x === y), "value equal")
3996
- assert(x != y, "but not equal")
4309
+ assert(x === y, "value equal")
4310
+ assert(x == y, "but not equal")
3997
4311
  assert(x === x, "x equals x")
3998
4312
  assert(y === y, "y equals y")
4313
+ assert(! (x.eql? y), "not eql? x=#{x.inspect} y=#{y.inspect}")
4314
+ assert(! (y.eql? x), "not eql? x=#{x.inspect} y=#{y.inspect}")
3999
4315
  end
4000
4316
 
4001
4317
  #
4002
4318
  # test unit() of LongDecimal
4003
4319
  #
4004
4320
  def test_unit
4321
+ print "\ntest_unit [#{Time.now}]: "
4005
4322
  10.times do |i|
4006
4323
  x = LongDecimal.zero!(i)
4007
4324
  u = x.unit
@@ -4024,6 +4341,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4024
4341
  # test sunit() of LongDecimal
4025
4342
  #
4026
4343
  def test_sunit
4344
+ print "\ntest_sunit [#{Time.now}]: "
4027
4345
  10.times do |i|
4028
4346
  x = LongDecimal.zero!(i)
4029
4347
  u = x.sunit
@@ -4048,6 +4366,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4048
4366
  # test denominator of LongDecimal
4049
4367
  #
4050
4368
  def test_denominator
4369
+ print "\ntest_denominator [#{Time.now}]: "
4051
4370
  x = LongDecimal("-2.20")
4052
4371
  assert_equal(100, x.denominator, "-2.20")
4053
4372
  x = LongDecimal("2.20")
@@ -4075,6 +4394,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4075
4394
  # test construction of LongDecimalQuot from LongDecimal
4076
4395
  #
4077
4396
  def test_ldq_ld_init
4397
+ print "\ntest_ldq_ld_init [#{Time.now}]: "
4078
4398
  x = LongDecimal(224, 2) # 2.24 dx=1 sx=2
4079
4399
  y = LongDecimal(225, 3) # 0.225 dy=0 sy=3
4080
4400
  z = LongDecimalQuot(x, y)
@@ -4092,6 +4412,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4092
4412
  # test sint_digits10 of LongDecimalQuot
4093
4413
  #
4094
4414
  def test_ldq_sint_digits10
4415
+ print "\ntest_ldq_sint_digits10 [#{Time.now}]: "
4095
4416
  assert_equal(nil, LongDecimalQuot(LongDecimal("0.0000"), 1.to_ld).sint_digits10, "0.0000")
4096
4417
  assert_equal(-3, LongDecimalQuot(LongDecimal("0.0009"), 1.to_ld).sint_digits10, "0.0009")
4097
4418
  assert_equal(-2, LongDecimalQuot(LongDecimal("0.0099"), 1.to_ld).sint_digits10, "0.0099")
@@ -4135,6 +4456,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4135
4456
  # test rounding of LongDecimalQuot with ROUND_UP
4136
4457
  #
4137
4458
  def test_ldq_round_to_scale_up
4459
+ print "\ntest_ldq_round_to_scale_up [#{Time.now}]: "
4138
4460
 
4139
4461
  # 0.99555555555555...
4140
4462
  l = LongDecimalQuot(Rational(224, 225), 0)
@@ -4171,6 +4493,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4171
4493
  # test rounding of LongDecimalQuot with ROUND_DOWN
4172
4494
  #
4173
4495
  def test_ldq_round_to_scale_down
4496
+ print "\ntest_ldq_round_to_scale_down [#{Time.now}]: "
4174
4497
 
4175
4498
  # 0.99555555555555...
4176
4499
  l = LongDecimalQuot(Rational(224, 225), 0)
@@ -4207,6 +4530,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4207
4530
  # test rounding of LongDecimalQuot with ROUND_CEILING
4208
4531
  #
4209
4532
  def test_ldq_round_to_scale_ceiling
4533
+ print "\ntest_ldq_round_to_scale_ceiling [#{Time.now}]: "
4210
4534
 
4211
4535
  # 0.99555555555555...
4212
4536
  l = LongDecimalQuot(Rational(224, 225), 0)
@@ -4242,6 +4566,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4242
4566
  # test rounding of LongDecimalQuot with ROUND_FLOOR
4243
4567
  #
4244
4568
  def test_ldq_round_to_scale_floor
4569
+ print "\ntest_ldq_round_to_scale_floor [#{Time.now}]: "
4245
4570
 
4246
4571
  # 0.99555555555555...
4247
4572
  l = LongDecimalQuot(Rational(224, 225), 0)
@@ -4277,6 +4602,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4277
4602
  # test rounding of LongDecimalQuot with ROUND_HALF_UP
4278
4603
  #
4279
4604
  def test_ldq_round_to_scale_half_up
4605
+ print "\ntest_ldq_round_to_scale_half_up [#{Time.now}]: "
4280
4606
 
4281
4607
  # 0.99555555555555...
4282
4608
  l = LongDecimalQuot(Rational(224, 225), 0)
@@ -4323,6 +4649,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4323
4649
  # test rounding of LongDecimalQuot with ROUND_HALF_DOWN
4324
4650
  #
4325
4651
  def test_ldq_round_to_scale_half_down
4652
+ print "\ntest_ldq_round_to_scale_half_down [#{Time.now}]: "
4326
4653
 
4327
4654
  # 0.99555555555555...
4328
4655
  l = LongDecimalQuot(Rational(224, 225), 0)
@@ -4369,6 +4696,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4369
4696
  # test rounding of LongDecimalQuot with ROUND_HALF_CEILING
4370
4697
  #
4371
4698
  def test_ldq_round_to_scale_half_ceiling
4699
+ print "\ntest_ldq_round_to_scale_half_ceiling [#{Time.now}]: "
4372
4700
 
4373
4701
  # 0.99555555555555...
4374
4702
  l = LongDecimalQuot(Rational(224, 225), 0)
@@ -4415,6 +4743,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4415
4743
  # test rounding of LongDecimalQuot with ROUND_HALF_FLOOR
4416
4744
  #
4417
4745
  def test_ldq_round_to_scale_half_floor
4746
+ print "\ntest_ldq_round_to_scale_half_floor [#{Time.now}]: "
4418
4747
 
4419
4748
  # 0.99555555555555...
4420
4749
  l = LongDecimalQuot(Rational(224, 225), 0)
@@ -4461,6 +4790,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4461
4790
  # test rounding of LongDecimalQuot with ROUND_HALF_EVEN
4462
4791
  #
4463
4792
  def test_ldq_round_to_scale_half_even
4793
+ print "\ntest_ldq_round_to_scale_half_even [#{Time.now}]: "
4464
4794
 
4465
4795
  # 0.99555555555555...
4466
4796
  l = LongDecimalQuot(Rational(224, 225), 0)
@@ -4508,6 +4838,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4508
4838
  # test rounding of LongDecimalQuot with ROUND_UNNECESSARY
4509
4839
  #
4510
4840
  def test_ldq_round_to_scale_unnecessary
4841
+ print "\ntest_ldq_round_to_scale_unnecessary [#{Time.now}]: "
4511
4842
  l = LongDecimalQuot(Rational(225, 4), 5)
4512
4843
  r = l.round_to_scale(2, LongDecimal::ROUND_UNNECESSARY)
4513
4844
  assert_equal("56.25", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
@@ -4523,6 +4854,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4523
4854
  # test conversion of LongDecimalQuot to String
4524
4855
  #
4525
4856
  def test_ldq_to_s
4857
+ print "\ntest_ldq_to_s [#{Time.now}]: "
4526
4858
  l = LongDecimalQuot(Rational(224, 225), 226)
4527
4859
  assert_equal("224/225[226]", l.to_s, "l=#{l.inspect}")
4528
4860
  l = LongDecimalQuot(Rational(-224, 225), 226)
@@ -4533,6 +4865,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4533
4865
  # test conversion of LongDecimalQuot to Rational
4534
4866
  #
4535
4867
  def test_ldq_to_r
4868
+ print "\ntest_ldq_to_r [#{Time.now}]: "
4536
4869
  rr = Rational(224, 225)
4537
4870
  l = LongDecimalQuot(rr, 22)
4538
4871
  r = l.to_r
@@ -4554,6 +4887,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4554
4887
  # test conversion of LongDecimalQuot to Float
4555
4888
  #
4556
4889
  def test_ldq_to_f
4890
+ print "\ntest_ldq_to_f [#{Time.now}]: "
4557
4891
  rr = Rational(224, 225)
4558
4892
  l = LongDecimalQuot(rr, 22)
4559
4893
  f = l.to_f
@@ -4578,6 +4912,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4578
4912
  # test conversion to BigDecimal
4579
4913
  #
4580
4914
  def test_ldq_to_bd
4915
+ print "\ntest_ldq_to_bd [#{Time.now}]: "
4581
4916
  rr = Rational(224, 225)
4582
4917
  l = LongDecimalQuot(rr, 22)
4583
4918
  b = l.to_bd
@@ -4604,6 +4939,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4604
4939
  # test to_i of LongDecimalQuot
4605
4940
  #
4606
4941
  def test_ldq_to_i
4942
+ print "\ntest_ldq_to_i [#{Time.now}]: "
4607
4943
  rr = Rational(224, 225)
4608
4944
  l = LongDecimalQuot(rr, 22)
4609
4945
  i = l.to_i
@@ -4628,6 +4964,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4628
4964
  # test to_ld of LongDecimalQuot
4629
4965
  #
4630
4966
  def test_ldq_to_ld
4967
+ print "\ntest_ldq_to_ld [#{Time.now}]: "
4631
4968
  x = LongDecimalQuot(1, 100)
4632
4969
  y = x.to_ld
4633
4970
  assert_kind_of(LongDecimal, y, "must be ld")
@@ -4659,6 +4996,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4659
4996
  # test negation operator (unary -) of LongDecimalQuot
4660
4997
  #
4661
4998
  def test_ldq_negation
4999
+ print "\ntest_ldq_negation [#{Time.now}]: "
4662
5000
  x = LongDecimalQuot(Rational(0, 2), 3)
4663
5001
  assert_equal(-x, x, "x and -x are equal for negative x=#{x.inspect}")
4664
5002
  x = LongDecimalQuot(Rational(224, 225), 226)
@@ -4673,6 +5011,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4673
5011
  # test addition operator (binary +) of LongDecimalQuot
4674
5012
  #
4675
5013
  def test_ldq_add
5014
+ print "\ntest_ldq_add [#{Time.now}]: "
4676
5015
  x = LongDecimalQuot(Rational(224, 225), 226)
4677
5016
 
4678
5017
  y = LongDecimal(3, 1)
@@ -4736,6 +5075,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4736
5075
  # test subtraction operator (binary -) of LongDecimalQuot
4737
5076
  #
4738
5077
  def test_ldq_sub
5078
+ print "\ntest_ldq_sub [#{Time.now}]: "
4739
5079
  x = LongDecimalQuot(Rational(224, 225), 226)
4740
5080
 
4741
5081
  y = LongDecimal(3, 1)
@@ -4803,6 +5143,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4803
5143
  # test multiplication operator (*) of LongDecimalQuot
4804
5144
  #
4805
5145
  def test_ldq_mul
5146
+ print "\ntest_ldq_mul [#{Time.now}]: "
4806
5147
  x = LongDecimalQuot(Rational(224, 225), 226)
4807
5148
 
4808
5149
  y = LongDecimal(3, 1)
@@ -4864,6 +5205,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4864
5205
  # test division operator (/) of LongDecimalQuot
4865
5206
  #
4866
5207
  def test_ldq_div
5208
+ print "\ntest_ldq_div [#{Time.now}]: "
4867
5209
  x = LongDecimalQuot(Rational(224, 225), 226)
4868
5210
 
4869
5211
  y = LongDecimal(3, 1)
@@ -4931,6 +5273,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4931
5273
  # test power operator (**) of LongDecimalQuot
4932
5274
  #
4933
5275
  def test_ldq_pow
5276
+ print "\ntest_ldq_pow [#{Time.now}]: "
4934
5277
 
4935
5278
  x = LongDecimalQuot(Rational(224, 225), 226)
4936
5279
 
@@ -4993,6 +5336,7 @@ class TestLongDecimal_class < RUNIT::TestCase
4993
5336
  # test divmod of LongDecimalQuot for division with remainder
4994
5337
  #
4995
5338
  def test_ldq_divmod
5339
+ print "\ntest_ldq_divmod [#{Time.now}]: "
4996
5340
  x = LongDecimalQuot(Rational(224, 225), 226)
4997
5341
 
4998
5342
  y = LongDecimal(3, 1)
@@ -5049,7 +5393,7 @@ class TestLongDecimal_class < RUNIT::TestCase
5049
5393
  assert_kind_of(LongDecimalQuot, r, "r must be LongDecimal")
5050
5394
  assert(r.abs < x.abs, "remainder must be less then divisor")
5051
5395
  zz = LongDecimalQuot(Rational(225*5, 224*3), 226*2)
5052
- assert_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect}")
5396
+ assert_equal(zz, q + r / x, "z=q=#{q.inspect} r=#{r.inspect} x=#{x.inspect} r/x=#{(r/x).inspect}")
5053
5397
 
5054
5398
  y = LongDecimalQuot(Rational(5, 3), 3)
5055
5399
  q, r = x.divmod y
@@ -5078,6 +5422,7 @@ class TestLongDecimal_class < RUNIT::TestCase
5078
5422
  # test dec, dec!, inc and inc! of LongDecimalQuot
5079
5423
  #
5080
5424
  def test_ldq_inc_dec
5425
+ print "\ntest_ldq_inc_dec [#{Time.now}]: "
5081
5426
 
5082
5427
  x0 = LongDecimalQuot(Rational(224, 225), 1)
5083
5428
  x = LongDecimalQuot(Rational(224, 225), 1)
@@ -5102,6 +5447,7 @@ class TestLongDecimal_class < RUNIT::TestCase
5102
5447
  # test absolute value of LongDecimalQuot
5103
5448
  #
5104
5449
  def test_ldq_abs
5450
+ print "\ntest_ldq_abs [#{Time.now}]: "
5105
5451
  x = LongDecimalQuot(Rational(-224, 225), 226)
5106
5452
  y = x.abs
5107
5453
  assert_equal(-x, y, "abs of negative")
@@ -5117,6 +5463,7 @@ class TestLongDecimal_class < RUNIT::TestCase
5117
5463
  # test ufo operator (<=>) of LongDecimalQuot
5118
5464
  #
5119
5465
  def test_ldq_ufo
5466
+ print "\ntest_ldq_ufo [#{Time.now}]: "
5120
5467
  x = LongDecimalQuot(Rational(224, 225), 226)
5121
5468
 
5122
5469
  z = x <=> x
@@ -5173,6 +5520,7 @@ class TestLongDecimal_class < RUNIT::TestCase
5173
5520
  # test is_int? of LongDecimalQuot
5174
5521
  #
5175
5522
  def test_ldq_is_int
5523
+ print "\ntest_ldq_is_int [#{Time.now}]: "
5176
5524
  assert(! LongDecimalQuot(Rational(1, 2), 0).is_int?, "1, 2")
5177
5525
  assert(! LongDecimalQuot(Rational(90, 91), 1).is_int?, "90, 91")
5178
5526
  assert(! LongDecimalQuot(Rational(200, 3), 2).is_int?, "200, 3")
@@ -5189,6 +5537,7 @@ class TestLongDecimal_class < RUNIT::TestCase
5189
5537
  # test zero? of LongDecimalQuot
5190
5538
  #
5191
5539
  def test_ldq_zero
5540
+ print "\ntest_ldq_zero [#{Time.now}]: "
5192
5541
  assert(LongDecimalQuot(0, 1000).zero?, "0, 1000")
5193
5542
  assert(LongDecimalQuot(0, 0).zero?, "0, 0")
5194
5543
  assert(! LongDecimalQuot(1, 1000).zero?, "1, 1000")
@@ -5199,6 +5548,7 @@ class TestLongDecimal_class < RUNIT::TestCase
5199
5548
  # test one? of LongDecimalQuot
5200
5549
  #
5201
5550
  def test_ldq_one
5551
+ print "\ntest_ldq_one [#{Time.now}]: "
5202
5552
  assert(LongDecimalQuot(1, 1000).one?, "1, 1000")
5203
5553
  assert(LongDecimalQuot(1, 0).one?, "1, 0")
5204
5554
  assert(! LongDecimalQuot(0, 1000).one?, "0, 1000")
@@ -5210,6 +5560,7 @@ class TestLongDecimal_class < RUNIT::TestCase
5210
5560
  # test sign method of LongDecimalQuot
5211
5561
  #
5212
5562
  def test_ldq_sgn
5563
+ print "\ntest_ldq_sgn [#{Time.now}]: "
5213
5564
  x = LongDecimalQuot(Rational(0, 5), 1000)
5214
5565
  s = x.sgn
5215
5566
  assert_equal(0, s, "must be 0")
@@ -5225,19 +5576,23 @@ class TestLongDecimal_class < RUNIT::TestCase
5225
5576
  # test equality operator (==) of LongDecimalQuot
5226
5577
  #
5227
5578
  def test_ldq_equal
5579
+ print "\ntest_ldq_equal [#{Time.now}]: "
5228
5580
  x = LongDecimalQuot(Rational(224, 225), 226)
5229
5581
  y = LongDecimalQuot(Rational(224, 225), 227)
5230
5582
  assert((x <=> y) == 0, "diff is zero")
5231
- assert(x != y, "but not equal")
5232
- assert(! (x == y), "but not equal")
5583
+ assert(x == y, "but not equal")
5584
+ assert(x === y, "but not equal")
5233
5585
  assert_equal(x, x, "x equals x")
5234
5586
  assert_equal(y, y, "y equals y")
5587
+ assert(! (x.eql? y), "! #{x.inspect} eql? #{y.inspect}")
5588
+ assert(! (y.eql? x), "! #{y.inspect} eql? #{x.inspect}")
5235
5589
  end
5236
5590
 
5237
5591
  #
5238
5592
  # test mul minverse of RoundingMode
5239
5593
  #
5240
5594
  def test_rm_minverse
5595
+ print "\ntest_rm_minverse [#{Time.now}]: "
5241
5596
  assert_equal(LongMath::ROUND_UP, LongMath::ROUND_DOWN.minverse)
5242
5597
  assert_equal(LongMath::ROUND_DOWN, LongMath::ROUND_UP.minverse)
5243
5598
  assert_equal(LongMath::ROUND_CEILING, LongMath::ROUND_FLOOR.minverse)
@@ -5254,6 +5609,7 @@ class TestLongDecimal_class < RUNIT::TestCase
5254
5609
  # test ainverse of RoundingMode
5255
5610
  #
5256
5611
  def test_rm_ainverse
5612
+ print "\ntest_rm_ainverse [#{Time.now}]: "
5257
5613
  assert_equal(LongMath::ROUND_UP, LongMath::ROUND_UP.ainverse)
5258
5614
  assert_equal(LongMath::ROUND_DOWN, LongMath::ROUND_DOWN.ainverse)
5259
5615
  assert_equal(LongMath::ROUND_CEILING, LongMath::ROUND_FLOOR.ainverse)
@@ -5267,7 +5623,83 @@ class TestLongDecimal_class < RUNIT::TestCase
5267
5623
  end
5268
5624
 
5269
5625
 
5626
+ #
5627
+ # helper method for test_npower10
5628
+ #
5629
+ def check_npower10(x, z = nil)
5630
+ y = LongMath.npower10(x)
5631
+ if (z.nil?) then
5632
+ @powers_of_10 ||= []
5633
+ z = @powers_of_10[x]
5634
+ if (z.nil?)
5635
+ z = 10**x
5636
+ @powers_of_10[x] = z
5637
+ end
5638
+ elsif (z & 0xff == 0)
5639
+ zz = @powers_of_10[x]
5640
+ if (zz.nil?)
5641
+ zz = 10**x
5642
+ @powers_of_10[x] = zz
5643
+ end
5644
+ assert_equal(z, zz)
5645
+ puts("exp=" + x.to_s)
5646
+ $stdout.flush
5647
+ else
5648
+ @powers_of_10[x] ||= z
5649
+ end
5650
+ assert_equal(z, y, "x=#{x}")
5651
+ end
5652
+
5653
+ #
5654
+ # test LongMath.npower10
5655
+ #
5656
+ def test_npower10
5657
+ print "\ntest_npower10 [#{Time.now}] (240 min): "
5658
+ $stdout.flush
5659
+
5660
+ prec = LongMath.prec_limit
5661
+ LongMath.prec_limit=LongMath::MAX_PREC
5662
+
5663
+ 12.times do |i|
5664
+ check_npower10(3**i)
5665
+ puts(3**i)
5666
+ end
5667
+
5668
+ 12.times do |i|
5669
+ check_npower10(3**i)
5670
+ puts(3**i)
5671
+ end
5672
+
5673
+ y = 1
5674
+ 1024.times do |i|
5675
+ check_npower10(i, y)
5676
+ y *= 10
5677
+ end
5678
+ y = 1
5679
+ y0 = 1
5680
+ xs = 4096
5681
+ yf = 10**xs
5682
+ x0 = 2046
5683
+ y0 = 10**x0
5684
+ 60.times do |i|
5685
+ puts "i=" + i.to_s
5686
+ $stdout.flush
5687
+ y = y0
5688
+ x = x0
5689
+ 5.times do |j|
5690
+ check_npower10(x, y)
5691
+ x += 1
5692
+ y *= 10
5693
+ end
5694
+ x0 += xs
5695
+ y0 *= yf
5696
+ end
5697
+
5698
+ LongMath.prec_limit = prec
5699
+ end
5700
+
5270
5701
  def test_scale_equal
5702
+ print "\ntest_scale_equal [#{Time.now}]: "
5271
5703
  x = LongDecimal(3, 9)
5272
5704
  y = LongDecimal(4, 9)
5273
5705
  z = LongDecimal(4, 8)
@@ -5288,6 +5720,7 @@ class TestLongDecimal_class < RUNIT::TestCase
5288
5720
  end
5289
5721
 
5290
5722
  def test_scale_ufo
5723
+ print "\ntest_scale_ufo [#{Time.now}]: "
5291
5724
  x = LongDecimal(3, 9)
5292
5725
  y = LongDecimal(4, 9)
5293
5726
  z = LongDecimal(4, 7)
@@ -5311,6 +5744,6 @@ class TestLongDecimal_class < RUNIT::TestCase
5311
5744
 
5312
5745
  end
5313
5746
 
5314
- RUNIT::CUI::TestRunner.run(TestLongDecimal_class.suite)
5747
+ # RUNIT::CUI::TestRunner.run(TestLongDecimal_class.suite)
5315
5748
 
5316
5749
  # end of file testlongdecimal.rb