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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  #
4
4
  # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/make_doc.rb,v 1.3 2009/04/15 19:29:37 bk1 Exp $
5
- # CVS-Label: $Name: BETA_02_01 $
5
+ # CVS-Label: $Name: RELEASE_1_00_00 $
6
6
  # Author: $Author: bk1 $ (Karl Brodowsky)
7
7
  #
8
8
 
@@ -4,31 +4,766 @@
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-extra.rb,v 1.6 2009/04/19 20:47:41 bk1 Exp $
8
- # CVS-Label: $Name: BETA_02_01 $
7
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal-extra.rb,v 1.28 2009/05/17 21:27:20 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 "lib/long-decimal-extra.rb"
18
20
  load "test/testlongdeclib.rb"
19
21
 
22
+ LongMath.prec_overflow_handling = :warn_use_max
23
+
20
24
  #
21
25
  # test class for LongDecimal and LongDecimalQuot
22
26
  #
23
- class TestLongDecimalExtra_class < RUNIT::TestCase
27
+ class TestLongDecimalExtra_class < Test::Unit::TestCase # RUNIT::TestCase
24
28
  include TestLongDecHelper
25
29
 
26
- @RCS_ID='-$Id: testlongdecimal-extra.rb,v 1.6 2009/04/19 20:47:41 bk1 Exp $-'
30
+ @RCS_ID='-$Id: testlongdecimal-extra.rb,v 1.28 2009/05/17 21:27:20 bk1 Exp $-'
31
+
32
+ MAX_FLOAT_I = (Float::MAX).to_i
33
+
34
+ #
35
+ # test conversion to Float
36
+ #
37
+ def test_to_f
38
+ print "\ntest_to_f [#{Time.now}]: "
39
+ l = LongDecimal(224, 0)
40
+ assert((l.to_f - 224).abs < 224 * 0.000001, "l=#{l.inspect}") # t2
41
+ assert(((-l).to_f + 224).abs < 224 * 0.000001, "l=#{l.inspect}")
42
+ l = LongDecimal(224, 1)
43
+ assert((l.to_f - 22.4).abs < 22.4 * 0.000001, "l=#{l.inspect}")
44
+ assert(((-l).to_f + 22.4).abs < 22.4 * 0.000001, "l=#{l.inspect}") # t3
45
+ l = LongDecimal(224, 2)
46
+ assert((l.to_f - 2.24).abs < 2.24 * 0.000001, "l=#{l.inspect}")
47
+ assert(((-l).to_f + 2.24).abs < 2.24 * 0.000001, "l=#{l.inspect}")
48
+ l = LongDecimal(224, 3)
49
+ assert((l.to_f - 0.224).abs < 0.224 * 0.000001, "l=#{l.inspect}")
50
+ assert(((-l).to_f + 0.224).abs < 0.224 * 0.000001, "l=#{l.inspect}")
51
+ l = LongDecimal(224, 4)
52
+ assert((l.to_f - 0.0224).abs < 0.0224 * 0.000001, "l=#{l.inspect}")
53
+ assert(((-l).to_f + 0.0224).abs < 0.0224 * 0.000001, "l=#{l.inspect}")
54
+
55
+ l = LongDecimal("0." + ("0" * 30) + "1" + ("0" * 500))
56
+ assert((l.to_f - 1e-31).abs < 1e-32, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
57
+ assert(((-l).to_f + 1e-31).abs < 1e-32, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
58
+ l = LongDecimal("0." + ("0" * 200) + "1" + ("0" * 500))
59
+ assert((l.to_f - 1e-201).abs < 1e-202, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
60
+ assert(((-l).to_f + 1e-201).abs < 1e-202, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
61
+ l = LongDecimal("0." + ("0" * 280) + "1" + ("0" * 500))
62
+ assert((l.to_f - 1e-281).abs < 1e-282, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
63
+ assert(((-l).to_f + 1e-281).abs < 1e-282, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
64
+
65
+ l = LongDecimal("0.00000000000000000000000000000000000000000000000000002090000000000000000000000000332000042999999999999999934478499999999999999999999979183597303900000000000002280678889571719972270000000870125632696979999999999928587104894304210318436999963636067429710015568287618182130517226303011944557351440293760289098908449297658922618709026683663019359834144789263320")
66
+ delta1 = (l - LongDecimal("0.0000000000000000000000000000000000000000000000000000209"))
67
+ delta2 = delta1.to_f.abs
68
+ assert(delta2 < 1e-60, "l=#{l.inspect}=#{l.to_s} delta1=#{delta1} delta2=#{delta2}")
69
+ assert(((-l).to_f + 0.0000000000000000000000000000000000000000000000000000209).abs < 1e-60, "l=#{l.inspect}")
70
+ end
71
+
72
+ #
73
+ # test to_f of Rational (trivial cases)
74
+ #
75
+ def test_r_to_f_small
76
+ print "\ntest_r_to_f_small [#{Time.now}]: "
77
+ # trivial: 0, 1, -1,...
78
+ r = Rational(0, 1)
79
+ assert_equal(0.0, r.to_f)
80
+ r = Rational(1, 1)
81
+ assert_equal(1.0, r.to_f)
82
+ r = Rational(-1, 1)
83
+ assert_equal(-1.0, r.to_f)
84
+ r = Rational(3, 2)
85
+ assert_equal(1.5, r.to_f)
86
+ r = Rational(-3, 2)
87
+ assert_equal(-1.5, r.to_f)
88
+ end
89
+
90
+ #
91
+ # test to_f of Rational (max of to_f_orig)
92
+ #
93
+ def test_r_to_f_max_float
94
+ print "\ntest_r_to_f_max_float [#{Time.now}]: "
95
+ # still numerator and denominator expressable as Float
96
+ r = Rational(LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE - 1)
97
+ assert_equal(1.0, r.to_f)
98
+ assert_equal(1.0, r.to_f_orig)
99
+ r = Rational(-LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE - 1)
100
+ assert_equal(-1.0, r.to_f)
101
+ assert_equal(-1.0, r.to_f_orig)
102
+ r = Rational(LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE)
103
+ assert_equal(1.0, r.to_f)
104
+ assert_equal(1.0, r.to_f_orig)
105
+ r = Rational(-(LongMath::MAX_FLOATABLE + 1), LongMath::MAX_FLOATABLE)
106
+ assert_equal(-1.0, r.to_f)
107
+ assert_equal(-1.0, r.to_f_orig)
108
+ r = Rational(LongMath::MAX_FLOATABLE, 1)
109
+ assert_equal(Float::MAX, r.to_f)
110
+ assert_equal(Float::MAX, r.to_f_orig)
111
+ r = Rational(-LongMath::MAX_FLOATABLE, 1)
112
+ assert_equal(-Float::MAX, r.to_f)
113
+ assert_equal(-Float::MAX, r.to_f_orig)
114
+ unless RUBY_PLATFORM == 'java'
115
+ # skip this test in JRuby due to bugs in JRuby's Float
116
+ r = Rational(1, LongMath::MAX_FLOATABLE)
117
+ assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
118
+ assert_equal_float(1/Float::MAX, r.to_f_orig, Float::MIN)
119
+ r = Rational(-1 , LongMath::MAX_FLOATABLE)
120
+ assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
121
+ assert_equal_float(-1/Float::MAX, r.to_f_orig, Float::MIN)
122
+ end
123
+ end
124
+
125
+ #
126
+ # test to_f of Rational with numerator.abs > Float::MAX
127
+ #
128
+ def test_r_to_f_big_numerator
129
+ print "\ntest_r_to_f_big_numerator [#{Time.now}]: "
130
+ # numerator beyond Float::MAX
131
+ r = Rational(LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE - 1)
132
+ assert_equal(1.0, r.to_f)
133
+ r = Rational(-LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE - 1)
134
+ assert_equal(-1.0, r.to_f)
135
+ r = Rational(LongMath::MAX_FLOATABLE + 1, 1)
136
+ assert_equal(Float::MAX, r.to_f)
137
+ r = Rational(-LongMath::MAX_FLOATABLE - 1 , 1)
138
+ assert_equal(-Float::MAX, r.to_f)
139
+ r = Rational(2 * LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE)
140
+ assert_equal(2.0, r.to_f)
141
+ r = Rational(-2 * LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE)
142
+ assert_equal(-2.0, r.to_f)
143
+ r = Rational(LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE)
144
+ assert_equal(Float::MAX, r.to_f)
145
+ r = Rational(-LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE)
146
+ assert_equal(-Float::MAX, r.to_f)
147
+ end
148
+
149
+ #
150
+ # test to_f of Rational with denominator.abs > Float::MAX
151
+ #
152
+ def test_r_to_f_big_numerator
153
+ print "\ntest_r_to_f_big_numerator [#{Time.now}]: "
154
+
155
+ # denominator beyond Float::MAX
156
+ r = Rational(LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE + 1)
157
+ assert_equal(1.0, r.to_f)
158
+ r = Rational(-LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE + 1)
159
+ assert_equal(-1.0, r.to_f)
160
+ r = Rational(1, LongMath::MAX_FLOATABLE + 1)
161
+ assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
162
+ r = Rational(-1, LongMath::MAX_FLOATABLE - 1)
163
+ assert_equal(-1/Float::MAX, r.to_f, Float::MIN)
164
+ r = Rational(LongMath::MAX_FLOATABLE, 2 * LongMath::MAX_FLOATABLE)
165
+ assert_equal(0.5, r.to_f)
166
+ r = Rational(-LongMath::MAX_FLOATABLE, 2 * LongMath::MAX_FLOATABLE)
167
+ assert_equal(-0.5, r.to_f)
168
+ r = Rational(LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE ** 2)
169
+ assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
170
+ r = Rational(-LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE ** 2)
171
+ assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
172
+ end
173
+
174
+ #
175
+ # test to_f of Rational with numerator.abs > Float::MAX and denominator.abs > Float::MAX
176
+ #
177
+ def test_r_to_f_big_numerator
178
+ print "\ntest_r_to_f_big_numerator [#{Time.now}]: "
179
+ # both beyond Float::MAX
180
+ delta = 1/Float::MAX
181
+ r = Rational(LongMath::MAX_FLOATABLE + 2, LongMath::MAX_FLOATABLE + 1)
182
+ assert_equal(1.0, r.to_f)
183
+ r = Rational(-LongMath::MAX_FLOATABLE - 2, LongMath::MAX_FLOATABLE + 1)
184
+ assert_equal(-1.0, r.to_f)
185
+ unless RUBY_PLATFORM == 'java'
186
+ # skip this test in JRuby due to bugs in JRuby's Float
187
+ r = Rational(LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE ** 3)
188
+ assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
189
+ r = Rational(-LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE ** 3)
190
+ assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
191
+ end
192
+ r = Rational(LongMath::MAX_FLOATABLE ** 3, LongMath::MAX_FLOATABLE ** 2)
193
+ assert_equal(Float::MAX, r.to_f)
194
+ r = Rational(-LongMath::MAX_FLOATABLE ** 3, LongMath::MAX_FLOATABLE ** 2)
195
+ assert_equal(-Float::MAX, r.to_f)
196
+ r = Rational(LongMath::MAX_FLOATABLE + 1, 2 * LongMath::MAX_FLOATABLE)
197
+ assert_equal(0.5, r.to_f)
198
+ r = Rational(-(LongMath::MAX_FLOATABLE + 1), 2 * LongMath::MAX_FLOATABLE)
199
+ assert_equal(-0.5, r.to_f)
200
+ unless RUBY_PLATFORM == 'java'
201
+ # skip this test in JRuby due to bugs in JRuby's Float
202
+ r = Rational(LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE ** 2)
203
+ assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
204
+ r = Rational(-LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE ** 2)
205
+ assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
206
+ end
207
+ end
208
+
209
+ #
210
+ # test to_f of Rational with medium sized absolute value
211
+ #
212
+ def test_r_to_f_medium
213
+ print "\ntest_r_to_f_medium [#{Time.now}]: "
214
+
215
+ # use some value < 1 "in the middle"
216
+ f = 1.34078079299426e-126
217
+ n = 134078079299426
218
+ d = 10 ** 140
219
+ u = 10 ** 300
220
+ n2 = n ** 2
221
+ d2 = d ** 2
222
+ u2 = u ** 2
223
+ delta = 10 ** 135
224
+ f2 = 1/f
225
+ delta2 = 1/delta
226
+ r = Rational(n, d)
227
+ assert_equal_float(f, r.to_f, delta)
228
+ r = Rational(d, n)
229
+ assert_equal_float(f2, r.to_f, delta2)
230
+ r = Rational(n * d, d2)
231
+ assert_equal_float(f, r.to_f, delta)
232
+ r = Rational(d2, n * d)
233
+ assert_equal_float(f2, r.to_f, delta2)
234
+ r = Rational(n2, d * n)
235
+ assert_equal_float(f, r.to_f, delta)
236
+ r = Rational(d * n, n2)
237
+ assert_equal_float(f2, r.to_f, delta2)
238
+ r = Rational(n * u, d * u)
239
+ assert_equal_float(f, r.to_f, delta)
240
+ r = Rational(d * u, n * u)
241
+ assert_equal_float(f2, r.to_f, delta2)
242
+ r = Rational(n * u2, d * u2)
243
+ assert_equal_float(f, r.to_f, delta)
244
+ r = Rational(d * u2, n * u2)
245
+ assert_equal_float(f2, r.to_f, delta2)
246
+
247
+ # use some value > 1 "in the middle"
248
+ f = 1.34078079299426e+154
249
+ n = 134078079299426 * 10**154
250
+ d = 10 ** 14
251
+ n2 = n ** 2
252
+ d2 = d ** 2
253
+ delta = 10 ** 135
254
+ f2 = 1/f
255
+ delta2 = 1/delta
256
+ r = Rational(n, d)
257
+ assert_equal_float(f, r.to_f, delta)
258
+ r = Rational(d, n)
259
+ assert_equal_float(f2, r.to_f, delta2)
260
+ r = Rational(n * d, d2)
261
+ assert_equal_float(f, r.to_f, delta)
262
+ r = Rational(d2, n * d)
263
+ assert_equal_float(f2, r.to_f, delta2)
264
+ r = Rational(n2, d * n)
265
+ assert_equal_float(f, r.to_f, delta)
266
+ r = Rational(d * n, n2)
267
+ assert_equal_float(f2, r.to_f, delta2)
268
+ r = Rational(n * u, d * u)
269
+ assert_equal_float(f, r.to_f, delta)
270
+ r = Rational(d * u, n * u)
271
+ assert_equal_float(f2, r.to_f, delta2)
272
+ r = Rational(n * u2, d * u2)
273
+ assert_equal_float(f, r.to_f, delta)
274
+ r = Rational(d * u2, n * u2)
275
+ assert_equal_float(f2, r.to_f, delta2)
276
+
277
+ end
278
+
279
+ #
280
+ # test to_f of Rational (trivial cases)
281
+ #
282
+ def test_ld_to_f_small
283
+ print "\ntest_ld_to_f_small [#{Time.now}]: "
284
+ # trivial: 0, 1, -1,...
285
+ r = LongDecimal(0, 0)
286
+ assert_equal(0.0, r.to_f) # t1
287
+ r = LongDecimal(1, 0)
288
+ assert_equal(1.0, r.to_f)
289
+ r = LongDecimal(-1, 0)
290
+ assert_equal(-1.0, r.to_f)
291
+ r = LongDecimal(15, 1)
292
+ assert_equal(1.5, r.to_f)
293
+ r = LongDecimal(-15, 1)
294
+ assert_equal(-1.5, r.to_f) # t3
295
+ end
296
+
297
+ #
298
+ # test to_f of LongDecimal
299
+ #
300
+ def test_ld_to_f_max_float
301
+ print "\ntest_ld_to_f_max_float [#{Time.now}]: "
302
+ y = 1.7976931348623158
303
+ z = 0.1 ** Float::MAX_10_EXP
304
+ # still numerator and denominator expressable as Float
305
+ r = LongDecimal(LongMath::MAX_FLOATABLE, Float::MAX_10_EXP)
306
+ assert_equal_float(y, r.to_f, 1e-13) # t4
307
+ r = LongDecimal(-LongMath::MAX_FLOATABLE, Float::MAX_10_EXP)
308
+ assert_equal_float(-y, r.to_f, 1e-13) # t3
309
+ r = LongDecimal(LongMath::MAX_FLOATABLE - 1, Float::MAX_10_EXP)
310
+ assert_equal_float(y, r.to_f, 1e-13) # t4
311
+ r = LongDecimal(-(LongMath::MAX_FLOATABLE + 1), Float::MAX_10_EXP)
312
+ assert_equal_float(-y, r.to_f, 1e-13)
313
+ r = LongDecimal(LongMath::MAX_FLOATABLE, 0)
314
+ assert_equal(Float::MAX, r.to_f)
315
+ r = LongDecimal(-LongMath::MAX_FLOATABLE, 0)
316
+ assert_equal(-Float::MAX, r.to_f)
317
+ r = LongDecimal(1, Float::MAX_10_EXP)
318
+ assert_equal_float(z, r.to_f, Float::MIN)
319
+ r = LongDecimal(-1, Float::MAX_10_EXP)
320
+ assert_equal_float(-z, r.to_f, Float::MIN)
321
+ end
322
+
323
+ #
324
+ # test to_f of LongDecimal with numerator.abs > Float::MAX
325
+ #
326
+ def test_ld_to_f_big_numerator
327
+ print "\ntest_ld_to_f_big_numerator [#{Time.now}]: "
328
+ y = 1.7976931348623158
329
+ u = 1.3407807929942596e308
330
+ # numerator beyond Float::MAX
331
+ r = LongDecimal(LongMath::MAX_FLOATABLE + 1, Float::MAX_10_EXP)
332
+ assert_equal(y, r.to_f)
333
+ r = LongDecimal(-LongMath::MAX_FLOATABLE - 1, Float::MAX_10_EXP)
334
+ assert_equal(-y, r.to_f)
335
+ r = LongDecimal(LongMath::MAX_FLOATABLE + 1, 0)
336
+ assert_equal(Float::MAX, r.to_f)
337
+ r = LongDecimal(-LongMath::MAX_FLOATABLE - 1, 0)
338
+ assert_equal(-Float::MAX, r.to_f)
339
+ r = LongDecimal(2 * LongMath::MAX_FLOATABLE, Float::MAX_10_EXP)
340
+ assert_equal(2.0 * y, r.to_f)
341
+ r = LongDecimal(-2 * LongMath::MAX_FLOATABLE, Float::MAX_10_EXP)
342
+ assert_equal(-2.0 * y, r.to_f)
343
+ r = LongDecimal(u ** 2, Float::MAX_10_EXP)
344
+ assert_equal(Float::MAX, r.to_f)
345
+ r = LongDecimal(-u ** 2, LongMath::MAX_FLOATABLE)
346
+ assert_equal(-Float::MAX, r.to_f)
347
+ end
348
+
349
+ #
350
+ # test to_f of LongDecimal with denominator.abs > Float::MAX
351
+ #
352
+ def test_ld_to_f_big_numerator
353
+ print "\ntest_ld_to_f_big_numerator [#{Time.now}]: "
354
+ y = 1.7976931348623158
355
+ z = 0.1 ** Float::MAX_10_EXP + 1
356
+
357
+ # denominator beyond Float::MAX
358
+ r = LongDecimal(LongMath::MAX_FLOATABLE - 1, Float::MAX_10_EXP + 1)
359
+ assert_equal(y * 0.1, r.to_f)
360
+ r = LongDecimal(-LongMath::MAX_FLOATABLE + 1, Float::MAX_10_EXP + 1)
361
+ assert_equal(-y * 0.1, r.to_f)
362
+ r = LongDecimal(1, Float::MAX_10_EXP + 1)
363
+ assert_equal_float(z, r.to_f, Float::MIN)
364
+ r = LongDecimal(-1, Float::MAX_10_EXP + 1)
365
+ assert_equal(-z, r.to_f, Float::MIN)
366
+ r = LongDecimal(LongMath::MAX_FLOATABLE, 2 * Float::MAX_10_EXP)
367
+ assert_equal(0.0, r.to_f)
368
+ r = LongDecimal(-LongMath::MAX_FLOATABLE, 2 * Float::MAX_10_EXP)
369
+ assert_equal(-0.0, r.to_f)
370
+ end
371
+
372
+ #
373
+ # test to_f of LongDecimal with numerator.abs > Float::MAX and denominator.abs > Float::MAX
374
+ #
375
+ def test_ld_to_f_big_numerator
376
+ print "\ntest_ld_to_f_big_numerator [#{Time.now}]: "
377
+ y = 1.7976931348623158
378
+ z = 0.1 ** Float::MAX_10_EXP + 1
379
+ u = 1.3407807929942596e308
380
+ v = y**2 * 0.1 ** Float::MAX_10_EXP
381
+ w = 10 ** Float::MAX_10_EXP
382
+ x = 0.1 ** Float::MAX_10_EXP
383
+
384
+ # both beyond Float::MAX
385
+ delta = 1/Float::MAX
386
+ r = LongDecimal(LongMath::MAX_FLOATABLE + 2, Float::MAX_10_EXP + 1)
387
+ assert_equal_float(y * 0.1, r.to_f, 1e-15) # t12
388
+ r = LongDecimal(-LongMath::MAX_FLOATABLE - 2, Float::MAX_10_EXP + 1)
389
+ assert_equal_float(-y * 0.1, r.to_f, 1e-15) # t3
390
+ r = LongDecimal(LongMath::MAX_FLOATABLE ** 2, 3 * Float::MAX_10_EXP)
391
+ assert_equal_float(v, r.to_f, Float::MIN) # t6
392
+ r = LongDecimal(-LongMath::MAX_FLOATABLE ** 2, 3 * Float::MAX_10_EXP)
393
+ assert_equal_float(-v, r.to_f, Float::MIN)
394
+ r = LongDecimal(10 * w + 2, Float::MAX_10_EXP + 1)
395
+ assert_equal_float(1.0, r.to_f, 1e-15)
396
+ r = LongDecimal(-10 * w - 2, Float::MAX_10_EXP + 1)
397
+ assert_equal_float(-1.0, r.to_f, 1e-15)
398
+ r = LongDecimal(w ** 2 - 1, 3 * Float::MAX_10_EXP)
399
+ assert_equal_float(x, r.to_f, Float::MIN)
400
+ r = LongDecimal(-w ** 2 - 1, 3 * Float::MAX_10_EXP)
401
+ assert_equal_float(-x, r.to_f, Float::MIN)
402
+ r = LongDecimal(w ** 2, 3 * Float::MAX_10_EXP)
403
+ assert_equal_float(x, r.to_f, Float::MIN)
404
+ r = LongDecimal(-w ** 2, 3 * Float::MAX_10_EXP)
405
+ assert_equal_float(-x, r.to_f, Float::MIN)
406
+ r = LongDecimal(w ** 2 + 1, 3 * Float::MAX_10_EXP)
407
+ assert_equal_float(x, r.to_f, Float::MIN)
408
+ r = LongDecimal(-w ** 2 + 1, 3 * Float::MAX_10_EXP)
409
+ assert_equal_float(-x, r.to_f, Float::MIN)
410
+ r = LongDecimal(w ** 2 - 1, 3 * Float::MAX_10_EXP + 1)
411
+ assert_equal(0.0, r.to_f)
412
+ r = LongDecimal(-w ** 2 - 1, 3 * Float::MAX_10_EXP + 1)
413
+ assert_equal(-0.0, r.to_f)
414
+ r = LongDecimal(w ** 2, 3 * Float::MAX_10_EXP + 1)
415
+ assert_equal(0.0, r.to_f)
416
+ r = LongDecimal(-w ** 2, 3 * Float::MAX_10_EXP + 1)
417
+ assert_equal(-0.0, r.to_f)
418
+ r = LongDecimal(w ** 2 + 1, 3 * Float::MAX_10_EXP + 1)
419
+ assert_equal(0.0, r.to_f)
420
+ r = LongDecimal(-w ** 2 + 1, 3 * Float::MAX_10_EXP + 1)
421
+ assert_equal(-0.0, r.to_f)
422
+ r = LongDecimal(w ** 3 + 1, 2 * Float::MAX_10_EXP)
423
+ assert_equal(w.to_f, r.to_f)
424
+ r = LongDecimal(-w ** 3 + 1, 2 * Float::MAX_10_EXP)
425
+ assert_equal(-w.to_f, r.to_f)
426
+ r = LongDecimal(10 * w + 1, 1 + Float::MAX_10_EXP)
427
+ assert_equal_float(1.0, r.to_f, 1e-15)
428
+ r = LongDecimal(-10 * w - 1, 1 + Float::MAX_10_EXP)
429
+ assert_equal_float(-1.0, r.to_f, 1e-15)
430
+ r = LongDecimal(10 * w + 1, 2 * Float::MAX_10_EXP)
431
+ assert_equal_float(10/Float::MAX, r.to_f, 2*Float::MIN, "d=#{r.to_f-10/Float::MAX}")
432
+ r = LongDecimal(-10 * w + 1, 2 * Float::MAX_10_EXP)
433
+ assert_equal_float(-10/Float::MAX, r.to_f, 2*Float::MIN, "d=#{r.to_f+10/Float::MAX}")
434
+ end
435
+
436
+ #
437
+ # test to_f of LongDecimal with medium sized absolute value
438
+ #
439
+ def test_ld_to_f_medium
440
+ print "\ntest_ld_to_f_medium [#{Time.now}]: "
441
+
442
+ # use some value < 1 "in the middle"
443
+ f = 1.34078079299426e-126
444
+ n = 134078079299426
445
+ ds = 140
446
+ d = 10 ** ds
447
+ us = 300
448
+ u = 10 ** us
449
+ n2 = n ** 2
450
+ d2 = d ** 2
451
+ u2 = u ** 2
452
+ delta = 10 ** 135
453
+ fi = 1/f
454
+ ni = 74583407312002050942828544 * 10 ** 100
455
+ deltai = 1/delta
456
+
457
+ r = LongDecimal(n, ds)
458
+ assert_equal_float(f, r.to_f, delta) # t4
459
+ r = LongDecimal(ni, 0)
460
+ assert_equal_float(fi, r.to_f, deltai)
461
+ r = LongDecimal(n * d, 2 * ds)
462
+ assert_equal_float(f, r.to_f, delta)
463
+ r = LongDecimal(n * u, ds + us)
464
+ assert_equal_float(f, r.to_f, delta)
465
+ r = LongDecimal(ni * u, us)
466
+ assert_equal_float(fi, r.to_f, deltai) # t9
467
+ r = LongDecimal(n * u2, ds + 2*us)
468
+ assert_equal_float(f, r.to_f, delta)
469
+
470
+ # use some value > 1 "in the middle"
471
+ f = 1.34078079299426e+154
472
+ n = 134078079299426 * 10**154
473
+ ds = 14
474
+ d = 10 ** ds
475
+ n2 = n ** 2
476
+ d2 = d ** 2
477
+ delta = 1e139
478
+ fi = 1/f
479
+ deltai = 1/delta
480
+ ni = 745834073120020496384
481
+ dis = 175
482
+ di = 10 ** dis
483
+
484
+ r = LongDecimal(n, ds)
485
+ assert_equal_float(f, r.to_f, delta, "d=#{f-r.to_f}")
486
+ r = LongDecimal(ni, dis)
487
+ assert_equal_float(fi, r.to_f, deltai)
488
+ r = LongDecimal(n * d, 2 * ds)
489
+ assert_equal_float(f, r.to_f, 3 * delta, "d=#{f - r.to_f}") # t4
490
+ r = LongDecimal(d * ni, ds + dis)
491
+ assert_equal_float(fi, r.to_f, deltai)
492
+ r = LongDecimal(n * u, ds + us)
493
+ assert_equal_float(f, r.to_f, delta)
494
+ r = LongDecimal(ni * u, dis + us)
495
+ assert_equal_float(fi, r.to_f, deltai)
496
+ r = LongDecimal(n * u2, ds + 2 * us)
497
+ assert_equal_float(f, r.to_f, delta)
498
+ r = LongDecimal(ni * u2, dis + 2*us)
499
+ assert_equal_float(fi, r.to_f, deltai)
500
+
501
+ end
502
+
503
+ # do some conversions that lead to infinity
504
+ def test_ld_to_f_infinity
505
+ print "\ntest_ld_to_f_infinity [#{Time.now}]: "
506
+ f1 = LongDecimal(1000000000000001, 15)
507
+ r = LongDecimal(LongMath::MAX_FLOATABLE + 1, 0)
508
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}") # t13
509
+ # assert_equal(Float::MAX, r.to_f, "r=#{r}=#{r.to_f}")
510
+ r = LongDecimal(-(LongMath::MAX_FLOATABLE + 1), 0)
511
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
512
+ # assert_equal(-Float::MAX, r.to_f, "r=#{r}=#{r.to_f}")
513
+ r = LongDecimal(LongMath::MAX_FLOATABLE * f1, 0)
514
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
515
+ r = LongDecimal(-LongMath::MAX_FLOATABLE * f1, 0)
516
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
517
+ r = LongDecimal(LongMath::MAX_FLOATABLE * 2, 0)
518
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
519
+ r = LongDecimal(-LongMath::MAX_FLOATABLE * 2, 0)
520
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
521
+ r = LongDecimal(LongMath::MAX_FLOATABLE ** 2, 0)
522
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
523
+ r = LongDecimal(-LongMath::MAX_FLOATABLE ** 2, 0)
524
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
525
+ r = LongDecimal(LongMath::MAX_FLOATABLE * 10 + 1, 1)
526
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
527
+ r = LongDecimal(-LongMath::MAX_FLOATABLE * 10 - 1, 1)
528
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
529
+ r = LongDecimal(LongMath::MAX_FLOATABLE ** 2, Float::MAX_10_EXP)
530
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
531
+ r = LongDecimal(-LongMath::MAX_FLOATABLE ** 2, Float::MAX_10_EXP)
532
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
533
+ r = LongDecimal(LongMath::MAX_FLOATABLE ** 3, 2 * Float::MAX_10_EXP)
534
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
535
+ r = LongDecimal(-LongMath::MAX_FLOATABLE ** 3, 2 * Float::MAX_10_EXP)
536
+ assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
537
+ end
538
+
539
+ # test t7
540
+ def test_ld_to_f_zero_t7
541
+ print "\ntest_ld_to_f_zero_t7 [#{Time.now}]: "
542
+ scale = 600
543
+ divisor = 10 ** scale
544
+ val = divisor / (LongMath::INV_MIN_FLOATABLE * 20)
545
+ r = LongDecimal(val - 1, scale)
546
+ assert_equal(0.0, r.to_f)
547
+ r = LongDecimal(-val + 1, scale)
548
+ assert_equal(0.0, r.to_f)
549
+ r = LongDecimal(val, scale)
550
+ assert_equal(0.0, r.to_f)
551
+ r = LongDecimal(-val, scale)
552
+ assert_equal(0.0, r.to_f)
553
+ r = LongDecimal(val + 1, scale)
554
+ assert_equal_float(0.0, r.to_f, Float::MIN) # t7 (JRuby-only)
555
+ r = LongDecimal(-val - 1, scale)
556
+ assert_equal_float(0.0, r.to_f, Float::MIN) # t7 (JRuby-only)
557
+ r = LongDecimal(val + 2, scale)
558
+ assert_equal_float(0.0, r.to_f, Float::MIN) # t7 (JRuby-only)
559
+ r = LongDecimal(-val - 2, scale)
560
+ assert_equal_float(0.0, r.to_f, Float::MIN) # t7 (JRuby-only)
561
+ end
562
+
563
+ #
564
+ # test to_f of LongDecimalQuot (trivial cases)
565
+ #
566
+ def test_ldq_to_f_small
567
+ print "\ntest_ldq_to_f_small [#{Time.now}]: "
568
+ # trivial: 0, 1, -1,...
569
+ r = LongDecimalQuot(Rational(0, 1), 7)
570
+ assert_equal(0.0, r.to_f)
571
+ r = LongDecimalQuot(Rational(1, 1), 7)
572
+ assert_equal(1.0, r.to_f)
573
+ r = LongDecimalQuot(Rational(-1, 1), 7)
574
+ assert_equal(-1.0, r.to_f)
575
+ r = LongDecimalQuot(Rational(3, 2), 7)
576
+ assert_equal(1.5, r.to_f)
577
+ r = LongDecimalQuot(Rational(-3, 2), 7)
578
+ assert_equal(-1.5, r.to_f)
579
+ end
580
+
581
+ #
582
+ # test to_f of LongDecimalQuot
583
+ #
584
+ def test_ldq_to_f_max_float
585
+ print "\ntest_ldq_to_f_max_float [#{Time.now}]: "
586
+ # still numerator and denominator expressable as Float
587
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE - 1), 7)
588
+ assert_equal(1.0, r.to_f)
589
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE - 1), 7)
590
+ assert_equal(-1.0, r.to_f)
591
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE), 7)
592
+ assert_equal(1.0, r.to_f)
593
+ r = LongDecimalQuot(Rational(-(LongMath::MAX_FLOATABLE + 1), LongMath::MAX_FLOATABLE), 7)
594
+ assert_equal(-1.0, r.to_f)
595
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE, 1), 7)
596
+ assert_equal(Float::MAX, r.to_f)
597
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE, 1), 7)
598
+ assert_equal(-Float::MAX, r.to_f)
599
+ unless RUBY_PLATFORM == 'java'
600
+ # skip this test in JRuby due to bugs in JRuby's Float
601
+ r = LongDecimalQuot(Rational(1, LongMath::MAX_FLOATABLE), 7)
602
+ assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
603
+ r = LongDecimalQuot(Rational(-1 , LongMath::MAX_FLOATABLE), 7)
604
+ assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
605
+ end
606
+ end
607
+
608
+ #
609
+ # test to_f of LongDecimalQuot with numerator.abs > Float::MAX
610
+ #
611
+ def test_ldq_to_f_big_numerator
612
+ print "\ntest_ldq_to_f_big_numerator [#{Time.now}]: "
613
+ # numerator beyond Float::MAX
614
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE - 1), 7)
615
+ assert_equal(1.0, r.to_f)
616
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE - 1), 7)
617
+ assert_equal(-1.0, r.to_f)
618
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE + 1, 1), 7)
619
+ assert_equal(Float::MAX, r.to_f)
620
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE - 1 , 1), 7)
621
+ assert_equal(-Float::MAX, r.to_f)
622
+ r = LongDecimalQuot(Rational(2 * LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE), 7)
623
+ assert_equal(2.0, r.to_f)
624
+ r = LongDecimalQuot(Rational(-2 * LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE), 7)
625
+ assert_equal(-2.0, r.to_f)
626
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE), 7)
627
+ assert_equal(Float::MAX, r.to_f)
628
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE), 7)
629
+ assert_equal(-Float::MAX, r.to_f)
630
+ end
631
+
632
+ #
633
+ # test to_f of LongDecimalQuot with denominator.abs > Float::MAX
634
+ #
635
+ def test_ldq_to_f_big_numerator
636
+ print "\ntest_ldq_to_f_big_numerator [#{Time.now}]: "
637
+
638
+ # denominator beyond Float::MAX
639
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE + 1), 7)
640
+ assert_equal(1.0, r.to_f)
641
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE + 1), 7)
642
+ assert_equal(-1.0, r.to_f)
643
+ r = LongDecimalQuot(Rational(1, LongMath::MAX_FLOATABLE + 1), 7)
644
+ assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
645
+ r = LongDecimalQuot(Rational(-1, LongMath::MAX_FLOATABLE - 1), 7)
646
+ assert_equal(-1/Float::MAX, r.to_f, Float::MIN)
647
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE, 2 * LongMath::MAX_FLOATABLE), 7)
648
+ assert_equal(0.5, r.to_f)
649
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE, 2 * LongMath::MAX_FLOATABLE), 7)
650
+ assert_equal(-0.5, r.to_f)
651
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE ** 2), 7)
652
+ assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
653
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE ** 2), 7)
654
+ assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
655
+ end
656
+
657
+ #
658
+ # test to_f of LongDecimalQuot with numerator.abs > Float::MAX and denominator.abs > Float::MAX
659
+ #
660
+ def test_ldq_to_f_big_numerator
661
+ print "\ntest_ldq_to_f_big_numerator [#{Time.now}]: "
662
+ # both beyond Float::MAX
663
+ delta = 1/Float::MAX
664
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE + 2, LongMath::MAX_FLOATABLE + 1), 7)
665
+ assert_equal(1.0, r.to_f)
666
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE - 2, LongMath::MAX_FLOATABLE + 1), 7)
667
+ assert_equal(-1.0, r.to_f)
668
+ unless RUBY_PLATFORM == 'java'
669
+ # skip this test in JRuby due to bugs in JRuby's Float
670
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE ** 3), 7)
671
+ assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
672
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE ** 3), 7)
673
+ assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
674
+ end
675
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE ** 3, LongMath::MAX_FLOATABLE ** 2), 7)
676
+ assert_equal(Float::MAX, r.to_f)
677
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE ** 3, LongMath::MAX_FLOATABLE ** 2), 7)
678
+ assert_equal(-Float::MAX, r.to_f)
679
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE + 1, 2 * LongMath::MAX_FLOATABLE), 7)
680
+ assert_equal(0.5, r.to_f)
681
+ r = LongDecimalQuot(Rational(-(LongMath::MAX_FLOATABLE + 1), 2 * LongMath::MAX_FLOATABLE), 7)
682
+ assert_equal(-0.5, r.to_f)
683
+ unless RUBY_PLATFORM == 'java'
684
+ # skip this test in JRuby due to bugs in JRuby's Float
685
+ r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE ** 2), 7)
686
+ assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
687
+ r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE ** 2), 7)
688
+ assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
689
+ end
690
+ end
691
+
692
+ #
693
+ # test to_f of LongDecimalQuot with medium sized absolute value
694
+ #
695
+ def test_ldq_to_f_medium
696
+ print "\ntest_ldq_to_f_medium [#{Time.now}]: "
697
+
698
+ # use some value < 1 "in the middle"
699
+ f = 1.34078079299426e-126
700
+ n = 134078079299426
701
+ d = 10 ** 140
702
+ u = 10 ** 300
703
+ n2 = n ** 2
704
+ d2 = d ** 2
705
+ u2 = u ** 2
706
+ delta = 10 ** 135
707
+ f2 = 1/f
708
+ delta2 = 1/delta
709
+ r = LongDecimalQuot(Rational(n, d), 7)
710
+ assert_equal_float(f, r.to_f, delta)
711
+ r = LongDecimalQuot(Rational(d, n), 7)
712
+ assert_equal_float(f2, r.to_f, delta2)
713
+ r = LongDecimalQuot(Rational(n * d, d2), 7)
714
+ assert_equal_float(f, r.to_f, delta)
715
+ r = LongDecimalQuot(Rational(d2, n * d), 7)
716
+ assert_equal_float(f2, r.to_f, delta2)
717
+ r = LongDecimalQuot(Rational(n2, d * n), 7)
718
+ assert_equal_float(f, r.to_f, delta)
719
+ r = LongDecimalQuot(Rational(d * n, n2), 7)
720
+ assert_equal_float(f2, r.to_f, delta2)
721
+ r = LongDecimalQuot(Rational(n * u, d * u), 7)
722
+ assert_equal_float(f, r.to_f, delta)
723
+ r = LongDecimalQuot(Rational(d * u, n * u), 7)
724
+ assert_equal_float(f2, r.to_f, delta2)
725
+ r = LongDecimalQuot(Rational(n * u2, d * u2), 7)
726
+ assert_equal_float(f, r.to_f, delta)
727
+ r = LongDecimalQuot(Rational(d * u2, n * u2), 7)
728
+ assert_equal_float(f2, r.to_f, delta2)
729
+
730
+ # use some value > 1 "in the middle"
731
+ f = 1.34078079299426e+154
732
+ n = 134078079299426 * 10**154
733
+ d = 10 ** 14
734
+ n2 = n ** 2
735
+ d2 = d ** 2
736
+ delta = 10 ** 135
737
+ f2 = 1/f
738
+ delta2 = 1/delta
739
+ r = LongDecimalQuot(Rational(n, d), 7)
740
+ assert_equal_float(f, r.to_f, delta)
741
+ r = LongDecimalQuot(Rational(d, n), 7)
742
+ assert_equal_float(f2, r.to_f, delta2)
743
+ r = LongDecimalQuot(Rational(n * d, d2), 7)
744
+ assert_equal_float(f, r.to_f, delta)
745
+ r = LongDecimalQuot(Rational(d2, n * d), 7)
746
+ assert_equal_float(f2, r.to_f, delta2)
747
+ r = LongDecimalQuot(Rational(n2, d * n), 7)
748
+ assert_equal_float(f, r.to_f, delta)
749
+ r = LongDecimalQuot(Rational(d * n, n2), 7)
750
+ assert_equal_float(f2, r.to_f, delta2)
751
+ r = LongDecimalQuot(Rational(n * u, d * u), 7)
752
+ assert_equal_float(f, r.to_f, delta)
753
+ r = LongDecimalQuot(Rational(d * u, n * u), 7)
754
+ assert_equal_float(f2, r.to_f, delta2)
755
+ r = LongDecimalQuot(Rational(n * u2, d * u2), 7)
756
+ assert_equal_float(f, r.to_f, delta)
757
+ r = LongDecimalQuot(Rational(d * u2, n * u2), 7)
758
+ assert_equal_float(f2, r.to_f, delta2)
759
+
760
+ end
27
761
 
