long-decimal 0.01.01 → 0.01.02
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 +17 -94
- data/VERSION +1 -1
- data/doc/classes/Integer.html +239 -0
- data/doc/classes/Integer.src/M000036.html +18 -0
- data/doc/classes/Integer.src/M000039.html +145 -0
- data/doc/classes/LongDecimal.html +453 -399
- data/doc/classes/LongDecimal.src/M000040.html +4 -4
- data/doc/classes/LongDecimal.src/M000041.html +4 -4
- data/doc/classes/LongDecimal.src/M000042.html +4 -6
- data/doc/classes/LongDecimal.src/M000043.html +4 -106
- data/doc/classes/LongDecimal.src/M000044.html +4 -21
- data/doc/classes/LongDecimal.src/M000045.html +4 -11
- data/doc/classes/LongDecimal.src/M000046.html +6 -27
- data/doc/classes/LongDecimal.src/M000047.html +103 -16
- data/doc/classes/LongDecimal.src/M000048.html +21 -4
- data/doc/classes/LongDecimal.src/M000049.html +10 -14
- data/doc/classes/LongDecimal.src/M000050.html +22 -36
- data/doc/classes/LongDecimal.src/M000051.html +34 -4
- data/doc/classes/LongDecimal.src/M000052.html +17 -6
- data/doc/classes/LongDecimal.src/M000053.html +4 -6
- data/doc/classes/LongDecimal.src/M000054.html +15 -4
- data/doc/classes/LongDecimal.src/M000055.html +44 -12
- data/doc/classes/LongDecimal.src/M000056.html +4 -7
- data/doc/classes/LongDecimal.src/M000057.html +8 -4
- data/doc/classes/LongDecimal.src/M000058.html +6 -15
- data/doc/classes/LongDecimal.src/M000059.html +4 -13
- data/doc/classes/LongDecimal.src/M000060.html +15 -4
- data/doc/classes/LongDecimal.src/M000061.html +7 -5
- data/doc/classes/LongDecimal.src/M000062.html +4 -4
- data/doc/classes/LongDecimal.src/M000063.html +15 -5
- data/doc/classes/LongDecimal.src/M000064.html +13 -5
- data/doc/classes/LongDecimal.src/M000065.html +4 -4
- data/doc/classes/LongDecimal.src/M000067.html +4 -8
- data/doc/classes/LongDecimal.src/M000068.html +5 -9
- data/doc/classes/LongDecimal.src/M000069.html +5 -9
- data/doc/classes/LongDecimal.src/M000070.html +4 -9
- data/doc/classes/LongDecimal.src/M000071.html +4 -4
- data/doc/classes/LongDecimal.src/M000072.html +6 -17
- data/doc/classes/LongDecimal.src/M000073.html +7 -7
- data/doc/classes/LongDecimal.src/M000074.html +7 -7
- data/doc/classes/LongDecimal.src/M000075.html +7 -19
- data/doc/classes/LongDecimal.src/M000076.html +4 -8
- data/doc/classes/LongDecimal.src/M000077.html +19 -5
- data/doc/classes/LongDecimal.src/M000078.html +7 -7
- data/doc/classes/LongDecimal.src/M000079.html +7 -7
- data/doc/classes/LongDecimal.src/M000080.html +19 -7
- data/doc/classes/LongDecimal.src/M000081.html +8 -4
- data/doc/classes/LongDecimal.src/M000082.html +5 -7
- data/doc/classes/LongDecimal.src/M000083.html +8 -6
- data/doc/classes/LongDecimal.src/M000084.html +9 -4
- data/doc/classes/LongDecimal.src/M000085.html +9 -4
- data/doc/classes/LongDecimal.src/M000086.html +4 -9
- data/doc/classes/LongDecimal.src/M000087.html +6 -8
- data/doc/classes/LongDecimal.src/M000088.html +7 -5
- data/doc/classes/LongDecimal.src/M000089.html +4 -9
- data/doc/classes/LongDecimal.src/M000090.html +4 -4
- data/doc/classes/LongDecimal.src/M000091.html +9 -4
- data/doc/classes/LongDecimal.src/M000092.html +9 -4
- data/doc/classes/LongDecimal.src/M000093.html +5 -4
- data/doc/classes/LongDecimal.src/M000094.html +7 -57
- data/doc/classes/LongDecimal.src/M000095.html +4 -4
- data/doc/classes/LongDecimal.src/M000096.html +4 -4
- data/doc/classes/LongDecimal.src/M000097.html +4 -5
- data/doc/classes/LongDecimal.src/M000098.html +4 -5
- data/doc/classes/LongDecimal.src/M000099.html +59 -5
- data/doc/classes/LongDecimal.src/M000100.html +4 -5
- data/doc/classes/LongDecimal.src/M000101.html +4 -4
- data/doc/classes/LongDecimal.src/M000104.html +19 -0
- data/doc/classes/LongDecimal.src/M000105.html +19 -0
- data/doc/classes/LongDecimal.src/M000106.html +18 -0
- data/doc/classes/LongDecimal.src/M000107.html +18 -0
- data/doc/classes/LongDecimal.src/M000108.html +18 -0
- data/doc/classes/LongDecimal.src/M000109.html +18 -0
- data/doc/classes/LongDecimalBase.html +69 -66
- data/doc/classes/LongDecimalBase.src/M000113.html +4 -9
- data/doc/classes/LongDecimalBase.src/M000114.html +4 -5
- data/doc/classes/LongDecimalBase.src/M000115.html +4 -9
- data/doc/classes/LongDecimalBase.src/M000116.html +4 -9
- data/doc/classes/LongDecimalBase.src/M000117.html +4 -5
- data/doc/classes/LongDecimalBase.src/M000118.html +23 -0
- data/doc/classes/LongDecimalBase.src/M000121.html +23 -0
- data/doc/classes/LongDecimalBase.src/M000122.html +19 -0
- data/doc/classes/LongDecimalBase.src/M000123.html +18 -0
- data/doc/classes/LongDecimalQuot.html +33 -27
- data/doc/classes/LongDecimalQuot.src/M000003.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000004.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000005.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000006.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000007.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000008.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000009.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000010.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000011.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000012.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000013.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000014.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000015.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000016.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000017.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000018.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000019.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000020.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000021.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000022.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000023.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000024.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000025.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000026.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000027.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000028.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000029.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000030.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000031.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000034.html +1 -1
- data/doc/classes/LongDecimalQuot.src/M000035.html +1 -1
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.html +25 -24
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000156.html +22 -0
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000157.html +18 -0
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000158.html +18 -0
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000159.html +18 -0
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000161.html +25 -0
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000162.html +18 -0
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000163.html +18 -0
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000164.html +18 -0
- data/doc/classes/LongDecimalRoundingMode/ZeroRoundingModeClass.html +178 -0
- data/doc/classes/LongDecimalRoundingMode/ZeroRoundingModeClass.src/M000165.html +25 -0
- data/doc/classes/LongDecimalRoundingMode/ZeroRoundingModeClass.src/M000166.html +18 -0
- data/doc/classes/LongDecimalRoundingMode.html +41 -4
- data/doc/classes/LongMath/CacheKey.html +10 -10
- data/doc/classes/LongMath/CacheKey.src/M000155.html +36 -0
- data/doc/classes/LongMath/CacheKey.src/M000160.html +36 -0
- data/doc/classes/LongMath.html +246 -235
- data/doc/classes/LongMath.src/M000124.html +5 -18
- data/doc/classes/LongMath.src/M000125.html +4 -18
- data/doc/classes/LongMath.src/M000126.html +4 -5
- data/doc/classes/LongMath.src/M000127.html +5 -29
- data/doc/classes/LongMath.src/M000128.html +4 -5
- data/doc/classes/LongMath.src/M000129.html +14 -53
- data/doc/classes/LongMath.src/M000130.html +17 -20
- data/doc/classes/LongMath.src/M000131.html +5 -36
- data/doc/classes/LongMath.src/M000132.html +29 -6
- data/doc/classes/LongMath.src/M000133.html +5 -33
- data/doc/classes/LongMath.src/M000134.html +47 -41
- data/doc/classes/LongMath.src/M000135.html +21 -7
- data/doc/classes/LongMath.src/M000136.html +36 -4
- data/doc/classes/LongMath.src/M000137.html +6 -4
- data/doc/classes/LongMath.src/M000138.html +31 -70
- data/doc/classes/LongMath.src/M000139.html +45 -38
- data/doc/classes/LongMath.src/M000140.html +7 -4
- data/doc/classes/LongMath.src/M000141.html +4 -4
- data/doc/classes/LongMath.src/M000142.html +4 -6
- data/doc/classes/LongMath.src/M000143.html +67 -14
- data/doc/classes/LongMath.src/M000144.html +39 -14
- data/doc/classes/LongMath.src/M000145.html +4 -44
- data/doc/classes/LongMath.src/M000146.html +5 -339
- data/doc/classes/LongMath.src/M000147.html +6 -25
- data/doc/classes/LongMath.src/M000148.html +14 -75
- data/doc/classes/LongMath.src/M000149.html +33 -0
- data/doc/classes/LongMath.src/M000150.html +58 -0
- data/doc/classes/LongMath.src/M000151.html +406 -0
- data/doc/classes/LongMath.src/M000152.html +63 -0
- data/doc/classes/LongMath.src/M000153.html +117 -0
- data/doc/classes/LongMath.src/M000154.html +150 -0
- data/doc/classes/LongMath.src/M000155.html +63 -0
- data/doc/classes/LongMath.src/M000156.html +18 -0
- data/doc/classes/LongMath.src/M000157.html +19 -0
- data/doc/classes/LongMath.src/M000158.html +18 -0
- data/doc/classes/LongMath.src/M000159.html +19 -0
- data/doc/classes/Numeric.html +23 -21
- data/doc/classes/Numeric.src/M000106.html +18 -0
- data/doc/classes/Numeric.src/M000110.html +23 -0
- data/doc/classes/Numeric.src/M000111.html +18 -0
- data/doc/classes/Rational.html +18 -16
- data/doc/classes/Rational.src/M000107.html +23 -0
- data/doc/classes/Rational.src/M000112.html +23 -0
- data/doc/created.rid +1 -1
- data/doc/dot/f_0.dot +23 -1
- data/doc/dot/f_0.png +0 -0
- data/doc/dot/m_0_0.png +0 -0
- data/doc/dot/m_0_1.dot +13 -0
- data/doc/dot/m_0_1.png +0 -0
- data/doc/files/lib/long-decimal_rb.html +15 -13
- data/doc/files/lib/long-decimal_rb.src/M000001.html +1 -1
- data/doc/files/lib/long-decimal_rb.src/M000002.html +1 -1
- data/doc/fr_class_index.html +2 -0
- data/doc/fr_method_index.html +131 -124
- data/lib/long-decimal.rb +373 -49
- data/test/testlongdecimal.rb +689 -7
- data/test/testlongdeclib.rb +51 -11
- data/test/testrandlib.rb +23 -7
- data/test/testrandom.rb +4 -4
- data/test/testrandpower.rb +11 -9
- metadata +48 -3
data/test/testlongdecimal.rb
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
#
|
|
3
3
|
# testlongdecimal.rb -- runit test for long-decimal.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.62 2007/07/11 21:22:21 bk1 Exp $
|
|
6
|
+
# CVS-Label: $Name: ALPHA_01_02 $
|
|
7
7
|
# Author: $Author: bk1 $ (Karl Brodowsky)
|
|
8
8
|
#
|
|
9
9
|
|
|
@@ -20,7 +20,7 @@ load "test/testlongdeclib.rb"
|
|
|
20
20
|
class TestLongDecimal_class < RUNIT::TestCase
|
|
21
21
|
include TestLongDecHelper
|
|
22
22
|
|
|
23
|
-
@RCS_ID='-$Id: testlongdecimal.rb,v 1.
|
|
23
|
+
@RCS_ID='-$Id: testlongdecimal.rb,v 1.62 2007/07/11 21:22:21 bk1 Exp $-'
|
|
24
24
|
|
|
25
25
|
#
|
|
26
26
|
# test split_to_words and merge_from_words
|
|
@@ -95,6 +95,23 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
|
95
95
|
check_exp_floated(LongDecimal("0.000000000000000000000000000000000000000000000000695000000000000000000000000000042500000000000000552"), 50)
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
+
#
|
|
99
|
+
# test the calculation of the exponential function where result is
|
|
100
|
+
# near zero
|
|
101
|
+
#
|
|
102
|
+
def test_exp_near_zero
|
|
103
|
+
|
|
104
|
+
x = LongDecimal(1, 100)
|
|
105
|
+
y = LongMath.log(x, 100)
|
|
106
|
+
z = check_exp_floated(y, 100)
|
|
107
|
+
assert_equal(x, z, "must be equal")
|
|
108
|
+
z = check_exp_floated(y, 99)
|
|
109
|
+
assert(z.zero?, "must be zero")
|
|
110
|
+
z = check_exp_floated(y * 100, 99)
|
|
111
|
+
assert(z.zero?, "must be zero")
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
98
115
|
#
|
|
99
116
|
# test the calculation of the exponential function with precision 0
|
|
100
117
|
#
|
|
@@ -155,6 +172,23 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
|
155
172
|
|
|
156
173
|
end
|
|
157
174
|
|
|
175
|
+
#
|
|
176
|
+
# test the calculation of the exponential function where result is
|
|
177
|
+
# near zero
|
|
178
|
+
#
|
|
179
|
+
def test_exp2_near_zero
|
|
180
|
+
|
|
181
|
+
x = LongDecimal(1, 100)
|
|
182
|
+
y = LongMath.log2(x, 100)
|
|
183
|
+
z = check_exp2_floated(y, 100)
|
|
184
|
+
assert_equal(x, z, "must be equal")
|
|
185
|
+
z = check_exp2_floated(y, 99)
|
|
186
|
+
assert(z.zero?, "must be zero")
|
|
187
|
+
z = check_exp2_floated(y * 100, 99)
|
|
188
|
+
assert(z.zero?, "must be zero")
|
|
189
|
+
|
|
190
|
+
end
|
|
191
|
+
|
|
158
192
|
#
|
|
159
193
|
# test exp10 of LongMath
|
|
160
194
|
#
|
|
@@ -172,6 +206,23 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
|
172
206
|
end
|
|
173
207
|
end
|
|
174
208
|
|
|
209
|
+
#
|
|
210
|
+
# test the calculation of the exponential function where result is
|
|
211
|
+
# near zero
|
|
212
|
+
#
|
|
213
|
+
def test_exp10_near_zero
|
|
214
|
+
|
|
215
|
+
x = LongDecimal(1, 100)
|
|
216
|
+
y = LongMath.log10(x, 100)
|
|
217
|
+
z = check_exp10_floated(y, 100)
|
|
218
|
+
assert_equal(x, z, "must be equal")
|
|
219
|
+
z = check_exp10_floated(y, 99)
|
|
220
|
+
assert(z.zero?, "must be zero")
|
|
221
|
+
z = check_exp10_floated(y * 100, 99)
|
|
222
|
+
assert(z.zero?, "must be zero")
|
|
223
|
+
|
|
224
|
+
end
|
|
225
|
+
|
|
175
226
|
#
|
|
176
227
|
# test LongMath.power for bases that can be expressed as integer
|
|
177
228
|
#
|
|
@@ -350,6 +401,77 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
|
350
401
|
|
|
351
402
|
end
|
|
352
403
|
|
|
404
|
+
#
|
|
405
|
+
# test LongMath.power for bases that can be expressed as integer
|
|
406
|
+
#
|
|
407
|
+
def test_lm_power_yhalfint
|
|
408
|
+
|
|
409
|
+
xx = LongMath.log(3, 40)
|
|
410
|
+
pi = LongMath.pi(40)
|
|
411
|
+
sq = LongMath.sqrt(5, 40)
|
|
412
|
+
|
|
413
|
+
check_power_yhalfint(xx, 801, 10)
|
|
414
|
+
check_power_yhalfint(xx, 799, 10)
|
|
415
|
+
check_power_yhalfint(xx, 201, 10)
|
|
416
|
+
check_power_yhalfint(xx, 3, 10)
|
|
417
|
+
check_power_yhalfint(xx, 1, 10)
|
|
418
|
+
check_power_yhalfint(xx, -1, 10)
|
|
419
|
+
check_power_yhalfint(xx, -201, 10)
|
|
420
|
+
check_power_yhalfint(xx, -799, 10)
|
|
421
|
+
check_power_yhalfint(xx, -801, 10)
|
|
422
|
+
|
|
423
|
+
check_power_yhalfint(pi, 801, 10)
|
|
424
|
+
check_power_yhalfint(pi, 799, 10)
|
|
425
|
+
check_power_yhalfint(pi, 201, 10)
|
|
426
|
+
check_power_yhalfint(pi, 3, 10)
|
|
427
|
+
check_power_yhalfint(pi, 1, 10)
|
|
428
|
+
check_power_yhalfint(pi, -1, 10)
|
|
429
|
+
check_power_yhalfint(pi, -201, 10)
|
|
430
|
+
check_power_yhalfint(pi, -799, 10)
|
|
431
|
+
check_power_yhalfint(pi, -801, 10)
|
|
432
|
+
|
|
433
|
+
check_power_yhalfint(sq, 801, 10)
|
|
434
|
+
check_power_yhalfint(sq, 799, 10)
|
|
435
|
+
check_power_yhalfint(sq, 201, 10)
|
|
436
|
+
check_power_yhalfint(sq, 3, 10)
|
|
437
|
+
check_power_yhalfint(sq, 1, 10)
|
|
438
|
+
check_power_yhalfint(sq, -1, 10)
|
|
439
|
+
check_power_yhalfint(sq, -201, 10)
|
|
440
|
+
check_power_yhalfint(sq, -799, 10)
|
|
441
|
+
check_power_yhalfint(sq, -801, 10)
|
|
442
|
+
|
|
443
|
+
check_power_yhalfint(xx, 801, 40)
|
|
444
|
+
check_power_yhalfint(xx, 799, 40)
|
|
445
|
+
check_power_yhalfint(xx, 201, 40)
|
|
446
|
+
check_power_yhalfint(xx, 3, 40)
|
|
447
|
+
check_power_yhalfint(xx, 1, 40)
|
|
448
|
+
check_power_yhalfint(xx, -1, 40)
|
|
449
|
+
check_power_yhalfint(xx, -201, 40)
|
|
450
|
+
check_power_yhalfint(xx, -799, 40)
|
|
451
|
+
check_power_yhalfint(xx, -801, 40)
|
|
452
|
+
|
|
453
|
+
check_power_yhalfint(pi, 801, 40)
|
|
454
|
+
check_power_yhalfint(pi, 799, 40)
|
|
455
|
+
check_power_yhalfint(pi, 201, 40)
|
|
456
|
+
check_power_yhalfint(pi, 3, 40)
|
|
457
|
+
check_power_yhalfint(pi, 1, 40)
|
|
458
|
+
check_power_yhalfint(pi, -1, 40)
|
|
459
|
+
check_power_yhalfint(pi, -201, 40)
|
|
460
|
+
check_power_yhalfint(pi, -799, 40)
|
|
461
|
+
check_power_yhalfint(pi, -801, 40)
|
|
462
|
+
|
|
463
|
+
check_power_yhalfint(sq, 801, 40)
|
|
464
|
+
check_power_yhalfint(sq, 799, 40)
|
|
465
|
+
check_power_yhalfint(sq, 201, 40)
|
|
466
|
+
check_power_yhalfint(sq, 3, 40)
|
|
467
|
+
check_power_yhalfint(sq, 1, 40)
|
|
468
|
+
check_power_yhalfint(sq, -1, 40)
|
|
469
|
+
check_power_yhalfint(sq, -201, 40)
|
|
470
|
+
check_power_yhalfint(sq, -799, 40)
|
|
471
|
+
check_power_yhalfint(sq, -801, 40)
|
|
472
|
+
|
|
473
|
+
end
|
|
474
|
+
|
|
353
475
|
#
|
|
354
476
|
# test LongMath.exp with non-LongDecimal arguments
|
|
355
477
|
#
|
|
@@ -490,6 +612,7 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
|
490
612
|
check_power_floated(1.01, 1e-20, 20)
|
|
491
613
|
check_power_floated(1e-20, 1.01, 21)
|
|
492
614
|
check_power_floated(1.01, 1e-20, 21)
|
|
615
|
+
puts "done (1.01, 1e-20, 21)"
|
|
493
616
|
|
|
494
617
|
check_power_floated(1.001, -1.001, 10)
|
|
495
618
|
check_power_floated(1.001, -2.001, 10)
|
|
@@ -503,95 +626,152 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
|
503
626
|
check_power_floated(1.01, -1e-20, 20)
|
|
504
627
|
check_power_floated(1e-20, -1.01, 21)
|
|
505
628
|
check_power_floated(1.01, -1e-20, 21)
|
|
629
|
+
puts "done (1.01, -1e-20, 21)"
|
|
506
630
|
|
|
507
631
|
# random tests that have failed
|
|
632
|
+
check_power_floated(LongDecimal("0.000000000077517987624900000000000000000000000000000000000000000000000000000000000000000000000000000014809051260000000000000000000000000000000000000000000000000000000000000000000000000000000000707281"),
|
|
633
|
+
LongDecimal("26.627053911388694974442854299008649887946027550330988420533923061901183724914978160564862753777080769340"),
|
|
634
|
+
29)
|
|
635
|
+
puts "a"
|
|
508
636
|
check_power_floated(LongDecimal("1.000000000000000151000000000000000000000000000000000000000000000000000000000000057800000000205"),
|
|
509
637
|
LongDecimal("-680.0000000000000000000013100000000000000000000000000000000000000165000000000000000000234"),
|
|
510
638
|
26)
|
|
639
|
+
puts "b"
|
|
511
640
|
check_power_floated(LongDecimal("1.0000000000000000000000000000000000000000000068000000000853000000000926"),
|
|
512
641
|
LongDecimal("-536.000000000086100000000000000000000000000019200000000000000000000000000000000000000000000000166"),
|
|
513
642
|
49)
|
|
643
|
+
puts "c"
|
|
514
644
|
check_power_floated(LongDecimal("1.0000000000000000049000000000002090000000000447"),
|
|
515
645
|
LongDecimal("-328.00000000000000000000000000000000567000000000000000026600000000000000000000000679"),
|
|
516
646
|
24)
|
|
647
|
+
puts "d"
|
|
517
648
|
check_power_floated(LongDecimal("1.0000000000000000000003580000000000000000000000376238"),
|
|
518
649
|
LongDecimal("-359.0000000003910721000000000000000000000000000000000000000000000000000000000000000000000000479"),
|
|
519
650
|
39)
|
|
651
|
+
puts "e"
|
|
520
652
|
check_power_floated(LongDecimal("1.000000000000000000000032000000001500000000000000000000439"),
|
|
521
653
|
LongDecimal("-252.00000000000000025500000000000176907"),
|
|
522
654
|
39)
|
|
655
|
+
puts "f"
|
|
523
656
|
check_power_floated(LongDecimal("1.0000000000000008590000521000000000000621"),
|
|
524
657
|
LongDecimal("-135.0000000000000000000000000000000000000000000000000000000074400000000000000000000000000321"),
|
|
525
658
|
50)
|
|
659
|
+
puts "g"
|
|
526
660
|
check_power_floated(LongDecimal("1.000000000000000151000000000000000000000000000000000000000000000000000000000000057800000000205"),
|
|
527
661
|
LongDecimal("-680.0000000000000000000013100000000000000000000000000000000000000165000000000000000000234"),
|
|
528
662
|
26)
|
|
663
|
+
puts "h"
|
|
529
664
|
check_power_floated(LongDecimal("1.02350000000000000000000356000000000000000000000000000000000000000000000000000000000104"),
|
|
530
665
|
LongDecimal("-971.0000000000000000055400000000000000000000000000000000000000000000000000040900000000000000000000000603"),
|
|
531
666
|
45)
|
|
667
|
+
puts "i"
|
|
532
668
|
check_power_floated(LongDecimal("1.0023800000000000000000000000000000000000000000000000000000000000265000000000000000000000000000000453"),
|
|
533
669
|
LongDecimal("-277.000000000000000000000000000000000000000000000000000000000000113000000000000000000041400000294"),
|
|
534
670
|
22)
|
|
671
|
+
puts "j"
|
|
535
672
|
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003422250001093950095910422515315300670761"),
|
|
536
673
|
LongDecimal("-0.99999999999999999999999999999999999999999999999999997909999999999999999999999999667999957000000000000000065521500000000000000000000020816402696099999999999997719321110428280027729999999129874367303020000000000071412895105695789681563000036363932570289984431712381817869482773696988055442648559706239710901091550702341077381290973316336980640165855210736680"),
|
|
537
674
|
46)
|
|
675
|
+
puts "k"
|
|
538
676
|
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000049273899694369"),
|
|
539
677
|
LongDecimal("-0.99999999999999999999999999999999999999988899963450000000000000000000000000000001847988671170038537499999999999999999999658146648184996349480690906250000000000066400422857493760370353798820585648437488207957808220483456569835670219978619056054192244103752969215743872596800486621906638928959243058783356441503226136251748249991020724187893339868"),
|
|
540
678
|
40)
|
|
679
|
+
puts "l"
|
|
541
680
|
check_power_floated(LongDecimal("0.0000000000000000000000000000003868840000000000000000000328416000000000000000000006969600000000000000000000000000000059338800000000000000000002518560000000000000000000000000000000000000000000000000000000227529"),
|
|
542
681
|
LongDecimal("-0.999999999999999999999999999999999999999999999999999998264999999999999999999999999999616741000000000000000004515337500000000000000000000001994863094999999999999986943149282831191620999999999993077825060350000000000033980453035745280148525000000024019946927993617107497210600671335038418031107762499920991889855598841096454678838495791189026426859181655270271342"),
|
|
543
682
|
31)
|
|
683
|
+
puts "m"
|
|
544
684
|
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000435600000000000000000000000000000000000000000000000006204000000075240000000000000000000000000000000000000022090000000535800000003249"),
|
|
545
685
|
LongDecimal("-4.50377349099168904759987513420506734335755704389619751192197520413005925604849718759451665302464588879636922713303481423460050066204079523260315868192642742903330525895063299416"),
|
|
546
686
|
20)
|
|
687
|
+
puts "n"
|
|
547
688
|
check_power_floated(LongDecimal("0.0000000000000000000000000000700720943029391693947940220429504569709269190190365416713568"),
|
|
548
689
|
LongDecimal("-6.633249580710799698229865473341373367854177091179010213018664944871230"),
|
|
549
690
|
7)
|
|
691
|
+
puts "o"
|
|
550
692
|
check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000816700000697"),
|
|
551
693
|
LongDecimal("-0.58685446009389671361502347417840375586854460093896713614906034406753510106019528753113359342280707917300359276157963863070992095386428055722936293804476401957909668625460628698383384886591034139"),
|
|
552
694
|
36)
|
|
695
|
+
puts "p"
|
|
553
696
|
check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
|
|
554
697
|
LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
|
|
555
698
|
3)
|
|
699
|
+
puts "q"
|
|
556
700
|
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000002450257484405715360000000000000000097614149083200000000000000000000000972196"),
|
|
557
701
|
LongDecimal("-1.00000008600000184900000000000000000000000000000000000000012640000543520000000000000000000013300000571900000000000000399424000000000000000000000000000840560000000000000000000000000000442225"),
|
|
558
702
|
3)
|
|
703
|
+
puts "r"
|
|
559
704
|
check_power_floated(LongDecimal("0.00000000000000000000000000000000000000000000000000000000000000000000367236000000000000000093202800000000000000005914074196000000000000000058905400000000000000000000146689"),
|
|
560
705
|
LongDecimal("-1.000000000008800000000019360000000062800000000276320250000000001100000985960000000000007850000000000000015625"),
|
|
561
706
|
4)
|
|
707
|
+
puts "s"
|
|
562
708
|
check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000000000000000000000000000002777290000000006513720000000003819240000000000000000000000000000100340800000000117667200000000000000000000000000000000000000000000906304"),
|
|
563
709
|
LongDecimal("-0.5773502691896257645091447198050641552797247036332110311421498194545129249630222981047763195372146430879281215100223411775138874331819083544781222838698051829302865547075365868655847179043571799566074987574406310154782766513220296853158689786573196010629608653145605201822170964422894732870490642190250948498852022304300879727510280657218553"),
|
|
564
710
|
23)
|
|
711
|
+
puts "s"
|
|
565
712
|
check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000007350000295000915"),
|
|
566
713
|
LongDecimal("-1.000002193000861"),
|
|
567
714
|
2)
|
|
715
|
+
puts "u"
|
|
568
716
|
check_power_floated(LongDecimal("0.0000000086862400000000000000015172960006039360000000662596000527472000104976"),
|
|
569
717
|
LongDecimal("-0.999999999999999999999999999999999999999999999999999999999997169999999999996784999999999687000000000000000000000000000012013350000000027295350000002672874337500003018885000000146896669625999999845508318999984783776699499965759759873248317316431267825611053489338193758007138415641516991908731376997678345955102618540146326218008264916981179817214058767402196571"),
|
|
570
718
|
11)
|
|
719
|
+
puts "v"
|
|
571
720
|
check_power_floated(LongDecimal("0.00000000000000000000000000624000383000000000000000000000000000000000000000000000358"),
|
|
572
721
|
LongDecimal("-1.0000004600000000000000000000000000000004210"),
|
|
573
722
|
3)
|
|
723
|
+
puts "w"
|
|
574
724
|
check_power_floated(LongDecimal("0.00000000006236994468492015585972291475115698519825552824875948893004062366348813472156776148562881057978611940708477498267201430163921921918813918304834563518614088250202460271818014152969"),
|
|
575
725
|
LongDecimal("-21.81742422927144044215775880732087497227530694228658299334049542576403906256739064739549866577137008231569804502022381108724983114382624747999460445291671084230968250529511708947428208082234"),
|
|
576
726
|
6)
|
|
727
|
+
puts "x"
|
|
577
728
|
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000035600000000928000000000000000450"),
|
|
578
729
|
LongDecimal("-0.70821529745042492917661444999959874487397062785764977666003279651340417551441776107007487983685090756343178115766012078677210548592741818458068450268168492334992979756923"),
|
|
579
730
|
13)
|
|
731
|
+
puts "y"
|
|
580
732
|
check_power_floated(LongDecimal("0.0000000000000000000000000000025900000000000000000000000000000000000000000022100000000000000000032"),
|
|
581
733
|
LongDecimal("-0.999943403203378688766215832183174473300891276419706031790088430934495839737458766990116492"),
|
|
582
734
|
4)
|
|
735
|
+
puts "z"
|
|
583
736
|
check_power_floated(LongDecimal("0.002658925294303146195800785280451092866235470739838791730450519159432915"),
|
|
584
737
|
LongDecimal("-87.0000000000000008330000000000000000000000000000000000000000000000000000000000000000000000000092046"),
|
|
585
738
|
90)
|
|
739
|
+
puts "a"
|
|
586
740
|
check_power_floated(LongDecimal("0.0014814814814814814812905349794238683127818125285779606767229367555739725854802645575188374989810195213530274617178142875856830586369415448003164084698537116523550097"),
|
|
587
741
|
LongDecimal("-52.0000000000000000000000000000000000000000683000000000000000000238000000000228"),
|
|
588
742
|
25)
|
|
743
|
+
puts "b"
|
|
589
744
|
check_power_floated(LongDecimal("0.00000000000000000000047400000000000000000084700000892"),
|
|
590
745
|
LongDecimal("-17.000000001310000000000000000000000000000000000000000000000000002800000000000000217"),
|
|
591
746
|
56)
|
|
747
|
+
puts "c"
|
|
592
748
|
check_power_floated(LongDecimal("0.00000000000000000000005110000000000000000004800000000000000000000000000000163"),
|
|
593
749
|
LongDecimal("-37.000000009170000000000000000000000000000000000000000000000000000000000000055800048"),
|
|
594
750
|
21)
|
|
751
|
+
puts "d"
|
|
752
|
+
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000002450257484405715360000000000000000097614149083200000000000000000000000972196"),
|
|
753
|
+
LongDecimal("-1.00000008600000184900000000000000000000000000000000000000012640000543520000000000000000000013300000571900000000000000399424000000000000000000000000000840560000000000000000000000000000442225"),
|
|
754
|
+
3)
|
|
755
|
+
puts "e"
|
|
756
|
+
check_power_floated(LongDecimal("0.999999999999983820000000000052544300000001372125483999980457478288050051600649560171986452284020178492146835403829341250837967306416835643061512149984415283328897050537606939603101940467080257495289168053434691062993302374332577706782680685214083677104079828206433042861334386773091111658939537092356816922764138900649581031721453211835260155666851398044388924204855221543729490461274063089475188763279119570"),
|
|
757
|
+
LongDecimal("80321932.89024988628926432624765785135567744505377819122460049392916097399960142838065367057138986526363804"),
|
|
758
|
+
40)
|
|
759
|
+
puts "f"
|
|
760
|
+
check_power_floated(LongDecimal("0.999999999999999999999999999999998351999999999999983020000000000002036927999998210041974559999999997978335404004424810825925120045592892314014072707890311225042124730264194167337496376801852022987153782535008598977724682635285958668331865904517437818865287190004735483899633845078360662820274644903126498781970492928578903950"),
|
|
761
|
+
LongDecimal("24449877750611246943765281173.594132029339853300733454400081300326994697544849684064538112517261374573394648075725881734888526076256999828217542217625441301525934675012853453406806380262764050867999"),
|
|
762
|
+
5)
|
|
763
|
+
puts "g"
|
|
764
|
+
check_power_floated(LongDecimal("0.999999999999999862599981980000014159073713922242243328677707050386499779178242565766291900177208859765599761583988066205590104341111429059119646260524293805643133602429678974677397380813589741657940554009198199034562447106122960905140273768835224006261013069576237942279008951360618433986"),
|
|
765
|
+
LongDecimal("10266940451745.37987679671457905534956086166404546967839388790271998098584221166751699838745542116653920000125768690393028114699714286512441385099525"),
|
|
766
|
+
14)
|
|
767
|
+
puts "h"
|
|
768
|
+
check_power_floated(LongDecimal("0.999999999999999981500000000000000256687499999999996834187500000000036604706930449997823687754750325053502286291757658419972795166437108241085949094447949893401640711985948839881287077716265593625727522425306777978451009970778400655052736724232660803755458234164496101454557290134193942433026948513566480800350007916601440691706219670728270104113540"),
|
|
769
|
+
LongDecimal("41380294430118397.455148144857963343847598908617723236165122243380531570432704458595232182042029429597565318650987561380534985825811466980798564531839364855305381553585381037046185516421336524897364607404185776449463"),
|
|
770
|
+
26)
|
|
771
|
+
puts "i"
|
|
772
|
+
check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
|
|
773
|
+
LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
|
|
774
|
+
23)
|
|
595
775
|
|
|
596
776
|
end
|
|
597
777
|
|
|
@@ -742,6 +922,8 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
|
742
922
|
assert_equal(l.round_to_scale(199, LongMath::ROUND_HALF_EVEN), pi, "199 digits")
|
|
743
923
|
pi = LongMath.pi 201
|
|
744
924
|
assert_equal(l.round_to_scale(201, LongMath::ROUND_HALF_EVEN), pi, "201 digits")
|
|
925
|
+
pi = LongMath.pi 1000
|
|
926
|
+
assert_equal(l.round_to_scale(1000, LongMath::ROUND_HALF_EVEN), pi, "1000 digits")
|
|
745
927
|
end
|
|
746
928
|
|
|
747
929
|
#
|
|
@@ -1224,12 +1406,12 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
|
1224
1406
|
10.times do |i|
|
|
1225
1407
|
n = i*i+i+1
|
|
1226
1408
|
while (n % 10) == 0 do
|
|
1227
|
-
|
|
1409
|
+
n /= 10
|
|
1228
1410
|
end
|
|
1229
1411
|
10.times do |j|
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1412
|
+
m = j*j
|
|
1413
|
+
x = n * 10**m
|
|
1414
|
+
assert_equal(m, LongMath.multiplicity_of_10(x), "x=#{x} i=#{i} j=#{j} n=#{n} m=#{m}")
|
|
1233
1415
|
end
|
|
1234
1416
|
end
|
|
1235
1417
|
end
|
|
@@ -1583,6 +1765,497 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
|
1583
1765
|
end
|
|
1584
1766
|
end
|
|
1585
1767
|
|
|
1768
|
+
#
|
|
1769
|
+
# test rounding of int to remainder set
|
|
1770
|
+
#
|
|
1771
|
+
def test_int_round_to_one_allowed_remainder
|
|
1772
|
+
2.upto 20 do |modulus|
|
|
1773
|
+
0.upto modulus-1 do |r|
|
|
1774
|
+
n = 3*modulus
|
|
1775
|
+
(-n).upto n do |i|
|
|
1776
|
+
text = "i=#{i} n=#{n} m=#{modulus} r=#{r}"
|
|
1777
|
+
|
|
1778
|
+
i_rounded = check_round_to_one_remainder(i, r, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1779
|
+
assert(i_rounded.abs >= i.abs, "i_r=#{i_rounded} " + text)
|
|
1780
|
+
if (i == 0) then
|
|
1781
|
+
assert(i_rounded >= 0, "i_r=#{i_rounded} " + text)
|
|
1782
|
+
end
|
|
1783
|
+
|
|
1784
|
+
i_rounded = check_round_to_one_remainder(i, r, modulus, LongDecimalRoundingMode::ROUND_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1785
|
+
if (i > 0)
|
|
1786
|
+
assert(i_rounded <= i, "i_r=#{i_rounded} " + text)
|
|
1787
|
+
elsif (i < 0)
|
|
1788
|
+
assert(i_rounded >= i, "i_r=#{i_rounded} " + text)
|
|
1789
|
+
elsif (i == 0) then
|
|
1790
|
+
assert(i_rounded >= 0, "i_r=#{i_rounded} " + text)
|
|
1791
|
+
else
|
|
1792
|
+
raise("i=#{i} i_r=#{i_rounded}")
|
|
1793
|
+
end
|
|
1794
|
+
|
|
1795
|
+
i_rounded = check_round_to_one_remainder(i, r, modulus, LongDecimalRoundingMode::ROUND_CEILING, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1796
|
+
assert(i_rounded >= i, "i_r=#{i_rounded} " + text)
|
|
1797
|
+
|
|
1798
|
+
i_rounded = check_round_to_one_remainder(i, r, modulus, LongDecimalRoundingMode::ROUND_FLOOR, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1799
|
+
assert(i_rounded <= i, "i_r=#{i_rounded} " + text)
|
|
1800
|
+
|
|
1801
|
+
i_rounded = check_round_to_one_remainder(i, r, modulus, LongDecimalRoundingMode::ROUND_HALF_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1802
|
+
dd = 2*(i_rounded - i).abs
|
|
1803
|
+
assert(dd <= modulus, "i_r=#{i_rounded} " + text)
|
|
1804
|
+
if (i_rounded.abs < i.abs || i_rounded.sgn == - i.sgn)
|
|
1805
|
+
assert(dd < modulus, "i_r=#{i_rounded} " + text)
|
|
1806
|
+
end
|
|
1807
|
+
|
|
1808
|
+
i_rounded = check_round_to_one_remainder(i, r, modulus, LongDecimalRoundingMode::ROUND_HALF_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1809
|
+
dd = 2*(i_rounded - i).abs
|
|
1810
|
+
assert(dd <= modulus, "i_r=#{i_rounded} " + text)
|
|
1811
|
+
if (i_rounded.abs > i.abs && i_rounded.sgn == i.sgn)
|
|
1812
|
+
assert(dd < modulus, "i_r=#{i_rounded} " + text)
|
|
1813
|
+
end
|
|
1814
|
+
|
|
1815
|
+
i_rounded = check_round_to_one_remainder(i, r, modulus, LongDecimalRoundingMode::ROUND_HALF_CEILING, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1816
|
+
dd = 2*(i_rounded - i).abs
|
|
1817
|
+
assert(dd <= modulus, "i_r=#{i_rounded} " + text)
|
|
1818
|
+
if (i_rounded < i)
|
|
1819
|
+
assert(dd < modulus, "i_r=#{i_rounded} " + text)
|
|
1820
|
+
end
|
|
1821
|
+
|
|
1822
|
+
i_rounded = check_round_to_one_remainder(i, r, modulus, LongDecimalRoundingMode::ROUND_HALF_FLOOR, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1823
|
+
dd = 2*(i_rounded - i).abs
|
|
1824
|
+
assert(dd <= modulus, "i_r=#{i_rounded} " + text)
|
|
1825
|
+
if (i_rounded > i && i != 0)
|
|
1826
|
+
assert(dd < modulus, "i_r=#{i_rounded} " + text)
|
|
1827
|
+
end
|
|
1828
|
+
end
|
|
1829
|
+
end
|
|
1830
|
+
end
|
|
1831
|
+
end
|
|
1832
|
+
|
|
1833
|
+
#
|
|
1834
|
+
# test rounding of int to remainder set
|
|
1835
|
+
#
|
|
1836
|
+
def test_zero_round_to_one_allowed_remainder
|
|
1837
|
+
2.upto 20 do |modulus|
|
|
1838
|
+
0.upto modulus-1 do |r|
|
|
1839
|
+
text = "m=#{modulus} r=#{r}"
|
|
1840
|
+
|
|
1841
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1842
|
+
assert(zero_r >= 0, "0_r=#{zero_r} " + text)
|
|
1843
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS)
|
|
1844
|
+
assert(zero_r <= 0, "0_r=#{zero_r} " + text)
|
|
1845
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS)
|
|
1846
|
+
dd = 2*zero_r.abs
|
|
1847
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1848
|
+
if (zero_r < 0)
|
|
1849
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1850
|
+
end
|
|
1851
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_MINUS)
|
|
1852
|
+
dd = 2*zero_r.abs
|
|
1853
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1854
|
+
if (zero_r > 0)
|
|
1855
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1856
|
+
end
|
|
1857
|
+
|
|
1858
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1859
|
+
assert(zero_r >= 0, "0_r=#{zero_r} " + text)
|
|
1860
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS)
|
|
1861
|
+
assert(zero_r <= 0, "0_r=#{zero_r} " + text)
|
|
1862
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS)
|
|
1863
|
+
dd = 2*zero_r.abs
|
|
1864
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1865
|
+
if (zero_r < 0)
|
|
1866
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1867
|
+
end
|
|
1868
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_MINUS)
|
|
1869
|
+
dd = 2*zero_r.abs
|
|
1870
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1871
|
+
if (zero_r > 0)
|
|
1872
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1873
|
+
end
|
|
1874
|
+
|
|
1875
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_CEILING, LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY)
|
|
1876
|
+
assert(zero_r >= 0, "0_r=#{zero_r} " + text)
|
|
1877
|
+
|
|
1878
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_FLOOR, LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY)
|
|
1879
|
+
assert(zero_r <= 0, "0_r=#{zero_r} " + text)
|
|
1880
|
+
|
|
1881
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_HALF_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1882
|
+
dd = 2*zero_r.abs
|
|
1883
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1884
|
+
if (zero_r < 0)
|
|
1885
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1886
|
+
end
|
|
1887
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_HALF_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS)
|
|
1888
|
+
dd = 2*zero_r.abs
|
|
1889
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1890
|
+
if (zero_r < 0)
|
|
1891
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1892
|
+
end
|
|
1893
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_HALF_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS)
|
|
1894
|
+
dd = 2*zero_r.abs
|
|
1895
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1896
|
+
if (zero_r > 0)
|
|
1897
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1898
|
+
end
|
|
1899
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_HALF_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_MINUS)
|
|
1900
|
+
dd = 2*zero_r.abs
|
|
1901
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1902
|
+
if (zero_r > 0)
|
|
1903
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1904
|
+
end
|
|
1905
|
+
|
|
1906
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_HALF_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1907
|
+
dd = 2*zero_r.abs
|
|
1908
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1909
|
+
if (zero_r < 0)
|
|
1910
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1911
|
+
end
|
|
1912
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_HALF_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS)
|
|
1913
|
+
dd = 2*zero_r.abs
|
|
1914
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1915
|
+
if (zero_r < 0)
|
|
1916
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1917
|
+
end
|
|
1918
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_HALF_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS)
|
|
1919
|
+
dd = 2*zero_r.abs
|
|
1920
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1921
|
+
if (zero_r > 0)
|
|
1922
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1923
|
+
end
|
|
1924
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_HALF_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_MINUS)
|
|
1925
|
+
dd = 2*zero_r.abs
|
|
1926
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1927
|
+
if (zero_r > 0)
|
|
1928
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1929
|
+
end
|
|
1930
|
+
|
|
1931
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_HALF_CEILING, LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY)
|
|
1932
|
+
dd = 2*zero_r.abs
|
|
1933
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1934
|
+
if (zero_r < 0)
|
|
1935
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1936
|
+
end
|
|
1937
|
+
|
|
1938
|
+
zero_r = check_round_to_one_remainder(0, r, modulus, LongDecimalRoundingMode::ROUND_HALF_FLOOR, LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY)
|
|
1939
|
+
dd = 2*zero_r.abs
|
|
1940
|
+
assert(dd <= modulus, "0_r=#{zero_r} " + text)
|
|
1941
|
+
if (zero_r > 0)
|
|
1942
|
+
assert(dd < modulus, "0_r=#{zero_r} " + text)
|
|
1943
|
+
end
|
|
1944
|
+
end
|
|
1945
|
+
end
|
|
1946
|
+
end
|
|
1947
|
+
|
|
1948
|
+
def check_round_to_one_remainder(i, r, modulus, rounding_mode, zero_rounding_mode)
|
|
1949
|
+
|
|
1950
|
+
# puts("i=#{i} r=#{r} m=#{modulus}")
|
|
1951
|
+
zero_modes = [ LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS,\
|
|
1952
|
+
LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS,\
|
|
1953
|
+
LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS,\
|
|
1954
|
+
LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_MINUS,\
|
|
1955
|
+
LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY ];
|
|
1956
|
+
remainders = [ r ]
|
|
1957
|
+
i_rounded = i.round_to_allowed_remainders(remainders, modulus, rounding_mode, zero_rounding_mode)
|
|
1958
|
+
if (i != 0 || zero_rounding_mode == LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY)
|
|
1959
|
+
zero_modes.each do |zm|
|
|
1960
|
+
assert_equal(i_rounded, i.round_to_allowed_remainders(remainders, modulus, rounding_mode, zm), "i=#{i} i_r=#{i_rounded} m=#{modulus} zm=#{zm} r=#{r}")
|
|
1961
|
+
end
|
|
1962
|
+
end
|
|
1963
|
+
assert_equal(0, (i_rounded - r) % modulus)
|
|
1964
|
+
assert(i - modulus < i_rounded)
|
|
1965
|
+
assert(i_rounded < i + modulus)
|
|
1966
|
+
i_rounded
|
|
1967
|
+
end
|
|
1968
|
+
|
|
1969
|
+
#
|
|
1970
|
+
# test rounding of int to remainder set
|
|
1971
|
+
#
|
|
1972
|
+
def test_int_round_to_allowed_remainders
|
|
1973
|
+
2.upto 8 do |modulus|
|
|
1974
|
+
xx = (1<< modulus) - 1
|
|
1975
|
+
xx.times do |x|
|
|
1976
|
+
remainders = make_set(x + 1, modulus)
|
|
1977
|
+
text0 = "m=#{modulus} x=#{x} s=#{remainders.inspect}"
|
|
1978
|
+
puts text0
|
|
1979
|
+
n = 3*modulus
|
|
1980
|
+
(-n).upto n do |i|
|
|
1981
|
+
text = "i=#{i} n=#{n} " + text0
|
|
1982
|
+
i_rounded, set, above, below = check_round_to_remainders(i, remainders, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1983
|
+
assert(i_rounded.abs >= i.abs, "i_r=#{i_rounded} " + text)
|
|
1984
|
+
if (i == 0) then
|
|
1985
|
+
assert(i_rounded >= 0, "i_r=#{i_rounded} " + text)
|
|
1986
|
+
assert_equal(above.length, 0, "i_r=#{i_rounded} " + text)
|
|
1987
|
+
elsif (i > 0) then
|
|
1988
|
+
# rounded away from 0, so for positive i to value >= i
|
|
1989
|
+
assert_equal(above.length, 0, text)
|
|
1990
|
+
assert(i_rounded >= i, "i_r=#{i_rounded} " + text)
|
|
1991
|
+
else
|
|
1992
|
+
# i < 0
|
|
1993
|
+
# rounded away from 0, so for positive i to value <= i
|
|
1994
|
+
assert_equal(below.length, 0, text)
|
|
1995
|
+
assert(i_rounded <= i, "i_r=#{i_rounded} " + text)
|
|
1996
|
+
end
|
|
1997
|
+
|
|
1998
|
+
i_rounded, set, above, below = check_round_to_remainders(i, remainders, modulus, LongDecimalRoundingMode::ROUND_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
1999
|
+
if (i > 0)
|
|
2000
|
+
assert(i_rounded <= i, "i_r=#{i_rounded} " + text)
|
|
2001
|
+
assert_equal(below.length, 0, "i_r=#{i_rounded} " + text)
|
|
2002
|
+
elsif (i < 0)
|
|
2003
|
+
assert(i_rounded >= i, "i_r=#{i_rounded} " + text)
|
|
2004
|
+
assert_equal(above.length, 0, "i_r=#{i_rounded} " + text)
|
|
2005
|
+
elsif (i == 0) then
|
|
2006
|
+
assert(i_rounded >= 0, "i_r=#{i_rounded} " + text)
|
|
2007
|
+
assert_equal(above.length, 0, "i_r=#{i_rounded} " + text)
|
|
2008
|
+
else
|
|
2009
|
+
raise("i=#{i} i_r=#{i_rounded}")
|
|
2010
|
+
end
|
|
2011
|
+
|
|
2012
|
+
i_rounded, set, above, below = check_round_to_remainders(i, remainders, modulus, LongDecimalRoundingMode::ROUND_CEILING, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
2013
|
+
assert(i_rounded >= i, "i_r=#{i_rounded} " + text)
|
|
2014
|
+
assert_equal(above.length, 0, "i_r=#{i_rounded} " + text)
|
|
2015
|
+
|
|
2016
|
+
i_rounded, set, above, below = check_round_to_remainders(i, remainders, modulus, LongDecimalRoundingMode::ROUND_FLOOR, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
2017
|
+
assert(i_rounded <= i, "i_r=#{i_rounded} " + text)
|
|
2018
|
+
assert_equal(below.length, 0, "i_r=#{i_rounded} " + text)
|
|
2019
|
+
|
|
2020
|
+
i_rounded, set, above, below = check_round_to_remainders(i, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
2021
|
+
dd = 2*(i_rounded - i).abs
|
|
2022
|
+
assert(dd <= modulus, "i_r=#{i_rounded} " + text)
|
|
2023
|
+
if (i_rounded.abs < i.abs || i_rounded.sgn == - i.sgn)
|
|
2024
|
+
assert(dd < modulus, "i_r=#{i_rounded} " + text)
|
|
2025
|
+
end
|
|
2026
|
+
assert_equal(below.length, 0, "i_r=#{i_rounded} " + text)
|
|
2027
|
+
assert_equal(above.length, 0, "i_r=#{i_rounded} " + text)
|
|
2028
|
+
|
|
2029
|
+
i_rounded, set, above, below = check_round_to_remainders(i, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
2030
|
+
dd = 2*(i_rounded - i).abs
|
|
2031
|
+
assert(dd <= modulus, "i_r=#{i_rounded} " + text)
|
|
2032
|
+
if (i_rounded.abs > i.abs && i_rounded.sgn == i.sgn)
|
|
2033
|
+
assert(dd < modulus, "i_r=#{i_rounded} " + text)
|
|
2034
|
+
end
|
|
2035
|
+
assert_equal(below.length, 0, "i_r=#{i_rounded} " + text)
|
|
2036
|
+
assert_equal(above.length, 0, "i_r=#{i_rounded} " + text)
|
|
2037
|
+
|
|
2038
|
+
i_rounded, set, above, below = check_round_to_remainders(i, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_CEILING, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
2039
|
+
dd = 2*(i_rounded - i).abs
|
|
2040
|
+
assert(dd <= modulus, "i_r=#{i_rounded} " + text)
|
|
2041
|
+
if (i_rounded < i)
|
|
2042
|
+
assert(dd < modulus, "i_r=#{i_rounded} " + text)
|
|
2043
|
+
end
|
|
2044
|
+
assert_equal(below.length, 0, "i_r=#{i_rounded} " + text)
|
|
2045
|
+
assert_equal(above.length, 0, "i_r=#{i_rounded} " + text)
|
|
2046
|
+
|
|
2047
|
+
i_rounded, set, above, below = check_round_to_remainders(i, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_FLOOR, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
2048
|
+
dd = 2*(i_rounded - i).abs
|
|
2049
|
+
assert(dd <= modulus, "i_r=#{i_rounded} " + text)
|
|
2050
|
+
if (i_rounded > i && i != 0)
|
|
2051
|
+
assert(dd < modulus, "i_r=#{i_rounded} " + text)
|
|
2052
|
+
end
|
|
2053
|
+
assert_equal(below.length, 0, "i_r=#{i_rounded} " + text)
|
|
2054
|
+
assert_equal(above.length, 0, "i_r=#{i_rounded} " + text)
|
|
2055
|
+
|
|
2056
|
+
end
|
|
2057
|
+
end
|
|
2058
|
+
end
|
|
2059
|
+
end
|
|
2060
|
+
|
|
2061
|
+
#
|
|
2062
|
+
# test rounding of 0 to remainder set
|
|
2063
|
+
#
|
|
2064
|
+
def test_zero_round_to_allowed_remainders
|
|
2065
|
+
2.upto 8 do |modulus|
|
|
2066
|
+
xx = (1<< modulus) - 1
|
|
2067
|
+
xx.times do |x|
|
|
2068
|
+
remainders = make_set(x + 1, modulus)
|
|
2069
|
+
text = "m=#{modulus} x=#{x} s=#{remainders.inspect}"
|
|
2070
|
+
puts text
|
|
2071
|
+
|
|
2072
|
+
# ROUND_UP and ROUND_DOWN have the same effect for 0
|
|
2073
|
+
zero_r1, set1, above1, below1 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
2074
|
+
zero_r2, set2, above2, below2 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
2075
|
+
assert_equal(zero_r1, zero_r2, text)
|
|
2076
|
+
assert_equal(above1, above2, text)
|
|
2077
|
+
assert_equal(below1, below2, text)
|
|
2078
|
+
assert(zero_r1 >= 0, "0_r=#{zero_r1} " + text)
|
|
2079
|
+
assert_equal(above1.length, 0, text)
|
|
2080
|
+
|
|
2081
|
+
zero_r1, set1, above1, below1 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS)
|
|
2082
|
+
zero_r2, set2, above2, below2 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS)
|
|
2083
|
+
assert_equal(zero_r1, zero_r2, text)
|
|
2084
|
+
assert_equal(above1, above2, text)
|
|
2085
|
+
assert_equal(below1, below2, text)
|
|
2086
|
+
assert(zero_r1 <= 0, "0_r=#{zero_r1} " + text)
|
|
2087
|
+
assert_equal(below1.length, 0, text)
|
|
2088
|
+
|
|
2089
|
+
zero_r1, set1, above1, below1 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS)
|
|
2090
|
+
zero_r2, set2, above2, below2 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS)
|
|
2091
|
+
assert_equal(zero_r1, zero_r2, text)
|
|
2092
|
+
assert_equal(above1, above2, text)
|
|
2093
|
+
assert_equal(below1, below2, text)
|
|
2094
|
+
dd = 2*zero_r1.abs
|
|
2095
|
+
assert(dd <= modulus, "0_r=#{zero_r1} dd=#{dd} " + text)
|
|
2096
|
+
if (zero_r1 < 0)
|
|
2097
|
+
assert(dd < modulus, "0_r=#{zero_r1} dd=#{dd} " + text)
|
|
2098
|
+
end
|
|
2099
|
+
if (below1.length > 0)
|
|
2100
|
+
assert(below1.max.abs >= zero_r1.abs, text)
|
|
2101
|
+
end
|
|
2102
|
+
if (above1.length > 0)
|
|
2103
|
+
assert(above1.min.abs >= zero_r1.abs, text)
|
|
2104
|
+
end
|
|
2105
|
+
|
|
2106
|
+
zero_r1, set1, above1, below1 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_MINUS)
|
|
2107
|
+
zero_r2, set2, above2, below2 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_MINUS)
|
|
2108
|
+
assert_equal(zero_r1, zero_r2, text)
|
|
2109
|
+
assert_equal(above1, above2, text)
|
|
2110
|
+
assert_equal(below1, below2, text)
|
|
2111
|
+
dd = 2*zero_r1.abs
|
|
2112
|
+
assert(dd <= modulus, "0_r=#{zero_r1} dd=#{dd} " + text)
|
|
2113
|
+
if (zero_r1 > 0)
|
|
2114
|
+
assert(dd < modulus, "0_r=#{zero_r1} dd=#{dd} " + text)
|
|
2115
|
+
end
|
|
2116
|
+
if (below1.length > 0)
|
|
2117
|
+
assert(below1.max.abs >= zero_r1.abs, text)
|
|
2118
|
+
end
|
|
2119
|
+
assert_equal(above1.length, 0, text)
|
|
2120
|
+
|
|
2121
|
+
zero_r0, set0, above0, below0 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_CEILING, LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY)
|
|
2122
|
+
assert(zero_r0 >= 0, "0_r=#{zero_r0} " + text)
|
|
2123
|
+
assert_equal(above0.length, 0, text)
|
|
2124
|
+
|
|
2125
|
+
zero_r0, set0, above0, below0 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_FLOOR, LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY)
|
|
2126
|
+
assert(zero_r0 <= 0, "0_r=#{zero_r0} " + text)
|
|
2127
|
+
assert_equal(below0.length, 0, text)
|
|
2128
|
+
|
|
2129
|
+
zero_r1, set1, above1, below1 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
2130
|
+
zero_r2, set2, above2, below2 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS)
|
|
2131
|
+
assert_equal(zero_r1, zero_r2, text)
|
|
2132
|
+
assert_equal(above1, above2, text)
|
|
2133
|
+
assert_equal(below1, below2, text)
|
|
2134
|
+
zero_r2, set2, above2, below2 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS)
|
|
2135
|
+
assert_equal(zero_r1, zero_r2, text)
|
|
2136
|
+
assert_equal(above1, above2, text)
|
|
2137
|
+
assert_equal(below1, below2, text)
|
|
2138
|
+
zero_r2, set2, above2, below2 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS)
|
|
2139
|
+
assert_equal(zero_r1, zero_r2, text)
|
|
2140
|
+
assert_equal(above1, above2, text)
|
|
2141
|
+
assert_equal(below1, below2, text)
|
|
2142
|
+
dd = 2*zero_r1.abs
|
|
2143
|
+
assert(dd <= modulus, "0_r=#{zero_r1} dd=#{dd} " + text)
|
|
2144
|
+
if (zero_r1 < 0)
|
|
2145
|
+
assert(dd < modulus, "0_r=#{zero_r1} dd=#{dd} " + text)
|
|
2146
|
+
end
|
|
2147
|
+
assert_equal(below1.length, 0, text)
|
|
2148
|
+
assert_equal(above1.length, 0, text)
|
|
2149
|
+
|
|
2150
|
+
zero_r1, set1, above1, below1 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS)
|
|
2151
|
+
zero_r2, set2, above2, below2 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS)
|
|
2152
|
+
assert_equal(zero_r1, zero_r2, text)
|
|
2153
|
+
assert_equal(above1, above2, text)
|
|
2154
|
+
assert_equal(below1, below2, text)
|
|
2155
|
+
zero_r2, set2, above2, below2 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_UP, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_MINUS)
|
|
2156
|
+
assert_equal(zero_r1, zero_r2, text)
|
|
2157
|
+
assert_equal(above1, above2, text)
|
|
2158
|
+
assert_equal(below1, below2, text)
|
|
2159
|
+
zero_r2, set2, above2, below2 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_DOWN, LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_MINUS)
|
|
2160
|
+
assert_equal(zero_r1, zero_r2, text)
|
|
2161
|
+
assert_equal(above1, above2, text)
|
|
2162
|
+
assert_equal(below1, below2, text)
|
|
2163
|
+
dd = 2*zero_r1.abs
|
|
2164
|
+
assert(dd <= modulus, "0_r=#{zero_r1} dd=#{dd} " + text)
|
|
2165
|
+
if (zero_r1 > 0)
|
|
2166
|
+
assert(dd < modulus, "0_r=#{zero_r1} dd=#{dd} " + text)
|
|
2167
|
+
end
|
|
2168
|
+
assert_equal(below1.length, 0, text)
|
|
2169
|
+
assert_equal(above1.length, 0, text)
|
|
2170
|
+
|
|
2171
|
+
zero_r0, set0, above0, below0 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_CEILING, LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY)
|
|
2172
|
+
dd = 2*zero_r0.abs
|
|
2173
|
+
assert(dd <= modulus, "0_r=#{zero_r0} dd=#{dd} " + text)
|
|
2174
|
+
if (zero_r0 < 0)
|
|
2175
|
+
assert(dd < modulus, "0_r=#{zero_r0} dd=#{dd} " + text)
|
|
2176
|
+
end
|
|
2177
|
+
assert_equal(below0.length, 0, text)
|
|
2178
|
+
assert_equal(above0.length, 0, text)
|
|
2179
|
+
|
|
2180
|
+
zero_r0, set0, above0, below0 = check_round_to_remainders(0, remainders, modulus, LongDecimalRoundingMode::ROUND_HALF_FLOOR, LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY)
|
|
2181
|
+
dd = 2*zero_r0.abs
|
|
2182
|
+
assert(dd <= modulus, "0_r=#{zero_r0} " + text)
|
|
2183
|
+
if (zero_r0 > 0)
|
|
2184
|
+
assert(dd < modulus, "0_r=#{zero_r0} " + text)
|
|
2185
|
+
end
|
|
2186
|
+
assert_equal(below0.length, 0, text)
|
|
2187
|
+
assert_equal(above0.length, 0, text)
|
|
2188
|
+
|
|
2189
|
+
end
|
|
2190
|
+
end
|
|
2191
|
+
end
|
|
2192
|
+
|
|
2193
|
+
def make_set(x, m)
|
|
2194
|
+
s = []
|
|
2195
|
+
b = 1
|
|
2196
|
+
m.times do |i|
|
|
2197
|
+
if (b & x) == b
|
|
2198
|
+
s = s.push(i)
|
|
2199
|
+
end
|
|
2200
|
+
b = 2*b
|
|
2201
|
+
end
|
|
2202
|
+
s
|
|
2203
|
+
end
|
|
2204
|
+
|
|
2205
|
+
def check_round_to_remainders(i, remainders, modulus, rounding_mode, zero_rounding_mode)
|
|
2206
|
+
|
|
2207
|
+
zero_modes = [ LongDecimalRoundingMode::ZERO_ROUND_TO_PLUS,\
|
|
2208
|
+
LongDecimalRoundingMode::ZERO_ROUND_TO_MINUS,\
|
|
2209
|
+
LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_PLUS,\
|
|
2210
|
+
LongDecimalRoundingMode::ZERO_ROUND_TO_CLOSEST_PREFER_MINUS,\
|
|
2211
|
+
LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY ];
|
|
2212
|
+
|
|
2213
|
+
i_rounded = i.round_to_allowed_remainders(remainders, modulus, rounding_mode, zero_rounding_mode)
|
|
2214
|
+
if (i != 0 || zero_rounding_mode == LongDecimalRoundingMode::ZERO_ROUND_UNNECESSARY)
|
|
2215
|
+
zero_modes.each do |zm|
|
|
2216
|
+
assert_equal(i_rounded, i.round_to_allowed_remainders(remainders, modulus, rounding_mode, zm), "i=#{i} i_r=#{i_rounded} m=#{modulus} zm=#{zm}")
|
|
2217
|
+
end
|
|
2218
|
+
end
|
|
2219
|
+
one_remainder = remainders.select do |r|
|
|
2220
|
+
(i_rounded - r) % modulus == 0
|
|
2221
|
+
end
|
|
2222
|
+
assert_equal(1, one_remainder.length, "i_r=#{i_rounded} i=#{i} m=#{modulus} r=#{remainders} or=#{one_remainder.to_s}")
|
|
2223
|
+
assert(i - modulus < i_rounded)
|
|
2224
|
+
assert(i_rounded < i + modulus)
|
|
2225
|
+
set = remainders.map do |r|
|
|
2226
|
+
check_round_to_one_remainder(i, r, modulus, rounding_mode, zero_rounding_mode)
|
|
2227
|
+
end
|
|
2228
|
+
closer_above = []
|
|
2229
|
+
closer_below = []
|
|
2230
|
+
found = false
|
|
2231
|
+
set.each do |i_r|
|
|
2232
|
+
if (i_r == i_rounded)
|
|
2233
|
+
found = true
|
|
2234
|
+
else
|
|
2235
|
+
assert(i != i_r, "i=#{i} i_r=#{i_r} i_rounded=#{i_rounded}")
|
|
2236
|
+
closer = ((i_r - i).abs < (i_rounded -i).abs)
|
|
2237
|
+
if (i < i_r)
|
|
2238
|
+
assert(i_rounded < i_r)
|
|
2239
|
+
if closer
|
|
2240
|
+
closer_above.push(i_r)
|
|
2241
|
+
end
|
|
2242
|
+
else
|
|
2243
|
+
# i_r < i
|
|
2244
|
+
assert(i_r < i_rounded)
|
|
2245
|
+
if closer
|
|
2246
|
+
closer_below.push(i_r)
|
|
2247
|
+
end
|
|
2248
|
+
end
|
|
2249
|
+
end
|
|
2250
|
+
end
|
|
2251
|
+
return i_rounded, set, closer_above, closer_below
|
|
2252
|
+
|
|
2253
|
+
end # check_round_to_remainders
|
|
2254
|
+
|
|
2255
|
+
# any subset of 0..m-1 with rounding of 0
|
|
2256
|
+
#
|
|
2257
|
+
# ROUND_UNNECESSARY/ROUND_HALF_EVEN
|
|
2258
|
+
|
|
1586
2259
|
#
|
|
1587
2260
|
# test conversion to String
|
|
1588
2261
|
#
|
|
@@ -1689,24 +2362,33 @@ class TestLongDecimal_class < RUNIT::TestCase
|
|
|
1689
2362
|
def test_to_f
|
|
1690
2363
|
l = LongDecimal(224, 0)
|
|
1691
2364
|
assert((l.to_f - 224).abs < 224 * 0.000001, "l=#{l.inspect}")
|
|
2365
|
+
assert(((-l).to_f + 224).abs < 224 * 0.000001, "l=#{l.inspect}")
|
|
1692
2366
|
l = LongDecimal(224, 1)
|
|
1693
2367
|
assert((l.to_f - 22.4).abs < 22.4 * 0.000001, "l=#{l.inspect}")
|
|
2368
|
+
assert(((-l).to_f + 22.4).abs < 22.4 * 0.000001, "l=#{l.inspect}")
|
|
1694
2369
|
l = LongDecimal(224, 2)
|
|
1695
2370
|
assert((l.to_f - 2.24).abs < 2.24 * 0.000001, "l=#{l.inspect}")
|
|
2371
|
+
assert(((-l).to_f + 2.24).abs < 2.24 * 0.000001, "l=#{l.inspect}")
|
|
1696
2372
|
l = LongDecimal(224, 3)
|
|
1697
2373
|
assert((l.to_f - 0.224).abs < 0.224 * 0.000001, "l=#{l.inspect}")
|
|
2374
|
+
assert(((-l).to_f + 0.224).abs < 0.224 * 0.000001, "l=#{l.inspect}")
|
|
1698
2375
|
l = LongDecimal(224, 4)
|
|
1699
2376
|
assert((l.to_f - 0.0224).abs < 0.0224 * 0.000001, "l=#{l.inspect}")
|
|
2377
|
+
assert(((-l).to_f + 0.0224).abs < 0.0224 * 0.000001, "l=#{l.inspect}")
|
|
1700
2378
|
|
|
1701
2379
|
l = LongDecimal("0." + ("0" * 30) + "1" + ("0" * 500))
|
|
1702
2380
|
assert((l.to_f - 1e-31).abs < 1e-32, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
|
2381
|
+
assert(((-l).to_f + 1e-31).abs < 1e-32, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
|
1703
2382
|
l = LongDecimal("0." + ("0" * 200) + "1" + ("0" * 500))
|
|
1704
2383
|
assert((l.to_f - 1e-201).abs < 1e-202, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
|
2384
|
+
assert(((-l).to_f + 1e-201).abs < 1e-202, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
|
1705
2385
|
l = LongDecimal("0." + ("0" * 280) + "1" + ("0" * 500))
|
|
1706
2386
|
assert((l.to_f - 1e-281).abs < 1e-282, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
|
2387
|
+
assert(((-l).to_f + 1e-281).abs < 1e-282, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
|
1707
2388
|
|
|
1708
2389
|
l = LongDecimal("0.00000000000000000000000000000000000000000000000000002090000000000000000000000000332000042999999999999999934478499999999999999999999979183597303900000000000002280678889571719972270000000870125632696979999999999928587104894304210318436999963636067429710015568287618182130517226303011944557351440293760289098908449297658922618709026683663019359834144789263320")
|
|
1709
2390
|
assert((l.to_f - 0.0000000000000000000000000000000000000000000000000000209).abs < 1e-60, "l=#{l.inspect}")
|
|
2391
|
+
assert(((-l).to_f + 0.0000000000000000000000000000000000000000000000000000209).abs < 1e-60, "l=#{l.inspect}")
|
|
1710
2392
|
end
|
|
1711
2393
|
|
|
1712
2394
|
#
|