long-decimal 1.00.01 → 1.00.02
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/LICENSE +15 -0
- data/README +41 -41
- data/Rakefile +19 -73
- data/lib/long-decimal-extra.rb +5 -672
- data/lib/long-decimal.rb +1609 -141
- data/lib/long-decimal/version.rb +3 -0
- data/long-decimal.gemspec +22 -0
- data/test/testlongdecimal.rb +2498 -651
- data/test/testlongdeclib.rb +20 -10
- data/test/testrandlib.rb +6 -5
- data/test/testrandom.rb +30 -14
- data/test/testrandpower.rb +22 -7
- data/tex/long-decimal.pdf +0 -0
- data/tex/long-decimal.tex +420 -0
- metadata +72 -64
- data/VERSION +0 -1
- data/install.rb +0 -18
- data/make_doc.rb +0 -12
- data/test/testlongdecimal-extra.rb +0 -1750
- data/test/testlongdecimal-performance.rb +0 -357
- data/test/testrandom-extra.rb +0 -80
- data/version.rb +0 -39
@@ -1,357 +0,0 @@
|
|
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
|
data/test/testrandom-extra.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# testrandom-extra.rb -- randem tests for long-decimal-extra.rb
|
4
|
-
#
|
5
|
-
# (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
|
6
|
-
#
|
7
|
-
# CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testrandom-extra.rb,v 1.4 2009/05/09 15:37:00 bk1 Exp $
|
8
|
-
# CVS-Label: $Name: RELEASE_1_00_00 $
|
9
|
-
# Author: $Author: bk1 $ (Karl Brodowsky)
|
10
|
-
#
|
11
|
-
|
12
|
-
require "runit/testcase"
|
13
|
-
require "runit/cui/testrunner"
|
14
|
-
require "runit/testsuite"
|
15
|
-
require "crypt/ISAAC"
|
16
|
-
|
17
|
-
load "lib/long-decimal.rb"
|
18
|
-
load "lib/long-decimal-extra.rb"
|
19
|
-
|
20
|
-
load "test/testlongdeclib.rb"
|
21
|
-
load "test/testrandlib.rb"
|
22
|
-
|
23
|
-
LongMath.prec_overflow_handling = :warn_use_max
|
24
|
-
|
25
|
-
#
|
26
|
-
# test class for LongDecimal and LongDecimalQuot
|
27
|
-
#
|
28
|
-
class TestRandom_class < RUNIT::TestCase
|
29
|
-
include TestLongDecHelper
|
30
|
-
include TestRandomHelper
|
31
|
-
|
32
|
-
@RCS_ID='-$Id: testrandom-extra.rb,v 1.4 2009/05/09 15:37:00 bk1 Exp $-'
|
33
|
-
|
34
|
-
# for how many seconds should this test run? change to different
|
35
|
-
# value on demand
|
36
|
-
@@duration = 1000000
|
37
|
-
|
38
|
-
def check_exp_log_rand(arr, eprec, lprec, pprec, sprec, sc, cnt)
|
39
|
-
arr.each do |x|
|
40
|
-
@scnt += 1
|
41
|
-
puts("\ncnt=#{cnt} scnt=#{@scnt} x=#{x} ep=#{eprec} lp=#{lprec} sp=#{sprec} pp=#{pprec}\n")
|
42
|
-
if (x <= LongMath::MAX_EXP_ABLE) then
|
43
|
-
check_exp_floated(x, eprec)
|
44
|
-
check_exp2_floated(x, pprec)
|
45
|
-
check_exp10_floated(x, pprec)
|
46
|
-
end
|
47
|
-
if (x > 0)
|
48
|
-
check_log_floated(x, lprec)
|
49
|
-
check_log2_floated(x, lprec)
|
50
|
-
check_log10_floated(x, lprec)
|
51
|
-
end
|
52
|
-
if (x > 0)
|
53
|
-
xr = x.round_to_scale(sc, LongMath::ROUND_HALF_UP)
|
54
|
-
check_sqrt_with_remainder(xr, sprec, "x=#{x} p=#{sprec}")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
# test the calculation of the exponential function
|
61
|
-
#
|
62
|
-
def test_random
|
63
|
-
cnt = 0
|
64
|
-
@scnt = 0
|
65
|
-
t0 = Time.new
|
66
|
-
while (true) do
|
67
|
-
d = Time.new - t0
|
68
|
-
break if d >= @@duration
|
69
|
-
arr, eprec, lprec, sprec, pprec, sc = random_arr
|
70
|
-
check_exp_log_rand(arr, eprec, lprec, pprec, sprec, sc, cnt)
|
71
|
-
cnt += 1
|
72
|
-
end
|
73
|
-
puts("done #{cnt} tests\n")
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
RUNIT::CUI::TestRunner.run(TestRandom_class.suite)
|
79
|
-
|
80
|
-
# end of file testrandom.rb
|
data/version.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#
|
4
|
-
# version.rb -- extract version information from files
|
5
|
-
#
|
6
|
-
# (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
|
7
|
-
#
|
8
|
-
# CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/version.rb,v 1.9 2011/01/22 12:34:39 bk1 Exp $
|
9
|
-
# CVS-Label: $Name: RELEASE_1_00_00 $
|
10
|
-
# Author: $Author: bk1 $ (Karl Brodowsky)
|
11
|
-
#
|
12
|
-
|
13
|
-
ARGV.each do |file|
|
14
|
-
name = ""
|
15
|
-
version = ""
|
16
|
-
|
17
|
-
File.open(file, "r") do |openFile|
|
18
|
-
openFile.each_line do |line|
|
19
|
-
if line =~ /\$[H]eader:\s.+,v\s+([0-9.]+)\s*.+\$/ then
|
20
|
-
version = $1
|
21
|
-
elsif line =~ /\$[N]ame:\s+(\S+)\s+\$/ then
|
22
|
-
name = $1
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
str = ""
|
28
|
-
if name =~ /(PRE_ALPHA|ALPHA|BETA)_(\d+)_(\d+)/ then
|
29
|
-
str = sprintf("0.%02d.%02d", $2.to_i, $3.to_i)
|
30
|
-
elsif name =~ /RELEASE_(\d+)_(\d+)_(\d+)/
|
31
|
-
str = sprintf("%d.%02d.%02d", $1.to_i, $2.to_i, $3.to_i)
|
32
|
-
else
|
33
|
-
str = version
|
34
|
-
end
|
35
|
-
|
36
|
-
print str,"\n"
|
37
|
-
end
|
38
|
-
|
39
|
-
# end of file version.rb
|