28
762
  #
29
763
  # test exp2 of LongMath
30
764
  #
31
765
  def test_exp2
766
+ print "\ntest_exp2 [#{Time.now}]: "
32
767
  10.times do |i|
33
768
  n = (i*i+i)/2
34
769
  x = LongDecimal(n, 3*i)+LongMath.pi(20)
@@ -51,6 +786,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
51
786
  # near zero
52
787
  #
53
788
  def test_exp2_near_zero
789
+ print "\ntest_exp2_near_zero [#{Time.now}]: "
54
790
 
55
791
  x = LongDecimal(1, 100)
56
792
  y = LongMath.log2(x, 100)
@@ -67,6 +803,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
67
803
  # test exp10 of LongMath
68
804
  #
69
805
  def test_exp10
806
+ print "\ntest_exp10 [#{Time.now}]: "
70
807
  10.times do |i|
71
808
  n = (i*i+i)/2
72
809
  x = LongDecimal(n, 3*i)+LongMath.pi(20)
@@ -85,6 +822,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
85
822
  # near zero
86
823
  #
87
824
  def test_exp10_near_zero
825
+ print "\ntest_exp10_near_zero [#{Time.now}]: "
88
826
 
89
827
  x = LongDecimal(1, 100)
90
828
  y = LongMath.log10(x, 100)
