long-decimal 0.00.11 → 0.00.12
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.
- data/README +6 -3
- data/VERSION +1 -1
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.html +5 -5
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000133.html +22 -0
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000135.html +22 -0
- data/doc/classes/LongMath.html +78 -29
- data/doc/classes/LongMath.src/M000001.html +1 -1
- data/doc/classes/LongMath.src/M000002.html +1 -1
- data/doc/classes/LongMath.src/M000003.html +1 -1
- data/doc/classes/LongMath.src/M000004.html +1 -1
- data/doc/classes/LongMath.src/M000005.html +1 -1
- data/doc/classes/LongMath.src/M000006.html +1 -1
- data/doc/classes/LongMath.src/M000007.html +1 -1
- data/doc/classes/LongMath.src/M000008.html +1 -1
- data/doc/classes/LongMath.src/M000009.html +1 -1
- data/doc/classes/LongMath.src/M000010.html +1 -1
- data/doc/classes/LongMath.src/M000011.html +2 -2
- data/doc/classes/LongMath.src/M000012.html +1 -1
- data/doc/classes/LongMath.src/M000013.html +1 -1
- data/doc/classes/LongMath.src/M000014.html +1 -1
- data/doc/classes/LongMath.src/M000015.html +1 -1
- data/doc/classes/LongMath.src/M000016.html +14 -11
- data/doc/classes/LongMath.src/M000017.html +10 -17
- data/doc/classes/LongMath.src/M000018.html +1 -1
- data/doc/classes/LongMath.src/M000019.html +2 -1
- data/doc/classes/LongMath.src/M000021.html +51 -1
- data/doc/classes/LongMath.src/M000022.html +12 -9
- data/doc/classes/LongMath.src/M000023.html +28 -5
- data/doc/classes/LongMath.src/M000024.html +22 -0
- data/doc/classes/LongMath.src/M000025.html +18 -0
- data/doc/classes/LongMath/LongDecimal.html +371 -371
- data/doc/classes/LongMath/LongDecimal.src/M000058.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000059.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000060.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000061.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000062.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000063.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000064.html +4 -6
- data/doc/classes/LongMath/LongDecimal.src/M000065.html +4 -95
- data/doc/classes/LongMath/LongDecimal.src/M000066.html +6 -20
- data/doc/classes/LongMath/LongDecimal.src/M000067.html +92 -24
- data/doc/classes/LongMath/LongDecimal.src/M000068.html +17 -18
- data/doc/classes/LongMath/LongDecimal.src/M000069.html +27 -4
- data/doc/classes/LongMath/LongDecimal.src/M000070.html +19 -13
- data/doc/classes/LongMath/LongDecimal.src/M000071.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000072.html +13 -22
- data/doc/classes/LongMath/LongDecimal.src/M000073.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000074.html +24 -4
- data/doc/classes/LongMath/LongDecimal.src/M000075.html +4 -6
- data/doc/classes/LongMath/LongDecimal.src/M000076.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000077.html +6 -15
- data/doc/classes/LongMath/LongDecimal.src/M000078.html +4 -32
- data/doc/classes/LongMath/LongDecimal.src/M000079.html +14 -14
- data/doc/classes/LongMath/LongDecimal.src/M000080.html +31 -12
- data/doc/classes/LongMath/LongDecimal.src/M000081.html +15 -4
- data/doc/classes/LongMath/LongDecimal.src/M000082.html +27 -0
- data/doc/classes/LongMath/LongDecimal.src/M000083.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000085.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000086.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000087.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000088.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000089.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000090.html +4 -8
- data/doc/classes/LongMath/LongDecimal.src/M000091.html +4 -9
- data/doc/classes/LongMath/LongDecimal.src/M000092.html +6 -7
- data/doc/classes/LongMath/LongDecimal.src/M000093.html +6 -6
- data/doc/classes/LongMath/LongDecimal.src/M000094.html +9 -4
- data/doc/classes/LongMath/LongDecimal.src/M000095.html +7 -13
- data/doc/classes/LongMath/LongDecimal.src/M000096.html +4 -9
- data/doc/classes/LongMath/LongDecimal.src/M000097.html +13 -7
- data/doc/classes/LongMath/LongDecimal.src/M000098.html +7 -18
- data/doc/classes/LongMath/LongDecimal.src/M000099.html +8 -7
- data/doc/classes/LongMath/LongDecimal.src/M000100.html +20 -5
- data/doc/classes/LongMath/LongDecimal.src/M000101.html +7 -8
- data/doc/classes/LongMath/LongDecimal.src/M000102.html +5 -9
- data/doc/classes/LongMath/LongDecimal.src/M000103.html +5 -5
- data/doc/classes/LongMath/LongDecimal.src/M000104.html +9 -4
- data/doc/classes/LongMath/LongDecimal.src/M000105.html +8 -6
- data/doc/classes/LongMath/LongDecimal.src/M000106.html +4 -7
- data/doc/classes/LongMath/LongDecimal.src/M000107.html +7 -4
- data/doc/classes/LongMath/LongDecimal.src/M000108.html +7 -4
- data/doc/classes/LongMath/LongDecimal.src/M000109.html +4 -9
- data/doc/classes/LongMath/LongDecimal.src/M000110.html +4 -9
- data/doc/classes/LongMath/LongDecimal.src/M000111.html +9 -5
- data/doc/classes/LongMath/LongDecimal.src/M000112.html +7 -7
- data/doc/classes/LongMath/LongDecimal.src/M000113.html +5 -4
- data/doc/classes/LongMath/LongDecimal.src/M000114.html +8 -15
- data/doc/classes/LongMath/LongDecimal.src/M000115.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000116.html +15 -8
- data/doc/classes/LongMath/LongDecimal.src/M000117.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000119.html +4 -9
- data/doc/classes/LongMath/LongDecimal.src/M000121.html +9 -4
- data/doc/classes/LongMath/LongDecimal.src/M000122.html +5 -33
- data/doc/classes/LongMath/LongDecimal.src/M000123.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000124.html +33 -4
- data/doc/classes/LongMath/LongDecimal.src/M000125.html +4 -33
- data/doc/classes/LongMath/LongDecimal.src/M000126.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000128.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000129.html +19 -0
- data/doc/classes/LongMath/LongDecimal.src/M000130.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000131.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000132.html +4 -4
- data/doc/classes/LongMath/LongDecimal.src/M000133.html +4 -4
- data/doc/classes/LongMath/LongDecimalQuot.html +168 -168
- data/doc/classes/LongMath/LongDecimalQuot.src/M000026.html +4 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000027.html +14 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000028.html +4 -5
- data/doc/classes/LongMath/LongDecimalQuot.src/M000029.html +4 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000030.html +5 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000031.html +4 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000032.html +4 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000033.html +4 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000034.html +4 -8
- data/doc/classes/LongMath/LongDecimalQuot.src/M000035.html +4 -9
- data/doc/classes/LongMath/LongDecimalQuot.src/M000036.html +6 -7
- data/doc/classes/LongMath/LongDecimalQuot.src/M000037.html +5 -5
- data/doc/classes/LongMath/LongDecimalQuot.src/M000038.html +5 -5
- data/doc/classes/LongMath/LongDecimalQuot.src/M000039.html +7 -19
- data/doc/classes/LongMath/LongDecimalQuot.src/M000040.html +8 -7
- data/doc/classes/LongMath/LongDecimalQuot.src/M000041.html +21 -5
- data/doc/classes/LongMath/LongDecimalQuot.src/M000042.html +8 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000043.html +5 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000044.html +4 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000045.html +4 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000046.html +4 -63
- data/doc/classes/LongMath/LongDecimalQuot.src/M000047.html +4 -22
- data/doc/classes/LongMath/LongDecimalQuot.src/M000048.html +63 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000049.html +20 -7
- data/doc/classes/LongMath/LongDecimalQuot.src/M000050.html +4 -5
- data/doc/classes/LongMath/LongDecimalQuot.src/M000051.html +9 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000052.html +5 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000053.html +4 -4
- data/doc/classes/LongMath/LongDecimalQuot.src/M000054.html +1 -1
- data/doc/classes/LongMath/LongDecimalQuot.src/M000055.html +1 -1
- data/doc/classes/LongMath/LongDecimalQuot.src/M000056.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000057.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000058.html +1 -1
- data/doc/classes/LongMath/LongDecimalQuot.src/M000059.html +4 -4
- data/doc/classes/LongMath/Numeric.html +5 -5
- data/doc/classes/LongMath/Numeric.src/M000132.html +18 -0
- data/doc/classes/LongMath/Numeric.src/M000134.html +18 -0
- data/doc/created.rid +1 -1
- data/doc/files/lib/longdecimal_rb.html +2 -2
- data/doc/fr_method_index.html +115 -113
- data/lib/longdecimal.rb +84 -34
- data/test/testlongdecimal.rb +271 -15
- metadata +17 -2
data/test/testlongdecimal.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
#
|
3
3
|
# testlongdecimal.rb -- runit test for longdecimal.rb
|
4
4
|
#
|
5
|
-
# CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal.rb,v 1.
|
6
|
-
# CVS-Label: $Name:
|
5
|
+
# CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal.rb,v 1.7 2006/03/18 06:03:58 bk1 Exp $
|
6
|
+
# CVS-Label: $Name: PRE_ALPHA_0_12 $
|
7
7
|
# Author: $Author: bk1 $ (Karl Brodowsky)
|
8
8
|
#
|
9
9
|
|
@@ -18,7 +18,7 @@ load "lib/longdecimal.rb"
|
|
18
18
|
#
|
19
19
|
class TestLongDecimal_class < RUNIT::TestCase
|
20
20
|
|
21
|
-
@RCS_ID='-$Id: testlongdecimal.rb,v 1.
|
21
|
+
@RCS_ID='-$Id: testlongdecimal.rb,v 1.7 2006/03/18 06:03:58 bk1 Exp $-'
|
22
22
|
|
23
23
|
def check_split_merge_words(x, l, wl)
|
24
24
|
w = LongMath.split_to_words(x, l)
|
@@ -101,6 +101,7 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
101
101
|
# test the calculation of the exponential function
|
102
102
|
#
|
103
103
|
def test_exp
|
104
|
+
xx = LongMath.log(10.to_ld, 10)*100
|
104
105
|
check_exp_floated(700, 10)
|
105
106
|
check_exp_floated(100, 10)
|
106
107
|
check_exp_floated(1, 10)
|
@@ -111,7 +112,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
111
112
|
check_exp_floated(-1, 10)
|
112
113
|
check_exp_floated(-100, 10)
|
113
114
|
check_exp_floated(-700, 10)
|
114
|
-
|
115
|
+
check_exp_floated(xx, 10)
|
116
|
+
check_exp_floated(-xx, 10)
|
117
|
+
|
115
118
|
check_exp_floated(700, 100)
|
116
119
|
check_exp_floated(100, 100)
|
117
120
|
check_exp_floated(1, 100)
|
@@ -122,6 +125,8 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
122
125
|
check_exp_floated(-1, 100)
|
123
126
|
check_exp_floated(-100, 100)
|
124
127
|
check_exp_floated(-700, 100)
|
128
|
+
check_exp_floated(xx, 100)
|
129
|
+
check_exp_floated(-xx, 100)
|
125
130
|
end
|
126
131
|
|
127
132
|
#
|
@@ -153,15 +158,15 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
153
158
|
if (y <= LongMath::MAX_EXP_ABLE) then
|
154
159
|
eprec = prec
|
155
160
|
if (y > 1) then
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
161
|
+
lx = 0
|
162
|
+
if (x > LongMath::MAX_FLOATABLE) then
|
163
|
+
puts("unusual x=#{x} y=#{y}\n")
|
164
|
+
lx = LongMath::MAX_EXP_ABLE
|
165
|
+
else
|
166
|
+
lx = Math.log(x.to_f)
|
167
|
+
end
|
163
168
|
l10 = (lx / Math.log(10)).ceil
|
164
|
-
eprec
|
169
|
+
eprec = [ eprec - l10, 0 ].max
|
165
170
|
end
|
166
171
|
|
167
172
|
z = LongMath.exp(y, eprec)
|
@@ -176,7 +181,7 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
176
181
|
end
|
177
182
|
|
178
183
|
#
|
179
|
-
# test the calculation of the
|
184
|
+
# test the calculation of the logarithm function
|
180
185
|
#
|
181
186
|
def test_log
|
182
187
|
check_log_floated(10**2000, 10)
|
@@ -198,6 +203,145 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
198
203
|
check_log_floated(LongDecimal(1, 2000), 100)
|
199
204
|
end
|
200
205
|
|
206
|
+
#
|
207
|
+
# helper method for test_exp
|
208
|
+
# tests if LongMath::power(x, y, prec) with precision prec is calculated correctly
|
209
|
+
#
|
210
|
+
def check_power_floated(x, y, prec)
|
211
|
+
|
212
|
+
# puts("start: check_power_floated: x=#{x} y=#{y} prec=#{prec}\n")
|
213
|
+
# make sure x and y are LongDecimal
|
214
|
+
x0 = x
|
215
|
+
x = x.to_ld
|
216
|
+
y0 = y
|
217
|
+
y = y.to_ld
|
218
|
+
# calculate z = x**y
|
219
|
+
z = LongMath.power(x, y, prec)
|
220
|
+
|
221
|
+
# compare y against w = x**y calculated using regular floating point arithmetic
|
222
|
+
w = (x.to_f) ** (y.to_f)
|
223
|
+
zf = z.to_f
|
224
|
+
assert((zf - w) / [zf.abs, w.abs, Float::MIN].max < 1e-9, "z=#{zf.to_s} and w=#{w.to_s} should be almost equal x=#{x} y=#{y}")
|
225
|
+
|
226
|
+
# check by taking log(z) = y * log(x)
|
227
|
+
# we have to take into account that we might not have enough
|
228
|
+
# significant digits, so we have to go down with the precision
|
229
|
+
if (z > 0) then
|
230
|
+
lprec = prec
|
231
|
+
if (z < 1) then
|
232
|
+
l10 = (Math.log(z.to_f) / Math.log(10)).round
|
233
|
+
lprec += l10
|
234
|
+
end
|
235
|
+
if (x < 1) then
|
236
|
+
l10 = (Math.log(x.to_f) / Math.log(10)).round
|
237
|
+
lprec += l10
|
238
|
+
end
|
239
|
+
l10y = 0
|
240
|
+
if (y > 1) then
|
241
|
+
l10y = (Math.log(y.to_f) / Math.log(10)).ceil
|
242
|
+
end
|
243
|
+
u = LongMath.log(z, lprec)
|
244
|
+
v = LongMath.log(x, lprec+l10y)
|
245
|
+
yv = (y*v).round_to_scale(lprec, LongDecimal::ROUND_HALF_DOWN)
|
246
|
+
assert((u - yv).abs <= u.unit, "u=#{u} and y*v=#{yv} should be almost equal (x=#{x.to_s} y=#{y.to_s} z=#{z.to_s} u=#{u.to_s} v=#{v.to_s} lprec=#{lprec} prec=#{prec})")
|
247
|
+
end
|
248
|
+
# puts("ok check_power_floated: x=#{x} y=#{y} prec=#{prec}\n")
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
#
|
253
|
+
# test the calculation of the exponential function
|
254
|
+
#
|
255
|
+
def test_lm_power
|
256
|
+
check_power_floated(1, 1, 10)
|
257
|
+
check_power_floated(1, 2, 10)
|
258
|
+
check_power_floated(2, 1, 10)
|
259
|
+
check_power_floated(2, 2, 10)
|
260
|
+
check_power_floated(100, 10, 10)
|
261
|
+
check_power_floated(10, 100, 10)
|
262
|
+
check_power_floated(10, 100, 100)
|
263
|
+
end
|
264
|
+
|
265
|
+
#
|
266
|
+
# helper method for test_log
|
267
|
+
# tests if log10(x) with precision prec is calculated correctly
|
268
|
+
#
|
269
|
+
def check_log10_floated(x, prec)
|
270
|
+
|
271
|
+
# make sure x is LongDecimal
|
272
|
+
x0 = x
|
273
|
+
x = x.to_ld
|
274
|
+
# calculate y = log10(x)
|
275
|
+
y = LongMath.log10(x, prec)
|
276
|
+
|
277
|
+
# compare y against z = log10(x) calculated using regular floating
|
278
|
+
# point arithmetic
|
279
|
+
if (x <= LongMath::MAX_FLOATABLE) then
|
280
|
+
xf = x.to_f
|
281
|
+
if (xf > 0) then
|
282
|
+
z = Math.log(x.to_f) / Math.log(10)
|
283
|
+
yf = y.to_f
|
284
|
+
assert((yf - z) / [yf.abs, z.abs, Float::MIN].max < 1e-9, "y=#{yf.to_s} and z=#{z.to_s} should be almost equal x=#{x}")
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
# check by taking 10**(log10(x))
|
289
|
+
# we have to take into account that we might not have enough
|
290
|
+
# significant digits, so we have to go down with the precision
|
291
|
+
if (y <= LongMath::MAX_EXP_ABLE) then
|
292
|
+
eprec = prec
|
293
|
+
if (y > 1) then
|
294
|
+
lx = 0
|
295
|
+
if (x > LongMath::MAX_FLOATABLE) then
|
296
|
+
puts("unusual x=#{x} y=#{y}\n")
|
297
|
+
lx = LongMath::MAX_EXP_ABLE
|
298
|
+
else
|
299
|
+
lx = Math.log(x.to_f)
|
300
|
+
end
|
301
|
+
l10 = (lx / Math.log(10)).ceil
|
302
|
+
eprec = [ eprec - l10, 0 ].max
|
303
|
+
end
|
304
|
+
|
305
|
+
z = LongMath.power(10.to_ld, y, eprec)
|
306
|
+
assert((x - z).abs <= z.unit, "x=#{x.to_s} and z=#{z.to_s} should be almost equal (y=#{y.to_s} eprec=#{eprec} prec=#{prec})")
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
#
|
312
|
+
# helper method for test_log
|
313
|
+
# tests if log10(x) with precision prec is calculated correctly
|
314
|
+
#
|
315
|
+
def check_log10_exact(x, log10x, prec)
|
316
|
+
|
317
|
+
# make sure x is LongDecimal
|
318
|
+
x0 = x
|
319
|
+
x = x.to_ld
|
320
|
+
log10x = log10x.to_ld.round_to_scale(prec)
|
321
|
+
# calculate y = log10(x)
|
322
|
+
y = LongMath.log10(x, prec)
|
323
|
+
assert_equal(y, log10x, "log x should match exactly x=#{x} y=#{y} log10x=#{log10x}")
|
324
|
+
end
|
325
|
+
|
326
|
+
#
|
327
|
+
# test the calculation of the logarithm function
|
328
|
+
#
|
329
|
+
def test_log10
|
330
|
+
check_log10_floated(10**2000, 30)
|
331
|
+
check_log10_floated(100, 30)
|
332
|
+
check_log10_floated(1, 30)
|
333
|
+
check_log10_floated(0.01, 30)
|
334
|
+
check_log10_floated(1e-10, 30)
|
335
|
+
check_log10_floated(1e-90, 30)
|
336
|
+
check_log10_floated(1e-300, 30)
|
337
|
+
check_log10_floated(LongDecimal(1, 2000), 30)
|
338
|
+
|
339
|
+
check_log10_exact(10**2000, 2000, 30)
|
340
|
+
check_log10_exact(10**0, 0, 30)
|
341
|
+
check_log10_exact(10**1, 1, 30)
|
342
|
+
check_log10_exact(10**10, 10, 30)
|
343
|
+
end
|
344
|
+
|
201
345
|
#
|
202
346
|
# helper method for test_sqrtb
|
203
347
|
#
|
@@ -357,7 +501,7 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
357
501
|
end
|
358
502
|
|
359
503
|
#
|
360
|
-
# test construction from Integer
|
504
|
+
# test construction of LongDecimal from Integer
|
361
505
|
#
|
362
506
|
def test_int_init
|
363
507
|
l = LongDecimal(224)
|
@@ -415,7 +559,7 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
415
559
|
end
|
416
560
|
|
417
561
|
#
|
418
|
-
# test rounding with ROUND_UP
|
562
|
+
# test rounding of LongDecimal with ROUND_UP
|
419
563
|
#
|
420
564
|
def test_round_to_scale_up
|
421
565
|
l = LongDecimal("2.21")
|
@@ -761,6 +905,10 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
761
905
|
assert_equal(-23, l.to_i, "l=#{l.inspect}")
|
762
906
|
end
|
763
907
|
|
908
|
+
#
|
909
|
+
# test adjustment of scale which is used as preparation for addition
|
910
|
+
# and subtraction
|
911
|
+
#
|
764
912
|
def test_equalize_scale
|
765
913
|
x = LongDecimal(1, 0)
|
766
914
|
y = LongDecimal(10, 1)
|
@@ -778,6 +926,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
778
926
|
assert_equal(200, v.int_val, "int_val must be 200")
|
779
927
|
end
|
780
928
|
|
929
|
+
#
|
930
|
+
# test adjustment of scale which is used as preparation for division
|
931
|
+
#
|
781
932
|
def test_anti_equalize_scale
|
782
933
|
x = LongDecimal(20, 3)
|
783
934
|
y = LongDecimal(10, 1)
|
@@ -788,6 +939,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
788
939
|
assert_equal(1000, v.int_val, "int_val must be 1000")
|
789
940
|
end
|
790
941
|
|
942
|
+
#
|
943
|
+
# test unary minus operation (negation)
|
944
|
+
#
|
791
945
|
def test_negation
|
792
946
|
x = LongDecimal(0, 5)
|
793
947
|
assert_equal(-x, x, "x and -x are equal for negative x=#{x.inspect}")
|
@@ -798,6 +952,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
798
952
|
assert_equal(-224, y.int_val, "int_val of y must be -224 y=#{y.inspect}")
|
799
953
|
end
|
800
954
|
|
955
|
+
#
|
956
|
+
# test addition of LongDecimal
|
957
|
+
#
|
801
958
|
def test_add
|
802
959
|
x = LongDecimal(224, 2)
|
803
960
|
|
@@ -856,6 +1013,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
856
1013
|
assert_equal(zz, z, "z=#{z.inspect}")
|
857
1014
|
end
|
858
1015
|
|
1016
|
+
#
|
1017
|
+
# test subtraction of LongDecimal
|
1018
|
+
#
|
859
1019
|
def test_sub
|
860
1020
|
x = LongDecimal(224, 2)
|
861
1021
|
|
@@ -920,6 +1080,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
920
1080
|
assert_equal(zz, z, "z=#{z.inspect}")
|
921
1081
|
end
|
922
1082
|
|
1083
|
+
#
|
1084
|
+
# test multiplication of LongDecimal
|
1085
|
+
#
|
923
1086
|
def test_mul
|
924
1087
|
x = LongDecimal(224, 2)
|
925
1088
|
|
@@ -978,6 +1141,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
978
1141
|
assert((zz-z).abs < 1e-9, "z=#{z.inspect}")
|
979
1142
|
end
|
980
1143
|
|
1144
|
+
#
|
1145
|
+
# test division of LongDecimal
|
1146
|
+
#
|
981
1147
|
def test_div
|
982
1148
|
x = LongDecimal(224, 2)
|
983
1149
|
|
@@ -1042,6 +1208,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1042
1208
|
assert((zz-z).abs < 1e-9, "z=#{z.inspect}")
|
1043
1209
|
end
|
1044
1210
|
|
1211
|
+
#
|
1212
|
+
# test power (**) of LongDecimal
|
1213
|
+
#
|
1045
1214
|
def test_pow
|
1046
1215
|
|
1047
1216
|
x = LongDecimal(224, 2)
|
@@ -1101,6 +1270,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1101
1270
|
assert((zz-z).abs < 1e-9, "z=#{z.inspect}")
|
1102
1271
|
end
|
1103
1272
|
|
1273
|
+
#
|
1274
|
+
# test division with remainder of LongDecimal
|
1275
|
+
#
|
1104
1276
|
def test_divmod
|
1105
1277
|
x = LongDecimal(224, 2)
|
1106
1278
|
|
@@ -1183,6 +1355,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1183
1355
|
end
|
1184
1356
|
end
|
1185
1357
|
|
1358
|
+
#
|
1359
|
+
# test absolute value of LongDecimal
|
1360
|
+
#
|
1186
1361
|
def test_abs
|
1187
1362
|
x = LongDecimal(-224, 2)
|
1188
1363
|
y = x.abs
|
@@ -1195,6 +1370,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1195
1370
|
assert_equal(x, y, "abs of zero")
|
1196
1371
|
end
|
1197
1372
|
|
1373
|
+
#
|
1374
|
+
# test moving of decimal point of LongDecimal
|
1375
|
+
#
|
1198
1376
|
def test_move_point
|
1199
1377
|
x = LongDecimal(224, 2)
|
1200
1378
|
|
@@ -1228,6 +1406,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1228
1406
|
assert_equal(z, y, "2240")
|
1229
1407
|
end
|
1230
1408
|
|
1409
|
+
#
|
1410
|
+
# test ufo-operator (<=>) of LongDecimal
|
1411
|
+
#
|
1231
1412
|
def test_ufo
|
1232
1413
|
x = LongDecimal(224, 2)
|
1233
1414
|
|
@@ -1281,6 +1462,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1281
1462
|
|
1282
1463
|
end
|
1283
1464
|
|
1465
|
+
#
|
1466
|
+
# test sign-method of LongDecimal
|
1467
|
+
#
|
1284
1468
|
def test_sgn
|
1285
1469
|
x = LongDecimal(0, 5)
|
1286
1470
|
s = x.sgn
|
@@ -1293,6 +1477,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1293
1477
|
assert_equal(-1, s, "must be -1")
|
1294
1478
|
end
|
1295
1479
|
|
1480
|
+
#
|
1481
|
+
# test equality-comparison (==) of LongDecimal
|
1482
|
+
#
|
1296
1483
|
def test_equal
|
1297
1484
|
x = LongDecimal(224, 2)
|
1298
1485
|
y = LongDecimal(2240, 3)
|
@@ -1303,6 +1490,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1303
1490
|
assert_equal(y, y, "y equals y")
|
1304
1491
|
end
|
1305
1492
|
|
1493
|
+
#
|
1494
|
+
# test construction of LongDecimalQuot from LongDecimal
|
1495
|
+
#
|
1306
1496
|
def test_ldq_ld_init
|
1307
1497
|
x = LongDecimal(224, 2)
|
1308
1498
|
y = LongDecimal(225, 3)
|
@@ -1311,6 +1501,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1311
1501
|
assert_equal(zz, z, "224/225")
|
1312
1502
|
end
|
1313
1503
|
|
1504
|
+
#
|
1505
|
+
# test rounding of LongDecimalQuot with ROUND_UP
|
1506
|
+
#
|
1314
1507
|
def test_ldq_round_to_scale_up
|
1315
1508
|
|
1316
1509
|
# 0.99555555555555...
|
@@ -1344,6 +1537,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1344
1537
|
assert_equal("1.0000", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
|
1345
1538
|
end
|
1346
1539
|
|
1540
|
+
#
|
1541
|
+
# test rounding of LongDecimalQuot with ROUND_DOWN
|
1542
|
+
#
|
1347
1543
|
def test_ldq_round_to_scale_down
|
1348
1544
|
|
1349
1545
|
# 0.99555555555555...
|
@@ -1377,6 +1573,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1377
1573
|
assert_equal("1.0000", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
|
1378
1574
|
end
|
1379
1575
|
|
1576
|
+
#
|
1577
|
+
# test rounding of LongDecimalQuot with ROUND_CEILING
|
1578
|
+
#
|
1380
1579
|
def test_ldq_round_to_scale_ceiling
|
1381
1580
|
|
1382
1581
|
# 0.99555555555555...
|
@@ -1409,6 +1608,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1409
1608
|
assert_equal("1.0000", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
|
1410
1609
|
end
|
1411
1610
|
|
1611
|
+
#
|
1612
|
+
# test rounding of LongDecimalQuot with ROUND_FLOOR
|
1613
|
+
#
|
1412
1614
|
def test_ldq_round_to_scale_floor
|
1413
1615
|
|
1414
1616
|
# 0.99555555555555...
|
@@ -1441,6 +1643,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1441
1643
|
assert_equal("1.0000", r.to_s, "l=#{l.inspect} r=#{r.inspect}")
|
1442
1644
|
end
|
1443
1645
|
|
1646
|
+
#
|
1647
|
+
# test rounding of LongDecimalQuot with ROUND_HALF_UP
|
1648
|
+
#
|
1444
1649
|
def test_ldq_round_to_scale_half_up
|
1445
1650
|
|
1446
1651
|
# 0.99555555555555...
|
@@ -1479,6 +1684,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1479
1684
|
assert_equal("225/4[0]", l.to_s, "l=#{l.inspect} r=#{r.inspect}")
|
1480
1685
|
end
|
1481
1686
|
|
1687
|
+
#
|
1688
|
+
# test rounding of LongDecimalQuot with ROUND_HALF_DOWN
|
1689
|
+
#
|
1482
1690
|
def test_ldq_round_to_scale_half_down
|
1483
1691
|
|
1484
1692
|
# 0.99555555555555...
|
@@ -1517,6 +1725,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1517
1725
|
assert_equal("225/4[0]", l.to_s, "l=#{l.inspect} r=#{r.inspect}")
|
1518
1726
|
end
|
1519
1727
|
|
1728
|
+
#
|
1729
|
+
# test rounding of LongDecimalQuot with ROUND_HALF_EVEN
|
1730
|
+
#
|
1520
1731
|
def test_ldq_round_to_scale_half_even
|
1521
1732
|
|
1522
1733
|
# 0.99555555555555...
|
@@ -1561,6 +1772,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1561
1772
|
assert_equal("227/4[0]", l.to_s, "l=#{l.inspect} r=#{r.inspect}")
|
1562
1773
|
end
|
1563
1774
|
|
1775
|
+
#
|
1776
|
+
# test rounding of LongDecimalQuot with ROUND_UNNECESSARY
|
1777
|
+
#
|
1564
1778
|
def test_ldq_round_to_scale_unnecessary
|
1565
1779
|
l = LongDecimalQuot(Rational(225, 4), 5)
|
1566
1780
|
r = l.round_to_scale(2, LongDecimal::ROUND_UNNECESSARY)
|
@@ -1573,6 +1787,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1573
1787
|
end
|
1574
1788
|
end
|
1575
1789
|
|
1790
|
+
#
|
1791
|
+
# test conversion of LongDecimalQuot to String
|
1792
|
+
#
|
1576
1793
|
def test_ldq_to_s
|
1577
1794
|
l = LongDecimalQuot(Rational(224, 225), 226)
|
1578
1795
|
assert_equal("224/225[226]", l.to_s, "l=#{l.inspect}")
|
@@ -1580,6 +1797,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1580
1797
|
assert_equal("-224/225[226]", l.to_s, "l=#{l.inspect}")
|
1581
1798
|
end
|
1582
1799
|
|
1800
|
+
#
|
1801
|
+
# test conversion of LongDecimalQuot to Rational
|
1802
|
+
#
|
1583
1803
|
def test_ldq_to_r
|
1584
1804
|
rr = Rational(224, 225)
|
1585
1805
|
l = LongDecimalQuot(rr, 22)
|
@@ -1598,6 +1818,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1598
1818
|
assert_equal(rr, r, "must be equal")
|
1599
1819
|
end
|
1600
1820
|
|
1821
|
+
#
|
1822
|
+
# test conversion of LongDecimalQuot to Float
|
1823
|
+
#
|
1601
1824
|
def test_ldq_to_f
|
1602
1825
|
rr = Rational(224, 225)
|
1603
1826
|
l = LongDecimalQuot(rr, 22)
|
@@ -1621,6 +1844,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1621
1844
|
|
1622
1845
|
# to_i not tested, goes via to_r anyway
|
1623
1846
|
|
1847
|
+
#
|
1848
|
+
# test negation operator (unary -) of LongDecimalQuot
|
1849
|
+
#
|
1624
1850
|
def test_ldq_negation
|
1625
1851
|
x = LongDecimalQuot(Rational(0, 2), 3)
|
1626
1852
|
assert_equal(-x, x, "x and -x are equal for negative x=#{x.inspect}")
|
@@ -1632,6 +1858,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1632
1858
|
assert_equal(yy, y, "yy and y must be equal")
|
1633
1859
|
end
|
1634
1860
|
|
1861
|
+
#
|
1862
|
+
# test addition operator (binary +) of LongDecimalQuot
|
1863
|
+
#
|
1635
1864
|
def test_ldq_add
|
1636
1865
|
x = LongDecimalQuot(Rational(224, 225), 226)
|
1637
1866
|
|
@@ -1692,6 +1921,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1692
1921
|
assert((zz-z).abs < 1e-9, "z=#{z.inspect}")
|
1693
1922
|
end
|
1694
1923
|
|
1924
|
+
#
|
1925
|
+
# test subtraction operator (binary -) of LongDecimalQuot
|
1926
|
+
#
|
1695
1927
|
def test_ldq_sub
|
1696
1928
|
x = LongDecimalQuot(Rational(224, 225), 226)
|
1697
1929
|
|
@@ -1756,6 +1988,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1756
1988
|
assert((zz-z).abs < 1e-9, "z=#{z.inspect} zz=#{zz.inspect}")
|
1757
1989
|
end
|
1758
1990
|
|
1991
|
+
#
|
1992
|
+
# test multiplication operator (*) of LongDecimalQuot
|
1993
|
+
#
|
1759
1994
|
def test_ldq_mul
|
1760
1995
|
x = LongDecimalQuot(Rational(224, 225), 226)
|
1761
1996
|
|
@@ -1814,6 +2049,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1814
2049
|
assert((zz-z).abs < 1e-9, "z=#{z.inspect} zz=#{zz.inspect}")
|
1815
2050
|
end
|
1816
2051
|
|
2052
|
+
#
|
2053
|
+
# test division operator (/) of LongDecimalQuot
|
2054
|
+
#
|
1817
2055
|
def test_ldq_div
|
1818
2056
|
x = LongDecimalQuot(Rational(224, 225), 226)
|
1819
2057
|
|
@@ -1878,6 +2116,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1878
2116
|
assert((zz-z).abs < 1e-9, "z=#{z.inspect} zz=#{zz.inspect}")
|
1879
2117
|
end
|
1880
2118
|
|
2119
|
+
#
|
2120
|
+
# test power operator (**) of LongDecimalQuot
|
2121
|
+
#
|
1881
2122
|
def test_ldq_pow
|
1882
2123
|
|
1883
2124
|
x = LongDecimalQuot(Rational(224, 225), 226)
|
@@ -1937,6 +2178,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
1937
2178
|
assert((zz-z).abs < 1e-9, "z=#{z.inspect}")
|
1938
2179
|
end
|
1939
2180
|
|
2181
|
+
#
|
2182
|
+
# test divmod of LongDecimalQuot for division with remainder
|
2183
|
+
#
|
1940
2184
|
def test_ldq_divmod
|
1941
2185
|
x = LongDecimalQuot(Rational(224, 225), 226)
|
1942
2186
|
|
@@ -2019,6 +2263,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
2019
2263
|
end
|
2020
2264
|
end
|
2021
2265
|
|
2266
|
+
#
|
2267
|
+
# test absolute value of LongDecimalQuot
|
2268
|
+
#
|
2022
2269
|
def test_ldq_abs
|
2023
2270
|
x = LongDecimalQuot(Rational(-224, 225), 226)
|
2024
2271
|
y = x.abs
|
@@ -2031,6 +2278,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
2031
2278
|
assert_equal(x, y, "abs of zero")
|
2032
2279
|
end
|
2033
2280
|
|
2281
|
+
#
|
2282
|
+
# test ufo operator (<=>) of LongDecimalQuot
|
2283
|
+
#
|
2034
2284
|
def test_ldq_ufo
|
2035
2285
|
x = LongDecimalQuot(Rational(224, 225), 226)
|
2036
2286
|
|
@@ -2084,6 +2334,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
2084
2334
|
|
2085
2335
|
end
|
2086
2336
|
|
2337
|
+
#
|
2338
|
+
# test sign method of LongDecimalQuot
|
2339
|
+
#
|
2087
2340
|
def test_ldq_sgn
|
2088
2341
|
x = LongDecimalQuot(Rational(0, 5), 1000)
|
2089
2342
|
s = x.sgn
|
@@ -2096,6 +2349,9 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
2096
2349
|
assert_equal(-1, s, "must be -1")
|
2097
2350
|
end
|
2098
2351
|
|
2352
|
+
#
|
2353
|
+
# test equality operator (==) of LongDecimalQuot
|
2354
|
+
#
|
2099
2355
|
def test_ldq_equal
|
2100
2356
|
x = LongDecimalQuot(Rational(224, 225), 226)
|
2101
2357
|
y = LongDecimalQuot(Rational(224, 225), 227)
|