@@ -101,6 +839,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
101
839
  # test LongMath.power for bases that can be expressed as integer
102
840
  #
103
841
  def test_lm_power_xint
842
+ print "\ntest_lm_power_xint [#{Time.now}]: "
104
843
 
105
844
  xx = LongMath.log(3, 40)
106
845
  pi = LongMath.pi(40)
@@ -196,6 +935,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
196
935
  # test LongMath.power for bases that can be expressed as integer
197
936
  #
198
937
  def test_lm_power_yint
938
+ print "\ntest_lm_power_yint [#{Time.now}] (2 min): "
199
939
 
200
940
  xx = LongMath.log(3, 40)
201
941
  pi = LongMath.pi(40)
@@ -279,6 +1019,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
279
1019
  # test LongMath.power for bases that can be expressed as integer
280
1020
  #
281
1021
  def test_lm_power_yhalfint
1022
+ print "\ntest_lm_power_yhalfint [#{Time.now}] (10 min): "
282
1023
 
283
1024
  xx = LongMath.log(3, 40)
284
1025
  pi = LongMath.pi(40)
@@ -350,6 +1091,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
350
1091
  # test LongMath.power with non-LongDecimal arguments
351
1092
  #
352
1093
  def test_non_ld_power
1094
+ print "\ntest_non_ld_power [#{Time.now}]: "
353
1095
  xi = 77
354
1096
  yi = 88
355
1097
  zi = LongMath.power(xi, yi, 35)
@@ -377,6 +1119,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
377
1119
  # test the calculation of the power-function of LongMath
378
1120
  #
379
1121
  def test_lm_power
1122
+ print "\ntest_lm_power [#{Time.now}]: "
380
1123
  check_power_floated(1.001, 1.001, 10)
381
1124
  check_power_floated(1.001, 2.001, 10)
382
1125
  check_power_floated(2.001, 1.001, 10)
@@ -405,169 +1148,516 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
405
1148
  check_power_floated(1.01, -1e-20, 21)
406
1149
 
407
1150
  # random tests that have failed
1151
+ end
408
1152
 
1153
+ def test_lm_power0a
1154
+ print "\ntest_lm_power0a [#{Time.now}]: "
409
1155
  check_power_floated(LongDecimal("0.000000000077517987624900000000000000000000000000000000000000000000000000000000000000000000000000000014809051260000000000000000000000000000000000000000000000000000000000000000000000000000000000707281"),
410
1156
  LongDecimal("26.627053911388694974442854299008649887946027550330988420533923061901183724914978160564862753777080769340"),
411
1157
  29)
412
1158
  puts "a"
1159
+ end
1160
+
1161
+ def test_lm_power0b
1162
+ print "\ntest_lm_power0b [#{Time.now}]: "
413
1163
  check_power_floated(LongDecimal("1.000000000000000151000000000000000000000000000000000000000000000000000000000000057800000000205"),
414
1164
  LongDecimal("-680.0000000000000000000013100000000000000000000000000000000000000165000000000000000000234"),
415
1165
  26)
416
1166
  puts "b"
1167
+ end
1168
+
1169
+ def test_lm_power0c
1170
+ print "\ntest_lm_power0c [#{Time.now}]: "
417
1171
  check_power_floated(LongDecimal("1.0000000000000000000000000000000000000000000068000000000853000000000926"),
418
1172
  LongDecimal("-536.000000000086100000000000000000000000000019200000000000000000000000000000000000000000000000166"),
419
1173
  49)
420
1174
  puts "c"
1175
+ end
1176
+
1177
+ def test_lm_power0d
1178
+ print "\ntest_lm_power0d [#{Time.now}]: "
421
1179
  check_power_floated(LongDecimal("1.0000000000000000049000000000002090000000000447"),
422
1180
  LongDecimal("-328.00000000000000000000000000000000567000000000000000026600000000000000000000000679"),
423
1181
  24)
424
1182
  puts "d"
1183
+ end
1184
+
1185
+ def test_lm_power0e
1186
+ print "\ntest_lm_power0e [#{Time.now}]: "
425
1187
  check_power_floated(LongDecimal("1.0000000000000000000003580000000000000000000000376238"),
426
1188
  LongDecimal("-359.0000000003910721000000000000000000000000000000000000000000000000000000000000000000000000479"),
427
1189
  39)
428
1190
  puts "e"
1191
+ end
1192
+
1193
+ def test_lm_power0f
1194
+ print "\ntest_lm_power0f [#{Time.now}]: "
429
1195
  check_power_floated(LongDecimal("1.000000000000000000000032000000001500000000000000000000439"),
430
1196
  LongDecimal("-252.00000000000000025500000000000176907"),
431
1197
  39)
432
1198
  puts "f"
1199
+ end
1200
+
1201
+ def test_lm_power0g
1202
+ print "\ntest_lm_power0g [#{Time.now}]: "
433
1203
  check_power_floated(LongDecimal("1.0000000000000008590000521000000000000621"),
434
1204
  LongDecimal("-135.0000000000000000000000000000000000000000000000000000000074400000000000000000000000000321"),
435
1205
  50)
436
1206
  puts "g"
1207
+ end
1208
+
1209
+ def test_lm_power0h
1210
+ print "\ntest_lm_power0h [#{Time.now}]: "
437
1211
  check_power_floated(LongDecimal("1.000000000000000151000000000000000000000000000000000000000000000000000000000000057800000000205"),
438
1212
  LongDecimal("-680.0000000000000000000013100000000000000000000000000000000000000165000000000000000000234"),
439
1213
  26)
440
1214
  puts "h"
1215
+ end
1216
+
1217
+ def test_lm_power0i
1218
+ print "\ntest_lm_power0i [#{Time.now}]: "
441
1219
  check_power_floated(LongDecimal("1.02350000000000000000000356000000000000000000000000000000000000000000000000000000000104"),
442
1220
  LongDecimal("-971.0000000000000000055400000000000000000000000000000000000000000000000000040900000000000000000000000603"),
443
1221
  45)
444
1222
  puts "i"
1223
+ end
1224
+
1225
+ def test_lm_power0j
1226
+ print "\ntest_lm_power0j [#{Time.now}]: "
445
1227
  check_power_floated(LongDecimal("1.0023800000000000000000000000000000000000000000000000000000000000265000000000000000000000000000000453"),
446
1228
  LongDecimal("-277.000000000000000000000000000000000000000000000000000000000000113000000000000000000041400000294"),
447
1229
  22)
448
1230
  puts "j"
1231
+ end
1232
+
1233
+ def test_lm_power0k
1234
+ print "\ntest_lm_power0k [#{Time.now}]: "
449
1235
  check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003422250001093950095910422515315300670761"),
450
1236
  LongDecimal("-0.99999999999999999999999999999999999999999999999999997909999999999999999999999999667999957000000000000000065521500000000000000000000020816402696099999999999997719321110428280027729999999129874367303020000000000071412895105695789681563000036363932570289984431712381817869482773696988055442648559706239710901091550702341077381290973316336980640165855210736680"),
451
1237
  46)
452
1238
  puts "k"
1239
+ end
1240
+
1241
+ def test_lm_power0l
1242
+ print "\ntest_lm_power0l [#{Time.now}]: "
453
1243
  check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000049273899694369"),
454
1244
  LongDecimal("-0.99999999999999999999999999999999999999988899963450000000000000000000000000000001847988671170038537499999999999999999999658146648184996349480690906250000000000066400422857493760370353798820585648437488207957808220483456569835670219978619056054192244103752969215743872596800486621906638928959243058783356441503226136251748249991020724187893339868"),
455
1245
  40)
456
1246
  puts "l"
1247
+ end
1248
+
1249
+ def test_lm_power0m
1250
+ print "\ntest_lm_power0m [#{Time.now}]: "
457
1251
  check_power_floated(LongDecimal("0.0000000000000000000000000000003868840000000000000000000328416000000000000000000006969600000000000000000000000000000059338800000000000000000002518560000000000000000000000000000000000000000000000000000000227529"),
458
1252
  LongDecimal("-0.999999999999999999999999999999999999999999999999999998264999999999999999999999999999616741000000000000000004515337500000000000000000000001994863094999999999999986943149282831191620999999999993077825060350000000000033980453035745280148525000000024019946927993617107497210600671335038418031107762499920991889855598841096454678838495791189026426859181655270271342"),
459
1253
  31)
460
1254
  puts "m"
1255
+ end
1256
+
1257
+ def test_lm_power0n
1258
+ print "\ntest_lm_power0n [#{Time.now}]: "
461
1259
  check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000435600000000000000000000000000000000000000000000000006204000000075240000000000000000000000000000000000000022090000000535800000003249"),
462
1260
  LongDecimal("-4.50377349099168904759987513420506734335755704389619751192197520413005925604849718759451665302464588879636922713303481423460050066204079523260315868192642742903330525895063299416"),
463
1261
  20)
464
1262
  puts "n"
1263
+ end
1264
+
1265
+ def test_lm_power0o
1266
+ print "\ntest_lm_power0o [#{Time.now}]: "
465
1267
  check_power_floated(LongDecimal("0.0000000000000000000000000000700720943029391693947940220429504569709269190190365416713568"),
466
1268
  LongDecimal("-6.633249580710799698229865473341373367854177091179010213018664944871230"),
467
1269
  7)
468
1270
  puts "o"
1271
+ end
1272
+
1273
+ def test_lm_power0p
1274
+ print "\ntest_lm_power0p [#{Time.now}]: "
469
1275
  check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000816700000697"),
470
1276
  LongDecimal("-0.58685446009389671361502347417840375586854460093896713614906034406753510106019528753113359342280707917300359276157963863070992095386428055722936293804476401957909668625460628698383384886591034139"),
471
1277
  36)
472
1278
  puts "p"
1279
+ end
1280
+
1281
+ def test_lm_power0q
1282
+ print "\ntest_lm_power0q [#{Time.now}]: "
473
1283
  check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
474
1284
  LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
475
1285
  3)
476
1286
  puts "q"
1287
+ end
1288
+
1289
+ def test_lm_power0r
1290
+ print "\ntest_lm_power0r [#{Time.now}]: "
477
1291
  check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000002450257484405715360000000000000000097614149083200000000000000000000000972196"),
478
1292
  LongDecimal("-1.00000008600000184900000000000000000000000000000000000000012640000543520000000000000000000013300000571900000000000000399424000000000000000000000000000840560000000000000000000000000000442225"),
479
1293
  3)
480
1294
  puts "r"
1295
+ end
1296
+
1297
+ def test_lm_power0s
1298
+ print "\ntest_lm_power0s [#{Time.now}]: "
481
1299
  check_power_floated(LongDecimal("0.00000000000000000000000000000000000000000000000000000000000000000000367236000000000000000093202800000000000000005914074196000000000000000058905400000000000000000000146689"),
482
1300
  LongDecimal("-1.000000000008800000000019360000000062800000000276320250000000001100000985960000000000007850000000000000015625"),
483
1301
  4)
484
1302
  puts "s"
1303
+ end
1304
+
1305
+ def test_lm_power0t
1306
+ print "\ntest_lm_power0t [#{Time.now}]: "
485
1307
  check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000000000000000000000000000002777290000000006513720000000003819240000000000000000000000000000100340800000000117667200000000000000000000000000000000000000000000906304"),
486
1308
  LongDecimal("-0.5773502691896257645091447198050641552797247036332110311421498194545129249630222981047763195372146430879281215100223411775138874331819083544781222838698051829302865547075365868655847179043571799566074987574406310154782766513220296853158689786573196010629608653145605201822170964422894732870490642190250948498852022304300879727510280657218553"),
487
1309
  23)
488
1310
  puts "t"
1311
+ end
1312
+
1313
+ def test_lm_power0u
1314
+ print "\ntest_lm_power0u [#{Time.now}]: "
489
1315
  check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000007350000295000915"),
490
1316
  LongDecimal("-1.000002193000861"),
491
1317
  2)
492
1318
  puts "u"
1319
+ end
1320
+
1321
+ def test_lm_power0v
1322
+ print "\ntest_lm_power0v [#{Time.now}]: "
493
1323
  check_power_floated(LongDecimal("0.0000000086862400000000000000015172960006039360000000662596000527472000104976"),
494
1324
  LongDecimal("-0.999999999999999999999999999999999999999999999999999999999997169999999999996784999999999687000000000000000000000000000012013350000000027295350000002672874337500003018885000000146896669625999999845508318999984783776699499965759759873248317316431267825611053489338193758007138415641516991908731376997678345955102618540146326218008264916981179817214058767402196571"),
495
1325
  11)
496
1326
  puts "v"
1327
+ end
1328
+
1329
+ def test_lm_power0w
1330
+ print "\ntest_lm_power0w [#{Time.now}]: "
497
1331
  check_power_floated(LongDecimal("0.00000000000000000000000000624000383000000000000000000000000000000000000000000000358"),
498
1332
  LongDecimal("-1.0000004600000000000000000000000000000004210"),
499
1333
  3)
500
1334
  puts "w"
1335
+ end
1336
+
1337
+ def test_lm_power0x
1338
+ print "\ntest_lm_power0x [#{Time.now}]: "
501
1339
  check_power_floated(LongDecimal("0.00000000006236994468492015585972291475115698519825552824875948893004062366348813472156776148562881057978611940708477498267201430163921921918813918304834563518614088250202460271818014152969"),
502
1340
  LongDecimal("-21.81742422927144044215775880732087497227530694228658299334049542576403906256739064739549866577137008231569804502022381108724983114382624747999460445291671084230968250529511708947428208082234"),
503
1341
  6)
504
1342
  puts "x"
1343
+ end
1344
+
1345
+ def test_lm_power0y
1346
+ print "\ntest_lm_power0y [#{Time.now}]: "
505
1347
  check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000035600000000928000000000000000450"),
506
1348
  LongDecimal("-0.70821529745042492917661444999959874487397062785764977666003279651340417551441776107007487983685090756343178115766012078677210548592741818458068450268168492334992979756923"),
507
1349
  13)
508
1350
  puts "y"
1351
+ end
1352
+
1353
+ def test_lm_power0z
1354
+ print "\ntest_lm_power0z [#{Time.now}]: "
509
1355
  check_power_floated(LongDecimal("0.0000000000000000000000000000025900000000000000000000000000000000000000000022100000000000000000032"),
510
1356
  LongDecimal("-0.999943403203378688766215832183174473300891276419706031790088430934495839737458766990116492"),
511
1357
  4)
512
1358
  puts "z"
1359
+ end
1360
+
1361
+ def test_lm_power1a
1362
+ print "\ntest_lm_power1a [#{Time.now}]: "
513
1363
  check_power_floated(LongDecimal("0.002658925294303146195800785280451092866235470739838791730450519159432915"),
514
1364
  LongDecimal("-87.0000000000000008330000000000000000000000000000000000000000000000000000000000000000000000000092046"),
515
1365
  90)
516
1366
  puts "a"
1367
+ end
1368
+
1369
+ def test_lm_power1b
1370
+ print "\ntest_lm_power1b [#{Time.now}]: "
517
1371
  check_power_floated(LongDecimal("0.0014814814814814814812905349794238683127818125285779606767229367555739725854802645575188374989810195213530274617178142875856830586369415448003164084698537116523550097"),
518
1372
  LongDecimal("-52.0000000000000000000000000000000000000000683000000000000000000238000000000228"),
519
1373
  25)
520
1374
  puts "b"
1375
+ end
1376
+
1377
+ def test_lm_power1c
1378
+ print "\ntest_lm_power1c [#{Time.now}]: "
521
1379
  check_power_floated(LongDecimal("0.00000000000000000000047400000000000000000084700000892"),
522
1380
  LongDecimal("-17.000000001310000000000000000000000000000000000000000000000000002800000000000000217"),
523
1381
  56)
524
1382
  puts "c"
1383
+ end
1384
+
1385
+ def test_lm_power1d
1386
+ print "\ntest_lm_power1d [#{Time.now}]: "
525
1387
  check_power_floated(LongDecimal("0.00000000000000000000005110000000000000000004800000000000000000000000000000163"),
526
1388
  LongDecimal("-37.000000009170000000000000000000000000000000000000000000000000000000000000055800048"),
527
1389
  21)
528
1390
  puts "d"
1391
+ end
1392
+
1393
+ # SLOW!!!
1394
+ def _test_lm_power1e
1395
+ print "\ntest_lm_power1e [#{Time.now}] (2 hours): "
529
1396
  check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000002450257484405715360000000000000000097614149083200000000000000000000000972196"),
530
1397
  LongDecimal("-1.00000008600000184900000000000000000000000000000000000000012640000543520000000000000000000013300000571900000000000000399424000000000000000000000000000840560000000000000000000000000000442225"),
531
1398
  3)
532
1399
  puts "e"
1400
+ end
1401
+
1402
+ # SLOW!!!
1403
+ def _test_lm_power1f
1404
+ print "\ntest_lm_power1f [#{Time.now}] (2 hours): "
533
1405
  check_power_floated(LongDecimal("0.999999999999983820000000000052544300000001372125483999980457478288050051600649560171986452284020178492146835403829341250837967306416835643061512149984415283328897050537606939603101940467080257495289168053434691062993302374332577706782680685214083677104079828206433042861334386773091111658939537092356816922764138900649581031721453211835260155666851398044388924204855221543729490461274063089475188763279119570"),
534
1406
  LongDecimal("80321932.89024988628926432624765785135567744505377819122460049392916097399960142838065367057138986526363804"),
535
1407
  40)
536
1408
  puts "f"
1409
+ end
1410
+
1411
+ # SLOW!!!
1412
+ def _test_lm_power1g
1413
+ print "\ntest_lm_power1g [#{Time.now}] (3 hours): "
537
1414
  check_power_floated(LongDecimal("0.999999999999999999999999999999998351999999999999983020000000000002036927999998210041974559999999997978335404004424810825925120045592892314014072707890311225042124730264194167337496376801852022987153782535008598977724682635285958668331865904517437818865287190004735483899633845078360662820274644903126498781970492928578903950"),
538
1415
  LongDecimal("24449877750611246943765281173.594132029339853300733454400081300326994697544849684064538112517261374573394648075725881734888526076256999828217542217625441301525934675012853453406806380262764050867999"),
539
1416
  5)
540
1417
  puts "g"
1418
+ end
1419
+
1420
+ # FAILURE!!! (needs to be fixed)
1421
+ def test_lm_power1h
1422
+ # 32) Failure:
1423
+ # test_lm_power1h(TestLongDecimalExtra_class) [/home/bk1/ruby/long-decimal/ruby/long-decimal/test/testlongdeclib.rb:537]:
1424
+ # u=log(z,7)=0.0000000 and yv=y*v=y*log(x,67)=-0.0000785 should be almost equal (unit=0.0000001 x=0.9999999999999999999999999999999999999999999999999999999999999992419999999999601999999916300000000000000000000000000000000000005745640000000603368000126905040400006662520000700569 y=103626942927112137297398420916877844574257389450065434211636.290893349001885021464207122860891972260613740163376239637940672943781241170230437221414760788160997546494517494155287108299429330120640311594334671250673655216674953919962963363315956632 z=1.0000000 u=0.0000000 v=-0.0000000000000000000000000000000000000000000000000000000000000007580 lprec=7 prec=7)
1425
+
1426
+ print "\ntest_lm_power1h [#{Time.now}]: "
541
1427
  check_power_floated(LongDecimal("0.999999999999999862599981980000014159073713922242243328677707050386499779178242565766291900177208859765599761583988066205590104341111429059119646260524293805643133602429678974677397380813589741657940554009198199034562447106122960905140273768835224006261013069576237942279008951360618433986"),
542
1428
  LongDecimal("10266940451745.37987679671457905534956086166404546967839388790271998098584221166751699838745542116653920000125768690393028114699714286512441385099525"),
543
1429
  14)
544
1430
  puts "h"
1431
+ end
1432
+
1433
+ # FAILURE!!! (needs to be fixed)
1434
+ def test_lm_power1i
1435
+ # 33) Failure:
1436
+ # test_lm_power1i(TestLongDecimalExtra_class) [/home/bk1/ruby/long-decimal/ruby/long-decimal/test/testlongdeclib.rb:537]:
1437
+ # u=log(z,13)=-0.0111941165167 and yv=y*v=y*log(x,76)=-0.0111941184373 should be almost equal (unit=0.0000000000001 x=1.000000000000000000000000000000000000000000000000000000000000000040632256971361441675364911547119523862617306023293961145667519711601390076843063624462699881424344873551296525030641685492629965401733250018815534188264352396285608689080041860127898254008134983805964167477328233064049446442345195928792206909976566059881698019 y=-275498317635275642242287018621310530812854589333829844444179465.026486828659378492893391926808279692889516447254926463357381523771105223660032617000227932272791794838690719013665737808233622061943268216888533855404111493288875534126178784830550654618969484969704069638284634725831920698820381864995363361738394367829090059556279914810540013438298547827401014937988931120431027937060054429855616000850263332145848273205542636020219974448846631834726343291615390210989854686573686051987947338952241558404158600234046969306176292822304779868899689391647661253521411090531104030615753856329486732170039585239348687257061864897478622958348189113878179294939392893585430107561210696450698403851795968372396462047808473453132852141249623740994995021422532249082127739 z=0.98886830447251 u=-0.0111941165167 v=0.0000000000000000000000000000000000000000000000000000000000000000406322569714 lprec=13 prec=14)
1438
+ print "\ntest_lm_power1i [#{Time.now}]: "
545
1439
  check_power_floated(LongDecimal("0.999999999999999981500000000000000256687499999999996834187500000000036604706930449997823687754750325053502286291757658419972795166437108241085949094447949893401640711985948839881287077716265593625727522425306777978451009970778400655052736724232660803755458234164496101454557290134193942433026948513566480800350007916601440691706219670728270104113540"),
546
1440
  LongDecimal("41380294430118397.455148144857963343847598908617723236165122243380531570432704458595232182042029429597565318650987561380534985825811466980798564531839364855305381553585381037046185516421336524897364607404185776449463"),
547
1441
  26)
548
1442
  puts "i"
1443
+ end
1444
+
1445
+ def test_lm_power1j
1446
+ print "\ntest_lm_power1j [#{Time.now}]: "
549
1447
  check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
550
1448
  LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
551
1449
  23)
552
1450
  puts "j"
1451
+ end
1452
+
1453
+ def test_lm_power1k
1454
+ print "\ntest_lm_power1k [#{Time.now}]: "
553
1455
  check_power_floated(LongDecimal("0.999999955000001687499940937501993359309219142762877860969997307557898777919131305606255214050322693251861572813240921773249050643887299214365089256902862200379712695062301304665207421015981915226866332635406597037254705387928614026219686983926304930980563519261869550253533841712248417739856791299844197817284010721773168197981077997089850680475101280715114294984559298890080189837019"),
554
1456
  LongDecimal("1152073732.71889400921658986175115207373271889400921658986175115207373271192582125814946165771199218501136146446091443861623733780713117713266372156187325484891985619348320999757983534072600830"),
555
1457
  34)
556
1458
  puts "k"
1459
+ end
1460
+
1461
+ def test_lm_power1l
1462
+ print "\ntest_lm_power1l [#{Time.now}]: "
557
1463
  check_power_floated(LongDecimal("0.9999999999999999790000000000000003307499999999999953571199999534000611652825014678992260416924691741095240984082153184971715719141172674714489939586322093325704050326051366867179642182008596501250357001333611677371975442553576183439891558582498678369021915"),
558
1464
  LongDecimal("723078346985052524411124.9942153732241195797916759141992675639370468905781573122561996247342863251769951237981444054472420932945762836317152649920140953979776753551488373967949714070011978110437743347922047335540909708006357292133505068791464115479823527616"),
559
1465
  12);
560
1466
  puts "l"
1467
+ end
1468
+
1469
+ def test_lm_power1m
1470
+ print "\ntest_lm_power1m [#{Time.now}]: "
561
1471
  check_power_floated(LongDecimal("0.0000000496000000000000000000000005130181"),
562
1472
  LongDecimal("4.481689070338064822602055460119275819005749868369667078288462665422608992659321754902779723364868999617977618563052671037918163226699981361015453605440282335627715767767332447975568034896269722320687889640"),
563
1473
  53)
564
-
1474
+ puts "m"
1475
+ end
1476
+
1477
+ def test_lm_power1n
1478
+ print "\ntest_lm_power1n [#{Time.now}]: "
1479
+ check_power_floated(LongDecimal("0.99999996920000071147998520954428850500259566957301785488841492770856751549533360159782111532707660143588897363762546661839650329823327036644"),
1480
+ LongDecimal("5136654.9693748423207184796146471922038482162171466427358132415227272949550162107575"),
1481
+ 35)
1482
+ puts "n"
1483
+ end
1484
+
1485
+ def test_lm_power1o
1486
+ print "\ntest_lm_power1o [#{Time.now}]: "
1487
+ check_power_floated(LongDecimal("0.999999999999999999999999999999999999999999999999990849999999999997459999999999999999999999999999514083722500000000046482000000000006451600000000008893033939125002468242034549999999822903580000236058"),
1488
+ LongDecimal("0.0000000000000000000000000000000"),
1489
+ 20)
1490
+ puts "o"
1491
+ end
1492
+
1493
+ def test_lm_power1p
1494
+ print "\ntest_lm_power1p [#{Time.now}]: "
1495
+ check_power_floated(LongDecimal("0.999999999999999999999999999999999999999999999999990849999999999997459999999999999999999999999999514083722500000000046482000000000006451600000000008893033939125002468242034549999999822903580000236058"),
1496
+ LongDecimal("0.0000000000000000000000000000000"),
1497
+ 40)
1498
+ puts "p"
1499
+ end
1500
+
1501
+ def test_lm_power1q
1502
+ print "\ntest_lm_power1q [#{Time.now}]: "
1503
+ check_power_floated(LongDecimal("0.999999999999999999999999999999999999999999999999990849999999999997459999999999999999999999999999514083722500000000046482000000000006451600000000008893033939125002468242034549999999822903580000236058"),
1504
+ LongDecimal("0.0000000000000000000000000000000"),
1505
+ 6)
1506
+ puts "q"
1507
+ end
1508
+
1509
+ def test_lm_power1r
1510
+ print "\ntest_lm_power1r [#{Time.now}]: "
1511
+ check_power_floated(LongDecimal("0.9999998980000104039989387921082432049591930941623043954449516646149302092771178487340615327073490985245976137220657507850136754851390337493573677445898517902642450071877694654887775650"),
1512
+ LongDecimal("-0.00000010199999479800035373597293919820816141870627986580"),
1513
+ 20)
1514
+ puts "r"
1515
+ end
1516
+
1517
+ def test_lm_power1s
1518
+ print "\ntest_lm_power1s [#{Time.now}]: "
1519
+ check_power_floated(LongDecimal("0.9999998980000104039989387921082432049591930941623043954449516646149302092771178487340615327073490985245976137220657507850136754851390337493573677445898517902642450071877694654887775650"),
1520
+ LongDecimal("-0.00000010199999479800035373597293919820816141870627986580"),
1521
+ 40)
1522
+ puts "s"
1523
+ end
1524
+
1525
+ def test_lm_power1t
1526
+ print "\ntest_lm_power1t [#{Time.now}]: "
1527
+ check_power_floated(LongDecimal("0.9999998980000104039989387921082432049591930941623043954449516646149302092771178487340615327073490985245976137220657507850136754851390337493573677445898517902642450071877694654887775650"),
1528
+ LongDecimal("-0.00000010199999479800035373597293919820816141870627986580"),
1529
+ 60)
1530
+ puts "t"
1531
+ end
1532
+
1533
+ # SLOW!!!
1534
+ def _test_lm_power1u
1535
+ print "\ntest_lm_power1u [#{Time.now}] (2 hours): "
1536
+ check_power_floated(LongDecimal("0.99999999999999999999999999999999999999999999999999992269999999999999999990289999999999999999450000000000597529000000000000001501166000000000000085972840999953811008406809999999825939805325"),
1537
+ LongDecimal("714285714285714285714285714.2857142367346938756989795918367346938775543790087466096793002963472667638481661974177164821324438268046647105967619250931245847564869975795833510071"),
1538
+ 25)
1539
+ puts "u"
1540
+ end
1541
+
1542
+ # SLOW!!!
1543
+ def _test_lm_power1v
1544
+ print "\ntest_lm_power1v [#{Time.now}] (2 hours): "
1545
+ check_power_floated(LongDecimal("0.999999999999999999072867000000000000859575599688999999203059095533538363738068211580703976213177165458547180420859035425970198975506846513796073745523480165"),
1546
+ LongDecimal("34260010678356060340110500.7153234888531563303375970232929042708037751160246890208435860708347495272359620209409070219221760532838693330228630931194027855701638117625325214394917620590686906959334466842413732434252133614001314264745394120941492068918606855981807681794442879762888899961878810388388032398007558964413624601333106812667470835155455035290542870179962369969203293410746331815980"),
1547
+ 4)
1548
+ puts "v"
1549
+ end
1550
+
1551
+ def test_lm_power1w
1552
+ print "\ntest_lm_power1w [#{Time.now}]: "
1553
+ check_power_floated(LongDecimal("0.999999955000001687499940937501993359309219142762877860969997307557898777919131305606255214050322693251861572813240921773249050643887299214365089256902862200379712695062301304665207421015981915226866332635406597037254705387928614026219686983926304930980563519261869550253533841712248417739856791299844197817284010721773168197981077997089850680475101280715114294984559298890080189837019"),
1554
+ LongDecimal("1152073732.71889400921658986175115207373271889400921658986175115207373271192582125814946165771199218501136146446091443861623733780713117713266372156187325484891985619348320999757983534072600830"),
1555
+ 34)
1556
+ puts "w"
1557
+ end
1558
+
1559
+ def test_lm_power1x
1560
+ print "\ntest_lm_power1x [#{Time.now}]: "
1561
+ check_power_floated(LongDecimal("0.9999999999999999064168934619655513256941764460425414729252240962626457779773851512889793738821624571066326550143425938244580355705073371363498199960410647291522935828683767303102466756569778099219013139392035"),
1562
+ LongDecimal("10940919037196297324861503538918892464840.3800411376419061644237297393478808698419759633900911655114302630926763678029075600021060757487171800272518085362"),
1563
+ 31)
1564
+ puts "x"
1565
+ end
1566
+
1567
+ # SLOW!!!
1568
+ def _test_lm_power1y
1569
+ print "\ntest_lm_power1y [#{Time.now}] (3 hours): "
1570
+ check_power_floated(LongDecimal("0.9999999999999999999999999999999999999999999938200000000000000000000000000000000000000000379683968899999999999999999999999999999999997667396464396000000000000000000000000000000014330439460181976721"),
1571
+ LongDecimal("2277904328018223234624145785876970127.80132938289029176166582780311904615875187470778863280340852479308725681566723062546696023632646350474949485203212931524794058129718906431046410107451255702719381563833303042603168923"),
1572
+ 29)
1573
+ puts "y"
1574
+ end
1575
+
1576
+ def test_lm_power1z
1577
+ print "\ntest_lm_power1z [#{Time.now}]: "
1578
+ check_power_floated(LongDecimal("0.999999999999999999999999999999999999999999921999999999022000000000000000000000000000004562456000114426000000717362999999999999999762787647991075570047888091371999532279324011562240678532015324522910310739147205531819744871729906561958405090975079783409588877137073074435963740549942065227793722398369867644224486056519686420388938836344615901685525200381485995400522678667"),
1579
+ LongDecimal("251896264925304377034350.0456973701263557812685942497288369797184140257647711785792872260304633895246908954737965005622561558677304225230618944035174740629720501757778145343269720425431792498286712042768306433898613430002918272371991628626003640130802094416142868825298695247199911145446388281612176850992412410783824332967890487347362798155764095915034449097990865463350294815436981248914797801550176"),
1580
+ 35)
1581
+ puts "z"
1582
+ end
1583
+
1584
+ def test_lm_power1a
1585
+ print "\ntest_lm_power1a [#{Time.now}]: "
1586
+ check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
1587
+ LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
1588
+ 20)
1589
+ puts "a"
1590
+ end
1591
+
1592
+ def test_lm_power1b
1593
+ print "\ntest_lm_power1b [#{Time.now}]: "
1594
+ check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
1595
+ LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
1596
+ 40)
1597
+ puts "b"
1598
+ end
1599
+
1600
+ def test_lm_power1c
1601
+ print "\ntest_lm_power1c [#{Time.now}]: "
1602
+ check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
1603
+ LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
1604
+ 60)
1605
+ puts "c"
1606
+ end
1607
+
1608
+ def test_lm_power1d
1609
+ print "\ntest_lm_power1d [#{Time.now}]: "
1610
+ check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000839040721742199946496057135094908790087131086768769514275053742150410299262922831017525963255748365635401006943680692892935684091800542751473902211475954311868825323737772210353295492066820457541121321"),
1611
+ LongDecimal("2.828427124746193491715927143848192103847391807094579920269011137128713363765124971278"),
1612
+ 18)
1613
+ puts "d"
1614
+ end
1615
+
1616
+ def test_lm_power1e
1617
+ print "\ntest_lm_power1e [#{Time.now}]: "
1618
+ check_power_floated(LongDecimal("0.99999999999999999957080000000000000013815947999999999996046796745599999999068446772992800001009363347018894143517944326551369536327300875532667540019363271336013307136215732697434336575655193825816793693484735543517962560133437707866565666368082465969956371712599637541755027515672768774646443956623736866833"),
1619
+ LongDecimal("1628664495113750809027151521859950785.982561401863566922682596781753765470394912797043370321097687714712745442876309819766690333961107251381272682168155358789120923845170161713855374636824144351065708845142153775687292"),
1620
+ 25)
1621
+ puts "e"
1622
+ end
1623
+
1624
+ def test_lm_power1f
1625
+ print "\ntest_lm_power1f [#{Time.now}]: "
1626
+ check_power_floated(LongDecimal("0.9999999999999999999996170000000000000000001466889999999999999995988181130000000000002857876622509999999998399356205378770000001997124082800492789998249134043407016130331222803769176235159503"),
1627
+ LongDecimal("10080628902211448045469261303.5133048444625606725923502869474154814472661420686348619932383678206438602596885342965949921926737285"),
1628
+ 40)
1629
+ puts "f"
1630
+ end
1631
+
1632
+ def test_lm_power1g
1633
+ print "\ntest_lm_power1g [#{Time.now}]: "
1634
+ check_power_floated(LongDecimal("0.99999999999999999999999999999999999999999999999999999567999999999999999999999999993280680000000000000000001866240000000000000000000000058054924799999999999999991938294692612624"),
1635
+ LongDecimal("172711571675280380383067706300721798.164293576729518909754806389655985463898067955382434334508821341973697474920186895196633042535349353452630898625575004836357975433177114954313031033076280846"),
1636
+ 29)
1637
+ puts "g"
1638
+ end
1639
+
1640
+ def test_lm_power1h
1641
+ print "\ntest_lm_power1h [#{Time.now}]: "
1642
+ check_power_floated(LongDecimal("0.9999999999999999999999999999999999999999999999999999999999999992419999999999601999999916300000000000000000000000000000000000005745640000000603368000126905040400006662520000700569"),
1643
+ LongDecimal("103626942927112137297398420916877844574257389450065434211636.290893349001885021464207122860891972260613740163376239637940672943781241170230437221414760788160997546494517494155287108299429330120640311594334671250673655216674953919962963363315956632"),
1644
+ 7)
1645
+ puts "h"
1646
+ end
1647
+
1648
+ def test_lm_power1i
1649
+ print "\ntest_lm_power1i [#{Time.now}]: "
1650
+ check_power_floated(LongDecimal("1.000000000000000000000000000000000000000000000000000000000000000040632256971361441675364911547119523862617306023293961145667519711601390076843063624462699881424344873551296525030641685492629965401733250018815534188264352396285608689080041860127898254008134983805964167477328233064049446442345195928792206909976566059881698019"),
1651
+ LongDecimal("-275498317635275642242287018621310530812854589333829844444179465.026486828659378492893391926808279692889516447254926463357381523771105223660032617000227932272791794838690719013665737808233622061943268216888533855404111493288875534126178784830550654618969484969704069638284634725831920698820381864995363361738394367829090059556279914810540013438298547827401014937988931120431027937060054429855616000850263332145848273205542636020219974448846631834726343291615390210989854686573686051987947338952241558404158600234046969306176292822304779868899689391647661253521411090531104030615753856329486732170039585239348687257061864897478622958348189113878179294939392893585430107561210696450698403851795968372396462047808473453132852141249623740994995021422532249082127739"),
1652
+ 14)
1653
+ puts "i"
565
1654
  end
566
1655
 
567
1656
  #
568
1657
  # test the calculation of the base-10-logarithm function
569
1658
  #
570
1659
  def test_log10
1660
+ print "\ntest_log10 [#{Time.now}]: "
571
1661
  check_log10_floated(10**2000, 30)
572
1662
  check_log10_floated(100, 30)
573
1663
  check_log10_floated(1, 30)
@@ -602,6 +1692,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
602
1692
  # test the calculation of the base-10-logarithm function
603
1693
  #
604
1694
  def test_log2
1695
+ print "\ntest_log2 [#{Time.now}]: "
605
1696
  check_log2_floated(10**2000, 30)
606
1697
  check_log2_floated(2**2000, 30)
607
1698
  check_log2_floated(100, 30)
@@ -633,6 +1724,7 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
633
1724
  # test the calculation of the base-x-logarithm of sqrt(x)
634
1725
  #
635
1726
  def test_log_2_10_of_sqrt
1727
+ print "\ntest_log_2_10_of_sqrt [#{Time.now}]: "
636
1728
  # n = 125
637
1729
  n = 30
638
1730
  m = 5
@@ -653,6 +1745,6 @@ class TestLongDecimalExtra_class < RUNIT::TestCase
653
1745
 
654
1746
  end
655
1747
 
656
- RUNIT::CUI::TestRunner.run(TestLongDecimalExtra_class.suite)
1748
+ # RUNIT::CUI::TestRunner.run(TestLongDecimalExtra_class.suite)
657
1749
 
658
1750
  # end of file testlongdecimal.rb