long-decimal 1.00.01 → 1.00.02
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/LICENSE +15 -0
- data/README +41 -41
- data/Rakefile +19 -73
- data/lib/long-decimal-extra.rb +5 -672
- data/lib/long-decimal.rb +1609 -141
- data/lib/long-decimal/version.rb +3 -0
- data/long-decimal.gemspec +22 -0
- data/test/testlongdecimal.rb +2498 -651
- data/test/testlongdeclib.rb +20 -10
- data/test/testrandlib.rb +6 -5
- data/test/testrandom.rb +30 -14
- data/test/testrandpower.rb +22 -7
- data/tex/long-decimal.pdf +0 -0
- data/tex/long-decimal.tex +420 -0
- metadata +72 -64
- data/VERSION +0 -1
- data/install.rb +0 -18
- data/make_doc.rb +0 -12
- data/test/testlongdecimal-extra.rb +0 -1750
- data/test/testlongdecimal-performance.rb +0 -357
- data/test/testrandom-extra.rb +0 -80
- data/version.rb +0 -39
metadata
CHANGED
@@ -1,79 +1,87 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: long-decimal
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: 1.00.01
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.00.02
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Karl Brodowsky
|
13
|
-
autorequire:
|
8
|
+
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
date: 2015-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Decimal arbitrary precision fixed point numbers in pure Ruby.
|
42
|
+
email:
|
43
|
+
- karl_brodowsky@yahoo.com
|
23
44
|
executables: []
|
24
|
-
|
25
45
|
extensions: []
|
26
|
-
|
27
46
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
- README
|
32
|
-
-
|
33
|
-
- lib/long-decimal-extra.rb
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
- test/
|
38
|
-
- test/
|
39
|
-
- test/testrandlib.rb
|
40
|
-
- test/
|
41
|
-
- test/
|
42
|
-
-
|
43
|
-
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
licenses: []
|
49
|
-
|
47
|
+
files:
|
48
|
+
- "./Gemfile"
|
49
|
+
- "./LICENSE"
|
50
|
+
- "./README"
|
51
|
+
- "./Rakefile"
|
52
|
+
- "./lib/long-decimal-extra.rb"
|
53
|
+
- "./lib/long-decimal.rb"
|
54
|
+
- "./lib/long-decimal/version.rb"
|
55
|
+
- "./long-decimal.gemspec"
|
56
|
+
- "./test/testlongdecimal.rb"
|
57
|
+
- "./test/testlongdeclib.rb"
|
58
|
+
- "./test/testrandlib.rb"
|
59
|
+
- "./test/testrandom.rb"
|
60
|
+
- "./test/testrandpower.rb"
|
61
|
+
- "./tex/long-decimal.pdf"
|
62
|
+
- "./tex/long-decimal.tex"
|
63
|
+
homepage: https://github.com/bk1/ruby-long-decimal
|
64
|
+
licenses:
|
65
|
+
- LGPL or Ruby
|
66
|
+
metadata: {}
|
50
67
|
post_install_message:
|
51
68
|
rdoc_options: []
|
52
|
-
|
53
|
-
require_paths:
|
69
|
+
require_paths:
|
54
70
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
|
57
|
-
requirements:
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
58
73
|
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
|
-
requirements:
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
66
78
|
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
- 0
|
70
|
-
version: "0"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
71
81
|
requirements: []
|
72
|
-
|
73
|
-
|
74
|
-
rubygems_version: 1.3.7
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.2.2
|
75
84
|
signing_key:
|
76
|
-
specification_version:
|
77
|
-
summary:
|
78
|
-
test_files:
|
79
|
-
- test/testlongdecimal.rb
|
85
|
+
specification_version: 4
|
86
|
+
summary: Fixed Point Decimal Numbers
|
87
|
+
test_files: []
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.00.01
|
data/install.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#
|
4
|
-
# CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/install.rb,v 1.3 2009/04/15 19:29:37 bk1 Exp $
|
5
|
-
# CVS-Label: $Name: RELEASE_1_00_00 $
|
6
|
-
# Author: $Author: bk1 $ (Karl Brodowsky)
|
7
|
-
#
|
8
|
-
|
9
|
-
require 'rbconfig'
|
10
|
-
require 'fileutils'
|
11
|
-
include FileUtils::Verbose
|
12
|
-
|
13
|
-
include Config
|
14
|
-
|
15
|
-
file = 'lib/long-decimal.rb'
|
16
|
-
dest = CONFIG["sitelibdir"]
|
17
|
-
install(file, dest)
|
18
|
-
# vim: set et sw=4 ts=4:
|
data/make_doc.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#
|
4
|
-
# CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/make_doc.rb,v 1.3 2009/04/15 19:29:37 bk1 Exp $
|
5
|
-
# CVS-Label: $Name: RELEASE_1_00_00 $
|
6
|
-
# Author: $Author: bk1 $ (Karl Brodowsky)
|
7
|
-
#
|
8
|
-
|
9
|
-
$outdir = 'doc/'
|
10
|
-
puts "Creating documentation in '#$outdir'."
|
11
|
-
system "rdoc -d -o #$outdir lib/long-decimal.rb"
|
12
|
-
# vim: set et sw=4 ts=4:
|
@@ -1,1750 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# testlongdecimal.rb -- runit test for long-decimal.rb
|
4
|
-
#
|
5
|
-
# (C) Karl Brodowsky (IT Sky Consulting GmbH) 2006-2009
|
6
|
-
#
|
7
|
-
# CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal-extra.rb,v 1.28 2009/05/17 21:27:20 bk1 Exp $
|
8
|
-
# CVS-Label: $Name: RELEASE_1_00_00 $
|
9
|
-
# Author: $Author: bk1 $ (Karl Brodowsky)
|
10
|
-
#
|
11
|
-
|
12
|
-
require 'test/unit'
|
13
|
-
|
14
|
-
# require "runit/testcase"
|
15
|
-
# require "runit/cui/testrunner"
|
16
|
-
# require "runit/testsuite"
|
17
|
-
|
18
|
-
load "lib/long-decimal.rb"
|
19
|
-
load "lib/long-decimal-extra.rb"
|
20
|
-
load "test/testlongdeclib.rb"
|
21
|
-
|
22
|
-
LongMath.prec_overflow_handling = :warn_use_max
|
23
|
-
|
24
|
-
#
|
25
|
-
# test class for LongDecimal and LongDecimalQuot
|
26
|
-
#
|
27
|
-
class TestLongDecimalExtra_class < Test::Unit::TestCase # RUNIT::TestCase
|
28
|
-
include TestLongDecHelper
|
29
|
-
|
30
|
-
@RCS_ID='-$Id: testlongdecimal-extra.rb,v 1.28 2009/05/17 21:27:20 bk1 Exp $-'
|
31
|
-
|
32
|
-
MAX_FLOAT_I = (Float::MAX).to_i
|
33
|
-
|
34
|
-
#
|
35
|
-
# test conversion to Float
|
36
|
-
#
|
37
|
-
def test_to_f
|
38
|
-
print "\ntest_to_f [#{Time.now}]: "
|
39
|
-
l = LongDecimal(224, 0)
|
40
|
-
assert((l.to_f - 224).abs < 224 * 0.000001, "l=#{l.inspect}") # t2
|
41
|
-
assert(((-l).to_f + 224).abs < 224 * 0.000001, "l=#{l.inspect}")
|
42
|
-
l = LongDecimal(224, 1)
|
43
|
-
assert((l.to_f - 22.4).abs < 22.4 * 0.000001, "l=#{l.inspect}")
|
44
|
-
assert(((-l).to_f + 22.4).abs < 22.4 * 0.000001, "l=#{l.inspect}") # t3
|
45
|
-
l = LongDecimal(224, 2)
|
46
|
-
assert((l.to_f - 2.24).abs < 2.24 * 0.000001, "l=#{l.inspect}")
|
47
|
-
assert(((-l).to_f + 2.24).abs < 2.24 * 0.000001, "l=#{l.inspect}")
|
48
|
-
l = LongDecimal(224, 3)
|
49
|
-
assert((l.to_f - 0.224).abs < 0.224 * 0.000001, "l=#{l.inspect}")
|
50
|
-
assert(((-l).to_f + 0.224).abs < 0.224 * 0.000001, "l=#{l.inspect}")
|
51
|
-
l = LongDecimal(224, 4)
|
52
|
-
assert((l.to_f - 0.0224).abs < 0.0224 * 0.000001, "l=#{l.inspect}")
|
53
|
-
assert(((-l).to_f + 0.0224).abs < 0.0224 * 0.000001, "l=#{l.inspect}")
|
54
|
-
|
55
|
-
l = LongDecimal("0." + ("0" * 30) + "1" + ("0" * 500))
|
56
|
-
assert((l.to_f - 1e-31).abs < 1e-32, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
57
|
-
assert(((-l).to_f + 1e-31).abs < 1e-32, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
58
|
-
l = LongDecimal("0." + ("0" * 200) + "1" + ("0" * 500))
|
59
|
-
assert((l.to_f - 1e-201).abs < 1e-202, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
60
|
-
assert(((-l).to_f + 1e-201).abs < 1e-202, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
61
|
-
l = LongDecimal("0." + ("0" * 280) + "1" + ("0" * 500))
|
62
|
-
assert((l.to_f - 1e-281).abs < 1e-282, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
63
|
-
assert(((-l).to_f + 1e-281).abs < 1e-282, "l=#{l.inspect}=#{l.to_s}=#{l.to_f}=#{l.to_s.to_f}")
|
64
|
-
|
65
|
-
l = LongDecimal("0.00000000000000000000000000000000000000000000000000002090000000000000000000000000332000042999999999999999934478499999999999999999999979183597303900000000000002280678889571719972270000000870125632696979999999999928587104894304210318436999963636067429710015568287618182130517226303011944557351440293760289098908449297658922618709026683663019359834144789263320")
|
66
|
-
delta1 = (l - LongDecimal("0.0000000000000000000000000000000000000000000000000000209"))
|
67
|
-
delta2 = delta1.to_f.abs
|
68
|
-
assert(delta2 < 1e-60, "l=#{l.inspect}=#{l.to_s} delta1=#{delta1} delta2=#{delta2}")
|
69
|
-
assert(((-l).to_f + 0.0000000000000000000000000000000000000000000000000000209).abs < 1e-60, "l=#{l.inspect}")
|
70
|
-
end
|
71
|
-
|
72
|
-
#
|
73
|
-
# test to_f of Rational (trivial cases)
|
74
|
-
#
|
75
|
-
def test_r_to_f_small
|
76
|
-
print "\ntest_r_to_f_small [#{Time.now}]: "
|
77
|
-
# trivial: 0, 1, -1,...
|
78
|
-
r = Rational(0, 1)
|
79
|
-
assert_equal(0.0, r.to_f)
|
80
|
-
r = Rational(1, 1)
|
81
|
-
assert_equal(1.0, r.to_f)
|
82
|
-
r = Rational(-1, 1)
|
83
|
-
assert_equal(-1.0, r.to_f)
|
84
|
-
r = Rational(3, 2)
|
85
|
-
assert_equal(1.5, r.to_f)
|
86
|
-
r = Rational(-3, 2)
|
87
|
-
assert_equal(-1.5, r.to_f)
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# test to_f of Rational (max of to_f_orig)
|
92
|
-
#
|
93
|
-
def test_r_to_f_max_float
|
94
|
-
print "\ntest_r_to_f_max_float [#{Time.now}]: "
|
95
|
-
# still numerator and denominator expressable as Float
|
96
|
-
r = Rational(LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE - 1)
|
97
|
-
assert_equal(1.0, r.to_f)
|
98
|
-
assert_equal(1.0, r.to_f_orig)
|
99
|
-
r = Rational(-LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE - 1)
|
100
|
-
assert_equal(-1.0, r.to_f)
|
101
|
-
assert_equal(-1.0, r.to_f_orig)
|
102
|
-
r = Rational(LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE)
|
103
|
-
assert_equal(1.0, r.to_f)
|
104
|
-
assert_equal(1.0, r.to_f_orig)
|
105
|
-
r = Rational(-(LongMath::MAX_FLOATABLE + 1), LongMath::MAX_FLOATABLE)
|
106
|
-
assert_equal(-1.0, r.to_f)
|
107
|
-
assert_equal(-1.0, r.to_f_orig)
|
108
|
-
r = Rational(LongMath::MAX_FLOATABLE, 1)
|
109
|
-
assert_equal(Float::MAX, r.to_f)
|
110
|
-
assert_equal(Float::MAX, r.to_f_orig)
|
111
|
-
r = Rational(-LongMath::MAX_FLOATABLE, 1)
|
112
|
-
assert_equal(-Float::MAX, r.to_f)
|
113
|
-
assert_equal(-Float::MAX, r.to_f_orig)
|
114
|
-
unless RUBY_PLATFORM == 'java'
|
115
|
-
# skip this test in JRuby due to bugs in JRuby's Float
|
116
|
-
r = Rational(1, LongMath::MAX_FLOATABLE)
|
117
|
-
assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
|
118
|
-
assert_equal_float(1/Float::MAX, r.to_f_orig, Float::MIN)
|
119
|
-
r = Rational(-1 , LongMath::MAX_FLOATABLE)
|
120
|
-
assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
|
121
|
-
assert_equal_float(-1/Float::MAX, r.to_f_orig, Float::MIN)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
#
|
126
|
-
# test to_f of Rational with numerator.abs > Float::MAX
|
127
|
-
#
|
128
|
-
def test_r_to_f_big_numerator
|
129
|
-
print "\ntest_r_to_f_big_numerator [#{Time.now}]: "
|
130
|
-
# numerator beyond Float::MAX
|
131
|
-
r = Rational(LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE - 1)
|
132
|
-
assert_equal(1.0, r.to_f)
|
133
|
-
r = Rational(-LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE - 1)
|
134
|
-
assert_equal(-1.0, r.to_f)
|
135
|
-
r = Rational(LongMath::MAX_FLOATABLE + 1, 1)
|
136
|
-
assert_equal(Float::MAX, r.to_f)
|
137
|
-
r = Rational(-LongMath::MAX_FLOATABLE - 1 , 1)
|
138
|
-
assert_equal(-Float::MAX, r.to_f)
|
139
|
-
r = Rational(2 * LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE)
|
140
|
-
assert_equal(2.0, r.to_f)
|
141
|
-
r = Rational(-2 * LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE)
|
142
|
-
assert_equal(-2.0, r.to_f)
|
143
|
-
r = Rational(LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE)
|
144
|
-
assert_equal(Float::MAX, r.to_f)
|
145
|
-
r = Rational(-LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE)
|
146
|
-
assert_equal(-Float::MAX, r.to_f)
|
147
|
-
end
|
148
|
-
|
149
|
-
#
|
150
|
-
# test to_f of Rational with denominator.abs > Float::MAX
|
151
|
-
#
|
152
|
-
def test_r_to_f_big_numerator
|
153
|
-
print "\ntest_r_to_f_big_numerator [#{Time.now}]: "
|
154
|
-
|
155
|
-
# denominator beyond Float::MAX
|
156
|
-
r = Rational(LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE + 1)
|
157
|
-
assert_equal(1.0, r.to_f)
|
158
|
-
r = Rational(-LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE + 1)
|
159
|
-
assert_equal(-1.0, r.to_f)
|
160
|
-
r = Rational(1, LongMath::MAX_FLOATABLE + 1)
|
161
|
-
assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
|
162
|
-
r = Rational(-1, LongMath::MAX_FLOATABLE - 1)
|
163
|
-
assert_equal(-1/Float::MAX, r.to_f, Float::MIN)
|
164
|
-
r = Rational(LongMath::MAX_FLOATABLE, 2 * LongMath::MAX_FLOATABLE)
|
165
|
-
assert_equal(0.5, r.to_f)
|
166
|
-
r = Rational(-LongMath::MAX_FLOATABLE, 2 * LongMath::MAX_FLOATABLE)
|
167
|
-
assert_equal(-0.5, r.to_f)
|
168
|
-
r = Rational(LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE ** 2)
|
169
|
-
assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
|
170
|
-
r = Rational(-LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE ** 2)
|
171
|
-
assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
|
172
|
-
end
|
173
|
-
|
174
|
-
#
|
175
|
-
# test to_f of Rational with numerator.abs > Float::MAX and denominator.abs > Float::MAX
|
176
|
-
#
|
177
|
-
def test_r_to_f_big_numerator
|
178
|
-
print "\ntest_r_to_f_big_numerator [#{Time.now}]: "
|
179
|
-
# both beyond Float::MAX
|
180
|
-
delta = 1/Float::MAX
|
181
|
-
r = Rational(LongMath::MAX_FLOATABLE + 2, LongMath::MAX_FLOATABLE + 1)
|
182
|
-
assert_equal(1.0, r.to_f)
|
183
|
-
r = Rational(-LongMath::MAX_FLOATABLE - 2, LongMath::MAX_FLOATABLE + 1)
|
184
|
-
assert_equal(-1.0, r.to_f)
|
185
|
-
unless RUBY_PLATFORM == 'java'
|
186
|
-
# skip this test in JRuby due to bugs in JRuby's Float
|
187
|
-
r = Rational(LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE ** 3)
|
188
|
-
assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
|
189
|
-
r = Rational(-LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE ** 3)
|
190
|
-
assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
|
191
|
-
end
|
192
|
-
r = Rational(LongMath::MAX_FLOATABLE ** 3, LongMath::MAX_FLOATABLE ** 2)
|
193
|
-
assert_equal(Float::MAX, r.to_f)
|
194
|
-
r = Rational(-LongMath::MAX_FLOATABLE ** 3, LongMath::MAX_FLOATABLE ** 2)
|
195
|
-
assert_equal(-Float::MAX, r.to_f)
|
196
|
-
r = Rational(LongMath::MAX_FLOATABLE + 1, 2 * LongMath::MAX_FLOATABLE)
|
197
|
-
assert_equal(0.5, r.to_f)
|
198
|
-
r = Rational(-(LongMath::MAX_FLOATABLE + 1), 2 * LongMath::MAX_FLOATABLE)
|
199
|
-
assert_equal(-0.5, r.to_f)
|
200
|
-
unless RUBY_PLATFORM == 'java'
|
201
|
-
# skip this test in JRuby due to bugs in JRuby's Float
|
202
|
-
r = Rational(LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE ** 2)
|
203
|
-
assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
|
204
|
-
r = Rational(-LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE ** 2)
|
205
|
-
assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
#
|
210
|
-
# test to_f of Rational with medium sized absolute value
|
211
|
-
#
|
212
|
-
def test_r_to_f_medium
|
213
|
-
print "\ntest_r_to_f_medium [#{Time.now}]: "
|
214
|
-
|
215
|
-
# use some value < 1 "in the middle"
|
216
|
-
f = 1.34078079299426e-126
|
217
|
-
n = 134078079299426
|
218
|
-
d = 10 ** 140
|
219
|
-
u = 10 ** 300
|
220
|
-
n2 = n ** 2
|
221
|
-
d2 = d ** 2
|
222
|
-
u2 = u ** 2
|
223
|
-
delta = 10 ** 135
|
224
|
-
f2 = 1/f
|
225
|
-
delta2 = 1/delta
|
226
|
-
r = Rational(n, d)
|
227
|
-
assert_equal_float(f, r.to_f, delta)
|
228
|
-
r = Rational(d, n)
|
229
|
-
assert_equal_float(f2, r.to_f, delta2)
|
230
|
-
r = Rational(n * d, d2)
|
231
|
-
assert_equal_float(f, r.to_f, delta)
|
232
|
-
r = Rational(d2, n * d)
|
233
|
-
assert_equal_float(f2, r.to_f, delta2)
|
234
|
-
r = Rational(n2, d * n)
|
235
|
-
assert_equal_float(f, r.to_f, delta)
|
236
|
-
r = Rational(d * n, n2)
|
237
|
-
assert_equal_float(f2, r.to_f, delta2)
|
238
|
-
r = Rational(n * u, d * u)
|
239
|
-
assert_equal_float(f, r.to_f, delta)
|
240
|
-
r = Rational(d * u, n * u)
|
241
|
-
assert_equal_float(f2, r.to_f, delta2)
|
242
|
-
r = Rational(n * u2, d * u2)
|
243
|
-
assert_equal_float(f, r.to_f, delta)
|
244
|
-
r = Rational(d * u2, n * u2)
|
245
|
-
assert_equal_float(f2, r.to_f, delta2)
|
246
|
-
|
247
|
-
# use some value > 1 "in the middle"
|
248
|
-
f = 1.34078079299426e+154
|
249
|
-
n = 134078079299426 * 10**154
|
250
|
-
d = 10 ** 14
|
251
|
-
n2 = n ** 2
|
252
|
-
d2 = d ** 2
|
253
|
-
delta = 10 ** 135
|
254
|
-
f2 = 1/f
|
255
|
-
delta2 = 1/delta
|
256
|
-
r = Rational(n, d)
|
257
|
-
assert_equal_float(f, r.to_f, delta)
|
258
|
-
r = Rational(d, n)
|
259
|
-
assert_equal_float(f2, r.to_f, delta2)
|
260
|
-
r = Rational(n * d, d2)
|
261
|
-
assert_equal_float(f, r.to_f, delta)
|
262
|
-
r = Rational(d2, n * d)
|
263
|
-
assert_equal_float(f2, r.to_f, delta2)
|
264
|
-
r = Rational(n2, d * n)
|
265
|
-
assert_equal_float(f, r.to_f, delta)
|
266
|
-
r = Rational(d * n, n2)
|
267
|
-
assert_equal_float(f2, r.to_f, delta2)
|
268
|
-
r = Rational(n * u, d * u)
|
269
|
-
assert_equal_float(f, r.to_f, delta)
|
270
|
-
r = Rational(d * u, n * u)
|
271
|
-
assert_equal_float(f2, r.to_f, delta2)
|
272
|
-
r = Rational(n * u2, d * u2)
|
273
|
-
assert_equal_float(f, r.to_f, delta)
|
274
|
-
r = Rational(d * u2, n * u2)
|
275
|
-
assert_equal_float(f2, r.to_f, delta2)
|
276
|
-
|
277
|
-
end
|
278
|
-
|
279
|
-
#
|
280
|
-
# test to_f of Rational (trivial cases)
|
281
|
-
#
|
282
|
-
def test_ld_to_f_small
|
283
|
-
print "\ntest_ld_to_f_small [#{Time.now}]: "
|
284
|
-
# trivial: 0, 1, -1,...
|
285
|
-
r = LongDecimal(0, 0)
|
286
|
-
assert_equal(0.0, r.to_f) # t1
|
287
|
-
r = LongDecimal(1, 0)
|
288
|
-
assert_equal(1.0, r.to_f)
|
289
|
-
r = LongDecimal(-1, 0)
|
290
|
-
assert_equal(-1.0, r.to_f)
|
291
|
-
r = LongDecimal(15, 1)
|
292
|
-
assert_equal(1.5, r.to_f)
|
293
|
-
r = LongDecimal(-15, 1)
|
294
|
-
assert_equal(-1.5, r.to_f) # t3
|
295
|
-
end
|
296
|
-
|
297
|
-
#
|
298
|
-
# test to_f of LongDecimal
|
299
|
-
#
|
300
|
-
def test_ld_to_f_max_float
|
301
|
-
print "\ntest_ld_to_f_max_float [#{Time.now}]: "
|
302
|
-
y = 1.7976931348623158
|
303
|
-
z = 0.1 ** Float::MAX_10_EXP
|
304
|
-
# still numerator and denominator expressable as Float
|
305
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE, Float::MAX_10_EXP)
|
306
|
-
assert_equal_float(y, r.to_f, 1e-13) # t4
|
307
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE, Float::MAX_10_EXP)
|
308
|
-
assert_equal_float(-y, r.to_f, 1e-13) # t3
|
309
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE - 1, Float::MAX_10_EXP)
|
310
|
-
assert_equal_float(y, r.to_f, 1e-13) # t4
|
311
|
-
r = LongDecimal(-(LongMath::MAX_FLOATABLE + 1), Float::MAX_10_EXP)
|
312
|
-
assert_equal_float(-y, r.to_f, 1e-13)
|
313
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE, 0)
|
314
|
-
assert_equal(Float::MAX, r.to_f)
|
315
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE, 0)
|
316
|
-
assert_equal(-Float::MAX, r.to_f)
|
317
|
-
r = LongDecimal(1, Float::MAX_10_EXP)
|
318
|
-
assert_equal_float(z, r.to_f, Float::MIN)
|
319
|
-
r = LongDecimal(-1, Float::MAX_10_EXP)
|
320
|
-
assert_equal_float(-z, r.to_f, Float::MIN)
|
321
|
-
end
|
322
|
-
|
323
|
-
#
|
324
|
-
# test to_f of LongDecimal with numerator.abs > Float::MAX
|
325
|
-
#
|
326
|
-
def test_ld_to_f_big_numerator
|
327
|
-
print "\ntest_ld_to_f_big_numerator [#{Time.now}]: "
|
328
|
-
y = 1.7976931348623158
|
329
|
-
u = 1.3407807929942596e308
|
330
|
-
# numerator beyond Float::MAX
|
331
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE + 1, Float::MAX_10_EXP)
|
332
|
-
assert_equal(y, r.to_f)
|
333
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE - 1, Float::MAX_10_EXP)
|
334
|
-
assert_equal(-y, r.to_f)
|
335
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE + 1, 0)
|
336
|
-
assert_equal(Float::MAX, r.to_f)
|
337
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE - 1, 0)
|
338
|
-
assert_equal(-Float::MAX, r.to_f)
|
339
|
-
r = LongDecimal(2 * LongMath::MAX_FLOATABLE, Float::MAX_10_EXP)
|
340
|
-
assert_equal(2.0 * y, r.to_f)
|
341
|
-
r = LongDecimal(-2 * LongMath::MAX_FLOATABLE, Float::MAX_10_EXP)
|
342
|
-
assert_equal(-2.0 * y, r.to_f)
|
343
|
-
r = LongDecimal(u ** 2, Float::MAX_10_EXP)
|
344
|
-
assert_equal(Float::MAX, r.to_f)
|
345
|
-
r = LongDecimal(-u ** 2, LongMath::MAX_FLOATABLE)
|
346
|
-
assert_equal(-Float::MAX, r.to_f)
|
347
|
-
end
|
348
|
-
|
349
|
-
#
|
350
|
-
# test to_f of LongDecimal with denominator.abs > Float::MAX
|
351
|
-
#
|
352
|
-
def test_ld_to_f_big_numerator
|
353
|
-
print "\ntest_ld_to_f_big_numerator [#{Time.now}]: "
|
354
|
-
y = 1.7976931348623158
|
355
|
-
z = 0.1 ** Float::MAX_10_EXP + 1
|
356
|
-
|
357
|
-
# denominator beyond Float::MAX
|
358
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE - 1, Float::MAX_10_EXP + 1)
|
359
|
-
assert_equal(y * 0.1, r.to_f)
|
360
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE + 1, Float::MAX_10_EXP + 1)
|
361
|
-
assert_equal(-y * 0.1, r.to_f)
|
362
|
-
r = LongDecimal(1, Float::MAX_10_EXP + 1)
|
363
|
-
assert_equal_float(z, r.to_f, Float::MIN)
|
364
|
-
r = LongDecimal(-1, Float::MAX_10_EXP + 1)
|
365
|
-
assert_equal(-z, r.to_f, Float::MIN)
|
366
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE, 2 * Float::MAX_10_EXP)
|
367
|
-
assert_equal(0.0, r.to_f)
|
368
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE, 2 * Float::MAX_10_EXP)
|
369
|
-
assert_equal(-0.0, r.to_f)
|
370
|
-
end
|
371
|
-
|
372
|
-
#
|
373
|
-
# test to_f of LongDecimal with numerator.abs > Float::MAX and denominator.abs > Float::MAX
|
374
|
-
#
|
375
|
-
def test_ld_to_f_big_numerator
|
376
|
-
print "\ntest_ld_to_f_big_numerator [#{Time.now}]: "
|
377
|
-
y = 1.7976931348623158
|
378
|
-
z = 0.1 ** Float::MAX_10_EXP + 1
|
379
|
-
u = 1.3407807929942596e308
|
380
|
-
v = y**2 * 0.1 ** Float::MAX_10_EXP
|
381
|
-
w = 10 ** Float::MAX_10_EXP
|
382
|
-
x = 0.1 ** Float::MAX_10_EXP
|
383
|
-
|
384
|
-
# both beyond Float::MAX
|
385
|
-
delta = 1/Float::MAX
|
386
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE + 2, Float::MAX_10_EXP + 1)
|
387
|
-
assert_equal_float(y * 0.1, r.to_f, 1e-15) # t12
|
388
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE - 2, Float::MAX_10_EXP + 1)
|
389
|
-
assert_equal_float(-y * 0.1, r.to_f, 1e-15) # t3
|
390
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE ** 2, 3 * Float::MAX_10_EXP)
|
391
|
-
assert_equal_float(v, r.to_f, Float::MIN) # t6
|
392
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE ** 2, 3 * Float::MAX_10_EXP)
|
393
|
-
assert_equal_float(-v, r.to_f, Float::MIN)
|
394
|
-
r = LongDecimal(10 * w + 2, Float::MAX_10_EXP + 1)
|
395
|
-
assert_equal_float(1.0, r.to_f, 1e-15)
|
396
|
-
r = LongDecimal(-10 * w - 2, Float::MAX_10_EXP + 1)
|
397
|
-
assert_equal_float(-1.0, r.to_f, 1e-15)
|
398
|
-
r = LongDecimal(w ** 2 - 1, 3 * Float::MAX_10_EXP)
|
399
|
-
assert_equal_float(x, r.to_f, Float::MIN)
|
400
|
-
r = LongDecimal(-w ** 2 - 1, 3 * Float::MAX_10_EXP)
|
401
|
-
assert_equal_float(-x, r.to_f, Float::MIN)
|
402
|
-
r = LongDecimal(w ** 2, 3 * Float::MAX_10_EXP)
|
403
|
-
assert_equal_float(x, r.to_f, Float::MIN)
|
404
|
-
r = LongDecimal(-w ** 2, 3 * Float::MAX_10_EXP)
|
405
|
-
assert_equal_float(-x, r.to_f, Float::MIN)
|
406
|
-
r = LongDecimal(w ** 2 + 1, 3 * Float::MAX_10_EXP)
|
407
|
-
assert_equal_float(x, r.to_f, Float::MIN)
|
408
|
-
r = LongDecimal(-w ** 2 + 1, 3 * Float::MAX_10_EXP)
|
409
|
-
assert_equal_float(-x, r.to_f, Float::MIN)
|
410
|
-
r = LongDecimal(w ** 2 - 1, 3 * Float::MAX_10_EXP + 1)
|
411
|
-
assert_equal(0.0, r.to_f)
|
412
|
-
r = LongDecimal(-w ** 2 - 1, 3 * Float::MAX_10_EXP + 1)
|
413
|
-
assert_equal(-0.0, r.to_f)
|
414
|
-
r = LongDecimal(w ** 2, 3 * Float::MAX_10_EXP + 1)
|
415
|
-
assert_equal(0.0, r.to_f)
|
416
|
-
r = LongDecimal(-w ** 2, 3 * Float::MAX_10_EXP + 1)
|
417
|
-
assert_equal(-0.0, r.to_f)
|
418
|
-
r = LongDecimal(w ** 2 + 1, 3 * Float::MAX_10_EXP + 1)
|
419
|
-
assert_equal(0.0, r.to_f)
|
420
|
-
r = LongDecimal(-w ** 2 + 1, 3 * Float::MAX_10_EXP + 1)
|
421
|
-
assert_equal(-0.0, r.to_f)
|
422
|
-
r = LongDecimal(w ** 3 + 1, 2 * Float::MAX_10_EXP)
|
423
|
-
assert_equal(w.to_f, r.to_f)
|
424
|
-
r = LongDecimal(-w ** 3 + 1, 2 * Float::MAX_10_EXP)
|
425
|
-
assert_equal(-w.to_f, r.to_f)
|
426
|
-
r = LongDecimal(10 * w + 1, 1 + Float::MAX_10_EXP)
|
427
|
-
assert_equal_float(1.0, r.to_f, 1e-15)
|
428
|
-
r = LongDecimal(-10 * w - 1, 1 + Float::MAX_10_EXP)
|
429
|
-
assert_equal_float(-1.0, r.to_f, 1e-15)
|
430
|
-
r = LongDecimal(10 * w + 1, 2 * Float::MAX_10_EXP)
|
431
|
-
assert_equal_float(10/Float::MAX, r.to_f, 2*Float::MIN, "d=#{r.to_f-10/Float::MAX}")
|
432
|
-
r = LongDecimal(-10 * w + 1, 2 * Float::MAX_10_EXP)
|
433
|
-
assert_equal_float(-10/Float::MAX, r.to_f, 2*Float::MIN, "d=#{r.to_f+10/Float::MAX}")
|
434
|
-
end
|
435
|
-
|
436
|
-
#
|
437
|
-
# test to_f of LongDecimal with medium sized absolute value
|
438
|
-
#
|
439
|
-
def test_ld_to_f_medium
|
440
|
-
print "\ntest_ld_to_f_medium [#{Time.now}]: "
|
441
|
-
|
442
|
-
# use some value < 1 "in the middle"
|
443
|
-
f = 1.34078079299426e-126
|
444
|
-
n = 134078079299426
|
445
|
-
ds = 140
|
446
|
-
d = 10 ** ds
|
447
|
-
us = 300
|
448
|
-
u = 10 ** us
|
449
|
-
n2 = n ** 2
|
450
|
-
d2 = d ** 2
|
451
|
-
u2 = u ** 2
|
452
|
-
delta = 10 ** 135
|
453
|
-
fi = 1/f
|
454
|
-
ni = 74583407312002050942828544 * 10 ** 100
|
455
|
-
deltai = 1/delta
|
456
|
-
|
457
|
-
r = LongDecimal(n, ds)
|
458
|
-
assert_equal_float(f, r.to_f, delta) # t4
|
459
|
-
r = LongDecimal(ni, 0)
|
460
|
-
assert_equal_float(fi, r.to_f, deltai)
|
461
|
-
r = LongDecimal(n * d, 2 * ds)
|
462
|
-
assert_equal_float(f, r.to_f, delta)
|
463
|
-
r = LongDecimal(n * u, ds + us)
|
464
|
-
assert_equal_float(f, r.to_f, delta)
|
465
|
-
r = LongDecimal(ni * u, us)
|
466
|
-
assert_equal_float(fi, r.to_f, deltai) # t9
|
467
|
-
r = LongDecimal(n * u2, ds + 2*us)
|
468
|
-
assert_equal_float(f, r.to_f, delta)
|
469
|
-
|
470
|
-
# use some value > 1 "in the middle"
|
471
|
-
f = 1.34078079299426e+154
|
472
|
-
n = 134078079299426 * 10**154
|
473
|
-
ds = 14
|
474
|
-
d = 10 ** ds
|
475
|
-
n2 = n ** 2
|
476
|
-
d2 = d ** 2
|
477
|
-
delta = 1e139
|
478
|
-
fi = 1/f
|
479
|
-
deltai = 1/delta
|
480
|
-
ni = 745834073120020496384
|
481
|
-
dis = 175
|
482
|
-
di = 10 ** dis
|
483
|
-
|
484
|
-
r = LongDecimal(n, ds)
|
485
|
-
assert_equal_float(f, r.to_f, delta, "d=#{f-r.to_f}")
|
486
|
-
r = LongDecimal(ni, dis)
|
487
|
-
assert_equal_float(fi, r.to_f, deltai)
|
488
|
-
r = LongDecimal(n * d, 2 * ds)
|
489
|
-
assert_equal_float(f, r.to_f, 3 * delta, "d=#{f - r.to_f}") # t4
|
490
|
-
r = LongDecimal(d * ni, ds + dis)
|
491
|
-
assert_equal_float(fi, r.to_f, deltai)
|
492
|
-
r = LongDecimal(n * u, ds + us)
|
493
|
-
assert_equal_float(f, r.to_f, delta)
|
494
|
-
r = LongDecimal(ni * u, dis + us)
|
495
|
-
assert_equal_float(fi, r.to_f, deltai)
|
496
|
-
r = LongDecimal(n * u2, ds + 2 * us)
|
497
|
-
assert_equal_float(f, r.to_f, delta)
|
498
|
-
r = LongDecimal(ni * u2, dis + 2*us)
|
499
|
-
assert_equal_float(fi, r.to_f, deltai)
|
500
|
-
|
501
|
-
end
|
502
|
-
|
503
|
-
# do some conversions that lead to infinity
|
504
|
-
def test_ld_to_f_infinity
|
505
|
-
print "\ntest_ld_to_f_infinity [#{Time.now}]: "
|
506
|
-
f1 = LongDecimal(1000000000000001, 15)
|
507
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE + 1, 0)
|
508
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}") # t13
|
509
|
-
# assert_equal(Float::MAX, r.to_f, "r=#{r}=#{r.to_f}")
|
510
|
-
r = LongDecimal(-(LongMath::MAX_FLOATABLE + 1), 0)
|
511
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
512
|
-
# assert_equal(-Float::MAX, r.to_f, "r=#{r}=#{r.to_f}")
|
513
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE * f1, 0)
|
514
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
515
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE * f1, 0)
|
516
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
517
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE * 2, 0)
|
518
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
519
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE * 2, 0)
|
520
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
521
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE ** 2, 0)
|
522
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
523
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE ** 2, 0)
|
524
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
525
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE * 10 + 1, 1)
|
526
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
527
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE * 10 - 1, 1)
|
528
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
529
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE ** 2, Float::MAX_10_EXP)
|
530
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
531
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE ** 2, Float::MAX_10_EXP)
|
532
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
533
|
-
r = LongDecimal(LongMath::MAX_FLOATABLE ** 3, 2 * Float::MAX_10_EXP)
|
534
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
535
|
-
r = LongDecimal(-LongMath::MAX_FLOATABLE ** 3, 2 * Float::MAX_10_EXP)
|
536
|
-
assert(! r.to_f.finite?, "r=#{r}=#{r.to_f}")
|
537
|
-
end
|
538
|
-
|
539
|
-
# test t7
|
540
|
-
def test_ld_to_f_zero_t7
|
541
|
-
print "\ntest_ld_to_f_zero_t7 [#{Time.now}]: "
|
542
|
-
scale = 600
|
543
|
-
divisor = 10 ** scale
|
544
|
-
val = divisor / (LongMath::INV_MIN_FLOATABLE * 20)
|
545
|
-
r = LongDecimal(val - 1, scale)
|
546
|
-
assert_equal(0.0, r.to_f)
|
547
|
-
r = LongDecimal(-val + 1, scale)
|
548
|
-
assert_equal(0.0, r.to_f)
|
549
|
-
r = LongDecimal(val, scale)
|
550
|
-
assert_equal(0.0, r.to_f)
|
551
|
-
r = LongDecimal(-val, scale)
|
552
|
-
assert_equal(0.0, r.to_f)
|
553
|
-
r = LongDecimal(val + 1, scale)
|
554
|
-
assert_equal_float(0.0, r.to_f, Float::MIN) # t7 (JRuby-only)
|
555
|
-
r = LongDecimal(-val - 1, scale)
|
556
|
-
assert_equal_float(0.0, r.to_f, Float::MIN) # t7 (JRuby-only)
|
557
|
-
r = LongDecimal(val + 2, scale)
|
558
|
-
assert_equal_float(0.0, r.to_f, Float::MIN) # t7 (JRuby-only)
|
559
|
-
r = LongDecimal(-val - 2, scale)
|
560
|
-
assert_equal_float(0.0, r.to_f, Float::MIN) # t7 (JRuby-only)
|
561
|
-
end
|
562
|
-
|
563
|
-
#
|
564
|
-
# test to_f of LongDecimalQuot (trivial cases)
|
565
|
-
#
|
566
|
-
def test_ldq_to_f_small
|
567
|
-
print "\ntest_ldq_to_f_small [#{Time.now}]: "
|
568
|
-
# trivial: 0, 1, -1,...
|
569
|
-
r = LongDecimalQuot(Rational(0, 1), 7)
|
570
|
-
assert_equal(0.0, r.to_f)
|
571
|
-
r = LongDecimalQuot(Rational(1, 1), 7)
|
572
|
-
assert_equal(1.0, r.to_f)
|
573
|
-
r = LongDecimalQuot(Rational(-1, 1), 7)
|
574
|
-
assert_equal(-1.0, r.to_f)
|
575
|
-
r = LongDecimalQuot(Rational(3, 2), 7)
|
576
|
-
assert_equal(1.5, r.to_f)
|
577
|
-
r = LongDecimalQuot(Rational(-3, 2), 7)
|
578
|
-
assert_equal(-1.5, r.to_f)
|
579
|
-
end
|
580
|
-
|
581
|
-
#
|
582
|
-
# test to_f of LongDecimalQuot
|
583
|
-
#
|
584
|
-
def test_ldq_to_f_max_float
|
585
|
-
print "\ntest_ldq_to_f_max_float [#{Time.now}]: "
|
586
|
-
# still numerator and denominator expressable as Float
|
587
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE - 1), 7)
|
588
|
-
assert_equal(1.0, r.to_f)
|
589
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE - 1), 7)
|
590
|
-
assert_equal(-1.0, r.to_f)
|
591
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE), 7)
|
592
|
-
assert_equal(1.0, r.to_f)
|
593
|
-
r = LongDecimalQuot(Rational(-(LongMath::MAX_FLOATABLE + 1), LongMath::MAX_FLOATABLE), 7)
|
594
|
-
assert_equal(-1.0, r.to_f)
|
595
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE, 1), 7)
|
596
|
-
assert_equal(Float::MAX, r.to_f)
|
597
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE, 1), 7)
|
598
|
-
assert_equal(-Float::MAX, r.to_f)
|
599
|
-
unless RUBY_PLATFORM == 'java'
|
600
|
-
# skip this test in JRuby due to bugs in JRuby's Float
|
601
|
-
r = LongDecimalQuot(Rational(1, LongMath::MAX_FLOATABLE), 7)
|
602
|
-
assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
|
603
|
-
r = LongDecimalQuot(Rational(-1 , LongMath::MAX_FLOATABLE), 7)
|
604
|
-
assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
|
605
|
-
end
|
606
|
-
end
|
607
|
-
|
608
|
-
#
|
609
|
-
# test to_f of LongDecimalQuot with numerator.abs > Float::MAX
|
610
|
-
#
|
611
|
-
def test_ldq_to_f_big_numerator
|
612
|
-
print "\ntest_ldq_to_f_big_numerator [#{Time.now}]: "
|
613
|
-
# numerator beyond Float::MAX
|
614
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE - 1), 7)
|
615
|
-
assert_equal(1.0, r.to_f)
|
616
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE - 1), 7)
|
617
|
-
assert_equal(-1.0, r.to_f)
|
618
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE + 1, 1), 7)
|
619
|
-
assert_equal(Float::MAX, r.to_f)
|
620
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE - 1 , 1), 7)
|
621
|
-
assert_equal(-Float::MAX, r.to_f)
|
622
|
-
r = LongDecimalQuot(Rational(2 * LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE), 7)
|
623
|
-
assert_equal(2.0, r.to_f)
|
624
|
-
r = LongDecimalQuot(Rational(-2 * LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE), 7)
|
625
|
-
assert_equal(-2.0, r.to_f)
|
626
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE), 7)
|
627
|
-
assert_equal(Float::MAX, r.to_f)
|
628
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE), 7)
|
629
|
-
assert_equal(-Float::MAX, r.to_f)
|
630
|
-
end
|
631
|
-
|
632
|
-
#
|
633
|
-
# test to_f of LongDecimalQuot with denominator.abs > Float::MAX
|
634
|
-
#
|
635
|
-
def test_ldq_to_f_big_numerator
|
636
|
-
print "\ntest_ldq_to_f_big_numerator [#{Time.now}]: "
|
637
|
-
|
638
|
-
# denominator beyond Float::MAX
|
639
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE + 1), 7)
|
640
|
-
assert_equal(1.0, r.to_f)
|
641
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE + 1), 7)
|
642
|
-
assert_equal(-1.0, r.to_f)
|
643
|
-
r = LongDecimalQuot(Rational(1, LongMath::MAX_FLOATABLE + 1), 7)
|
644
|
-
assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
|
645
|
-
r = LongDecimalQuot(Rational(-1, LongMath::MAX_FLOATABLE - 1), 7)
|
646
|
-
assert_equal(-1/Float::MAX, r.to_f, Float::MIN)
|
647
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE, 2 * LongMath::MAX_FLOATABLE), 7)
|
648
|
-
assert_equal(0.5, r.to_f)
|
649
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE, 2 * LongMath::MAX_FLOATABLE), 7)
|
650
|
-
assert_equal(-0.5, r.to_f)
|
651
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE ** 2), 7)
|
652
|
-
assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
|
653
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE, LongMath::MAX_FLOATABLE ** 2), 7)
|
654
|
-
assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
|
655
|
-
end
|
656
|
-
|
657
|
-
#
|
658
|
-
# test to_f of LongDecimalQuot with numerator.abs > Float::MAX and denominator.abs > Float::MAX
|
659
|
-
#
|
660
|
-
def test_ldq_to_f_big_numerator
|
661
|
-
print "\ntest_ldq_to_f_big_numerator [#{Time.now}]: "
|
662
|
-
# both beyond Float::MAX
|
663
|
-
delta = 1/Float::MAX
|
664
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE + 2, LongMath::MAX_FLOATABLE + 1), 7)
|
665
|
-
assert_equal(1.0, r.to_f)
|
666
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE - 2, LongMath::MAX_FLOATABLE + 1), 7)
|
667
|
-
assert_equal(-1.0, r.to_f)
|
668
|
-
unless RUBY_PLATFORM == 'java'
|
669
|
-
# skip this test in JRuby due to bugs in JRuby's Float
|
670
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE ** 3), 7)
|
671
|
-
assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
|
672
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE ** 2, LongMath::MAX_FLOATABLE ** 3), 7)
|
673
|
-
assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
|
674
|
-
end
|
675
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE ** 3, LongMath::MAX_FLOATABLE ** 2), 7)
|
676
|
-
assert_equal(Float::MAX, r.to_f)
|
677
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE ** 3, LongMath::MAX_FLOATABLE ** 2), 7)
|
678
|
-
assert_equal(-Float::MAX, r.to_f)
|
679
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE + 1, 2 * LongMath::MAX_FLOATABLE), 7)
|
680
|
-
assert_equal(0.5, r.to_f)
|
681
|
-
r = LongDecimalQuot(Rational(-(LongMath::MAX_FLOATABLE + 1), 2 * LongMath::MAX_FLOATABLE), 7)
|
682
|
-
assert_equal(-0.5, r.to_f)
|
683
|
-
unless RUBY_PLATFORM == 'java'
|
684
|
-
# skip this test in JRuby due to bugs in JRuby's Float
|
685
|
-
r = LongDecimalQuot(Rational(LongMath::MAX_FLOATABLE + 1, LongMath::MAX_FLOATABLE ** 2), 7)
|
686
|
-
assert_equal_float(1/Float::MAX, r.to_f, Float::MIN)
|
687
|
-
r = LongDecimalQuot(Rational(-LongMath::MAX_FLOATABLE - 1, LongMath::MAX_FLOATABLE ** 2), 7)
|
688
|
-
assert_equal_float(-1/Float::MAX, r.to_f, Float::MIN)
|
689
|
-
end
|
690
|
-
end
|
691
|
-
|
692
|
-
#
|
693
|
-
# test to_f of LongDecimalQuot with medium sized absolute value
|
694
|
-
#
|
695
|
-
def test_ldq_to_f_medium
|
696
|
-
print "\ntest_ldq_to_f_medium [#{Time.now}]: "
|
697
|
-
|
698
|
-
# use some value < 1 "in the middle"
|
699
|
-
f = 1.34078079299426e-126
|
700
|
-
n = 134078079299426
|
701
|
-
d = 10 ** 140
|
702
|
-
u = 10 ** 300
|
703
|
-
n2 = n ** 2
|
704
|
-
d2 = d ** 2
|
705
|
-
u2 = u ** 2
|
706
|
-
delta = 10 ** 135
|
707
|
-
f2 = 1/f
|
708
|
-
delta2 = 1/delta
|
709
|
-
r = LongDecimalQuot(Rational(n, d), 7)
|
710
|
-
assert_equal_float(f, r.to_f, delta)
|
711
|
-
r = LongDecimalQuot(Rational(d, n), 7)
|
712
|
-
assert_equal_float(f2, r.to_f, delta2)
|
713
|
-
r = LongDecimalQuot(Rational(n * d, d2), 7)
|
714
|
-
assert_equal_float(f, r.to_f, delta)
|
715
|
-
r = LongDecimalQuot(Rational(d2, n * d), 7)
|
716
|
-
assert_equal_float(f2, r.to_f, delta2)
|
717
|
-
r = LongDecimalQuot(Rational(n2, d * n), 7)
|
718
|
-
assert_equal_float(f, r.to_f, delta)
|
719
|
-
r = LongDecimalQuot(Rational(d * n, n2), 7)
|
720
|
-
assert_equal_float(f2, r.to_f, delta2)
|
721
|
-
r = LongDecimalQuot(Rational(n * u, d * u), 7)
|
722
|
-
assert_equal_float(f, r.to_f, delta)
|
723
|
-
r = LongDecimalQuot(Rational(d * u, n * u), 7)
|
724
|
-
assert_equal_float(f2, r.to_f, delta2)
|
725
|
-
r = LongDecimalQuot(Rational(n * u2, d * u2), 7)
|
726
|
-
assert_equal_float(f, r.to_f, delta)
|
727
|
-
r = LongDecimalQuot(Rational(d * u2, n * u2), 7)
|
728
|
-
assert_equal_float(f2, r.to_f, delta2)
|
729
|
-
|
730
|
-
# use some value > 1 "in the middle"
|
731
|
-
f = 1.34078079299426e+154
|
732
|
-
n = 134078079299426 * 10**154
|
733
|
-
d = 10 ** 14
|
734
|
-
n2 = n ** 2
|
735
|
-
d2 = d ** 2
|
736
|
-
delta = 10 ** 135
|
737
|
-
f2 = 1/f
|
738
|
-
delta2 = 1/delta
|
739
|
-
r = LongDecimalQuot(Rational(n, d), 7)
|
740
|
-
assert_equal_float(f, r.to_f, delta)
|
741
|
-
r = LongDecimalQuot(Rational(d, n), 7)
|
742
|
-
assert_equal_float(f2, r.to_f, delta2)
|
743
|
-
r = LongDecimalQuot(Rational(n * d, d2), 7)
|
744
|
-
assert_equal_float(f, r.to_f, delta)
|
745
|
-
r = LongDecimalQuot(Rational(d2, n * d), 7)
|
746
|
-
assert_equal_float(f2, r.to_f, delta2)
|
747
|
-
r = LongDecimalQuot(Rational(n2, d * n), 7)
|
748
|
-
assert_equal_float(f, r.to_f, delta)
|
749
|
-
r = LongDecimalQuot(Rational(d * n, n2), 7)
|
750
|
-
assert_equal_float(f2, r.to_f, delta2)
|
751
|
-
r = LongDecimalQuot(Rational(n * u, d * u), 7)
|
752
|
-
assert_equal_float(f, r.to_f, delta)
|
753
|
-
r = LongDecimalQuot(Rational(d * u, n * u), 7)
|
754
|
-
assert_equal_float(f2, r.to_f, delta2)
|
755
|
-
r = LongDecimalQuot(Rational(n * u2, d * u2), 7)
|
756
|
-
assert_equal_float(f, r.to_f, delta)
|
757
|
-
r = LongDecimalQuot(Rational(d * u2, n * u2), 7)
|
758
|
-
assert_equal_float(f2, r.to_f, delta2)
|
759
|
-
|
760
|
-
end
|
761
|
-
|
762
|
-
#
|
763
|
-
# test exp2 of LongMath
|
764
|
-
#
|
765
|
-
def test_exp2
|
766
|
-
print "\ntest_exp2 [#{Time.now}]: "
|
767
|
-
10.times do |i|
|
768
|
-
n = (i*i+i)/2
|
769
|
-
x = LongDecimal(n, 3*i)+LongMath.pi(20)
|
770
|
-
check_exp2_floated(x, n)
|
771
|
-
|
772
|
-
y = LongMath.exp2(x, n)
|
773
|
-
yy = LongMath.exp2(x, n + 5)
|
774
|
-
assert_equal(yy.round_to_scale(y.scale, LongDecimal::ROUND_HALF_DOWN), y, "x=#{x} y=#{y} yy=#{yy}")
|
775
|
-
z = LongMath.power(2, x, n)
|
776
|
-
assert_equal(z, y, "exp2 x=#{x} y=#{y} z=#{z} i=#{i} n=#{n}")
|
777
|
-
end
|
778
|
-
|
779
|
-
# random tests that have failed previously
|
780
|
-
check_exp2_floated(LongDecimal("-0.00147492625237084606064197462823289474038138852346725504592707365251736299180323394082648207114993022483949313246714392730651107673327728615912046468517225938833913598854936005"), 20)
|
781
|
-
|
782
|
-
end
|
783
|
-
|
784
|
-
#
|
785
|
-
# test the calculation of the exponential function where result is
|
786
|
-
# near zero
|
787
|
-
#
|
788
|
-
def test_exp2_near_zero
|
789
|
-
print "\ntest_exp2_near_zero [#{Time.now}]: "
|
790
|
-
|
791
|
-
x = LongDecimal(1, 100)
|
792
|
-
y = LongMath.log2(x, 100)
|
793
|
-
z = check_exp2_floated(y, 100)
|
794
|
-
assert_equal(x, z, "must be equal")
|
795
|
-
z = check_exp2_floated(y, 99)
|
796
|
-
assert(z.zero?, "must be zero")
|
797
|
-
z = check_exp2_floated(y * 100, 99)
|
798
|
-
assert(z.zero?, "must be zero")
|
799
|
-
|
800
|
-
end
|
801
|
-
|
802
|
-
#
|
803
|
-
# test exp10 of LongMath
|
804
|
-
#
|
805
|
-
def test_exp10
|
806
|
-
print "\ntest_exp10 [#{Time.now}]: "
|
807
|
-
10.times do |i|
|
808
|
-
n = (i*i+i)/2
|
809
|
-
x = LongDecimal(n, 3*i)+LongMath.pi(20)
|
810
|
-
check_exp10_floated(x, n)
|
811
|
-
|
812
|
-
y = LongMath.exp10(x, n)
|
813
|
-
yy = LongMath.exp10(x, n + 5)
|
814
|
-
assert_equal(yy.round_to_scale(y.scale, LongDecimal::ROUND_HALF_DOWN), y, "x=#{x} y=#{y} yy=#{yy}")
|
815
|
-
z = LongMath.power(10, x, n)
|
816
|
-
assert_equal(z, y, "exp10 x=#{x} y=#{y} z=#{z} i=#{i} n=#{n}")
|
817
|
-
end
|
818
|
-
end
|
819
|
-
|
820
|
-
#
|
821
|
-
# test the calculation of the exponential function where result is
|
822
|
-
# near zero
|
823
|
-
#
|
824
|
-
def test_exp10_near_zero
|
825
|
-
print "\ntest_exp10_near_zero [#{Time.now}]: "
|
826
|
-
|
827
|
-
x = LongDecimal(1, 100)
|
828
|
-
y = LongMath.log10(x, 100)
|
829
|
-
z = check_exp10_floated(y, 100)
|
830
|
-
assert_equal(x, z, "must be equal")
|
831
|
-
z = check_exp10_floated(y, 99)
|
832
|
-
assert(z.zero?, "must be zero")
|
833
|
-
z = check_exp10_floated(y * 100, 99)
|
834
|
-
assert(z.zero?, "must be zero")
|
835
|
-
|
836
|
-
end
|
837
|
-
|
838
|
-
#
|
839
|
-
# test LongMath.power for bases that can be expressed as integer
|
840
|
-
#
|
841
|
-
def test_lm_power_xint
|
842
|
-
print "\ntest_lm_power_xint [#{Time.now}]: "
|
843
|
-
|
844
|
-
xx = LongMath.log(3, 40)
|
845
|
-
pi = LongMath.pi(40)
|
846
|
-
sq = LongMath.sqrt(5, 40)
|
847
|
-
|
848
|
-
check_power_xint(2, 700.01, 10)
|
849
|
-
check_power_xint(2, 100.001, 10)
|
850
|
-
check_power_xint(2, 1.000000001, 10)
|
851
|
-
check_power_xint(2, 0.01, 10)
|
852
|
-
check_power_xint(2, 1e-10, 10)
|
853
|
-
check_power_xint(2, 1e-90, 10)
|
854
|
-
check_power_xint(2, 0, 10)
|
855
|
-
check_power_xint(2, -1.000000001, 10)
|
856
|
-
check_power_xint(2, -100.001, 10)
|
857
|
-
check_power_xint(2, -700.01, 10)
|
858
|
-
check_power_xint(2, xx, 10)
|
859
|
-
check_power_xint(2, pi, 10)
|
860
|
-
check_power_xint(2, sq, 10)
|
861
|
-
|
862
|
-
check_power_xint(10, 308.01, 10)
|
863
|
-
check_power_xint(10, 100.001, 10)
|
864
|
-
check_power_xint(10, 1.000000001, 10)
|
865
|
-
check_power_xint(10, 0.01, 10)
|
866
|
-
check_power_xint(10, 1e-10, 10)
|
867
|
-
check_power_xint(10, 1e-90, 10)
|
868
|
-
check_power_xint(10, 0, 10)
|
869
|
-
check_power_xint(10, -1.000000001, 10)
|
870
|
-
check_power_xint(10, -100.001, 10)
|
871
|
-
check_power_xint(10, -308.01, 10)
|
872
|
-
check_power_xint(10, xx, 10)
|
873
|
-
check_power_xint(10, pi, 10)
|
874
|
-
check_power_xint(10, sq, 10)
|
875
|
-
|
876
|
-
check_power_xint(2, 700.01, 100)
|
877
|
-
check_power_xint(2, 100.001, 100)
|
878
|
-
check_power_xint(2, 1.000000001, 100)
|
879
|
-
check_power_xint(2, 0.01, 100)
|
880
|
-
check_power_xint(2, 1e-10, 100)
|
881
|
-
check_power_xint(2, 1e-90, 100)
|
882
|
-
check_power_xint(2, 0, 100)
|
883
|
-
check_power_xint(2, -1.000000001, 100)
|
884
|
-
check_power_xint(2, -100.001, 100)
|
885
|
-
check_power_xint(2, -700.01, 100)
|
886
|
-
check_power_xint(2, xx, 100)
|
887
|
-
check_power_xint(2, pi, 100)
|
888
|
-
check_power_xint(2, sq, 100)
|
889
|
-
|
890
|
-
check_power_xint(10, 308.01, 100)
|
891
|
-
check_power_xint(10, 100.001, 100)
|
892
|
-
check_power_xint(10, 1.000000001, 100)
|
893
|
-
check_power_xint(10, 0.01, 100)
|
894
|
-
check_power_xint(10, 1e-10, 100)
|
895
|
-
check_power_xint(10, 1e-90, 100)
|
896
|
-
check_power_xint(10, 0, 100)
|
897
|
-
check_power_xint(10, -1.000000001, 100)
|
898
|
-
check_power_xint(10, -100.001, 100)
|
899
|
-
check_power_xint(10, -308.01, 100)
|
900
|
-
check_power_xint(10, xx, 100)
|
901
|
-
check_power_xint(10, pi, 100)
|
902
|
-
check_power_xint(10, sq, 100)
|
903
|
-
|
904
|
-
check_power_xint(2, 700.01, 40)
|
905
|
-
check_power_xint(2, 100.001, 40)
|
906
|
-
check_power_xint(2, 1.000000001, 40)
|
907
|
-
check_power_xint(2, 0.01, 40)
|
908
|
-
check_power_xint(2, 1e-10, 40)
|
909
|
-
check_power_xint(2, 1e-90, 40)
|
910
|
-
check_power_xint(2, 0, 40)
|
911
|
-
check_power_xint(2, -1.000000001, 40)
|
912
|
-
check_power_xint(2, -100.001, 40)
|
913
|
-
check_power_xint(2, -700.01, 40)
|
914
|
-
check_power_xint(2, xx, 40)
|
915
|
-
check_power_xint(2, pi, 40)
|
916
|
-
check_power_xint(2, sq, 40)
|
917
|
-
|
918
|
-
check_power_xint(10, 308.01, 40)
|
919
|
-
check_power_xint(10, 100.001, 40)
|
920
|
-
check_power_xint(10, 1.000000001, 40)
|
921
|
-
check_power_xint(10, 0.01, 40)
|
922
|
-
check_power_xint(10, 1e-10, 40)
|
923
|
-
check_power_xint(10, 1e-90, 40)
|
924
|
-
check_power_xint(10, 0, 40)
|
925
|
-
check_power_xint(10, -1.000000001, 40)
|
926
|
-
check_power_xint(10, -100.001, 40)
|
927
|
-
check_power_xint(10, -308.01, 40)
|
928
|
-
check_power_xint(10, xx, 40)
|
929
|
-
check_power_xint(10, pi, 40)
|
930
|
-
check_power_xint(10, sq, 40)
|
931
|
-
|
932
|
-
end
|
933
|
-
|
934
|
-
#
|
935
|
-
# test LongMath.power for bases that can be expressed as integer
|
936
|
-
#
|
937
|
-
def test_lm_power_yint
|
938
|
-
print "\ntest_lm_power_yint [#{Time.now}] (2 min): "
|
939
|
-
|
940
|
-
xx = LongMath.log(3, 40)
|
941
|
-
pi = LongMath.pi(40)
|
942
|
-
sq = LongMath.sqrt(5, 40)
|
943
|
-
|
944
|
-
check_power_yint(xx, 400, 10)
|
945
|
-
check_power_yint(xx, 100, 10)
|
946
|
-
check_power_yint(xx, 1, 10)
|
947
|
-
check_power_yint(xx, 0, 10)
|
948
|
-
check_power_yint(xx, -1, 10)
|
949
|
-
check_power_yint(xx, -100, 10)
|
950
|
-
check_power_yint(xx, -400, 10)
|
951
|
-
|
952
|
-
check_power_yint(pi, 400, 10)
|
953
|
-
check_power_yint(pi, 100, 10)
|
954
|
-
check_power_yint(pi, 1, 10)
|
955
|
-
check_power_yint(pi, 0, 10)
|
956
|
-
check_power_yint(pi, -1, 10)
|
957
|
-
check_power_yint(pi, -100, 10)
|
958
|
-
check_power_yint(pi, -400, 10)
|
959
|
-
|
960
|
-
check_power_yint(sq, 400, 10)
|
961
|
-
check_power_yint(sq, 100, 10)
|
962
|
-
check_power_yint(sq, 1, 10)
|
963
|
-
check_power_yint(sq, 0, 10)
|
964
|
-
check_power_yint(sq, -1, 10)
|
965
|
-
check_power_yint(sq, -100, 10)
|
966
|
-
check_power_yint(sq, -400, 10)
|
967
|
-
|
968
|
-
check_power_yint(xx, 400, 100)
|
969
|
-
check_power_yint(xx, 100, 100)
|
970
|
-
check_power_yint(xx, 1, 100)
|
971
|
-
check_power_yint(xx, 0, 100)
|
972
|
-
check_power_yint(xx, -1, 100)
|
973
|
-
check_power_yint(xx, -100, 100)
|
974
|
-
check_power_yint(xx, -400, 100)
|
975
|
-
|
976
|
-
check_power_yint(pi, 400, 100)
|
977
|
-
check_power_yint(pi, 100, 100)
|
978
|
-
check_power_yint(pi, 1, 100)
|
979
|
-
check_power_yint(pi, 0, 100)
|
980
|
-
check_power_yint(pi, -1, 100)
|
981
|
-
check_power_yint(pi, -100, 100)
|
982
|
-
check_power_yint(pi, -400, 100)
|
983
|
-
|
984
|
-
check_power_yint(sq, 400, 100)
|
985
|
-
check_power_yint(sq, 100, 100)
|
986
|
-
check_power_yint(sq, 1, 100)
|
987
|
-
check_power_yint(sq, 0, 100)
|
988
|
-
check_power_yint(sq, -1, 100)
|
989
|
-
check_power_yint(sq, -100, 100)
|
990
|
-
check_power_yint(sq, -400, 100)
|
991
|
-
|
992
|
-
check_power_yint(xx, 400, 40)
|
993
|
-
check_power_yint(xx, 100, 40)
|
994
|
-
check_power_yint(xx, 1, 40)
|
995
|
-
check_power_yint(xx, 0, 40)
|
996
|
-
check_power_yint(xx, -1, 40)
|
997
|
-
check_power_yint(xx, -100, 40)
|
998
|
-
check_power_yint(xx, -400, 40)
|
999
|
-
|
1000
|
-
check_power_yint(pi, 400, 40)
|
1001
|
-
check_power_yint(pi, 100, 40)
|
1002
|
-
check_power_yint(pi, 1, 40)
|
1003
|
-
check_power_yint(pi, 0, 40)
|
1004
|
-
check_power_yint(pi, -1, 40)
|
1005
|
-
check_power_yint(pi, -100, 40)
|
1006
|
-
check_power_yint(pi, -400, 40)
|
1007
|
-
|
1008
|
-
check_power_yint(sq, 400, 40)
|
1009
|
-
check_power_yint(sq, 100, 40)
|
1010
|
-
check_power_yint(sq, 1, 40)
|
1011
|
-
check_power_yint(sq, 0, 40)
|
1012
|
-
check_power_yint(sq, -1, 40)
|
1013
|
-
check_power_yint(sq, -100, 40)
|
1014
|
-
check_power_yint(sq, -400, 40)
|
1015
|
-
|
1016
|
-
end
|
1017
|
-
|
1018
|
-
#
|
1019
|
-
# test LongMath.power for bases that can be expressed as integer
|
1020
|
-
#
|
1021
|
-
def test_lm_power_yhalfint
|
1022
|
-
print "\ntest_lm_power_yhalfint [#{Time.now}] (10 min): "
|
1023
|
-
|
1024
|
-
xx = LongMath.log(3, 40)
|
1025
|
-
pi = LongMath.pi(40)
|
1026
|
-
sq = LongMath.sqrt(5, 40)
|
1027
|
-
|
1028
|
-
check_power_yhalfint(xx, 801, 10)
|
1029
|
-
check_power_yhalfint(xx, 799, 10)
|
1030
|
-
check_power_yhalfint(xx, 201, 10)
|
1031
|
-
check_power_yhalfint(xx, 3, 10)
|
1032
|
-
check_power_yhalfint(xx, 1, 10)
|
1033
|
-
check_power_yhalfint(xx, -1, 10)
|
1034
|
-
check_power_yhalfint(xx, -201, 10)
|
1035
|
-
check_power_yhalfint(xx, -799, 10)
|
1036
|
-
check_power_yhalfint(xx, -801, 10)
|
1037
|
-
|
1038
|
-
check_power_yhalfint(pi, 801, 10)
|
1039
|
-
check_power_yhalfint(pi, 799, 10)
|
1040
|
-
check_power_yhalfint(pi, 201, 10)
|
1041
|
-
check_power_yhalfint(pi, 3, 10)
|
1042
|
-
check_power_yhalfint(pi, 1, 10)
|
1043
|
-
check_power_yhalfint(pi, -1, 10)
|
1044
|
-
check_power_yhalfint(pi, -201, 10)
|
1045
|
-
check_power_yhalfint(pi, -799, 10)
|
1046
|
-
check_power_yhalfint(pi, -801, 10)
|
1047
|
-
|
1048
|
-
check_power_yhalfint(sq, 801, 10)
|
1049
|
-
check_power_yhalfint(sq, 799, 10)
|
1050
|
-
check_power_yhalfint(sq, 201, 10)
|
1051
|
-
check_power_yhalfint(sq, 3, 10)
|
1052
|
-
check_power_yhalfint(sq, 1, 10)
|
1053
|
-
check_power_yhalfint(sq, -1, 10)
|
1054
|
-
check_power_yhalfint(sq, -201, 10)
|
1055
|
-
check_power_yhalfint(sq, -799, 10)
|
1056
|
-
check_power_yhalfint(sq, -801, 10)
|
1057
|
-
|
1058
|
-
check_power_yhalfint(xx, 801, 40)
|
1059
|
-
check_power_yhalfint(xx, 799, 40)
|
1060
|
-
check_power_yhalfint(xx, 201, 40)
|
1061
|
-
check_power_yhalfint(xx, 3, 40)
|
1062
|
-
check_power_yhalfint(xx, 1, 40)
|
1063
|
-
check_power_yhalfint(xx, -1, 40)
|
1064
|
-
check_power_yhalfint(xx, -201, 40)
|
1065
|
-
check_power_yhalfint(xx, -799, 40)
|
1066
|
-
check_power_yhalfint(xx, -801, 40)
|
1067
|
-
|
1068
|
-
check_power_yhalfint(pi, 801, 40)
|
1069
|
-
check_power_yhalfint(pi, 799, 40)
|
1070
|
-
check_power_yhalfint(pi, 201, 40)
|
1071
|
-
check_power_yhalfint(pi, 3, 40)
|
1072
|
-
check_power_yhalfint(pi, 1, 40)
|
1073
|
-
check_power_yhalfint(pi, -1, 40)
|
1074
|
-
check_power_yhalfint(pi, -201, 40)
|
1075
|
-
check_power_yhalfint(pi, -799, 40)
|
1076
|
-
check_power_yhalfint(pi, -801, 40)
|
1077
|
-
|
1078
|
-
check_power_yhalfint(sq, 801, 40)
|
1079
|
-
check_power_yhalfint(sq, 799, 40)
|
1080
|
-
check_power_yhalfint(sq, 201, 40)
|
1081
|
-
check_power_yhalfint(sq, 3, 40)
|
1082
|
-
check_power_yhalfint(sq, 1, 40)
|
1083
|
-
check_power_yhalfint(sq, -1, 40)
|
1084
|
-
check_power_yhalfint(sq, -201, 40)
|
1085
|
-
check_power_yhalfint(sq, -799, 40)
|
1086
|
-
check_power_yhalfint(sq, -801, 40)
|
1087
|
-
|
1088
|
-
end
|
1089
|
-
|
1090
|
-
#
|
1091
|
-
# test LongMath.power with non-LongDecimal arguments
|
1092
|
-
#
|
1093
|
-
def test_non_ld_power
|
1094
|
-
print "\ntest_non_ld_power [#{Time.now}]: "
|
1095
|
-
xi = 77
|
1096
|
-
yi = 88
|
1097
|
-
zi = LongMath.power(xi, yi, 35)
|
1098
|
-
wi = (LongMath.log(zi, 40) / LongMath.log(xi, 40)).round_to_scale(30, LongMath::ROUND_HALF_EVEN)
|
1099
|
-
assert(wi.is_int?, "wi=#{wi} not int (zi=#{zi})")
|
1100
|
-
assert_equal(yi, wi.to_i, "zi=#{zi} wi=#{wi}")
|
1101
|
-
zj = LongMath.power_internal(xi, yi, 35)
|
1102
|
-
assert_equal(zi, zj, "internal power should yield the same result zi=#{zi} zj=#{zj}")
|
1103
|
-
|
1104
|
-
xf = 77.0
|
1105
|
-
yf = 88.0
|
1106
|
-
zf = LongMath.power(xf, yf, 35)
|
1107
|
-
wf = (LongMath.log(zf, 40) / LongMath.log(xf, 40)).round_to_scale(30, LongMath::ROUND_HALF_EVEN)
|
1108
|
-
assert(wf.is_int?, "wf=#{wf} not int (zf=#{zf} wi=#{wi} zi=#{zi}")
|
1109
|
-
assert_equal(yf, wf.to_i, "yf=#{yf} wf=#{yf}")
|
1110
|
-
|
1111
|
-
xr = Rational(224, 225)
|
1112
|
-
yr = Rational(168, 169)
|
1113
|
-
zr = LongMath.power(xr, yr, 35)
|
1114
|
-
wr = (LongMath.log(zr, 40) / LongMath.log(xr, 40)).round_to_scale(30, LongMath::ROUND_HALF_EVEN)
|
1115
|
-
assert((yr-wr).abs <= wr.unit, "wr-yr")
|
1116
|
-
end
|
1117
|
-
|
1118
|
-
#
|
1119
|
-
# test the calculation of the power-function of LongMath
|
1120
|
-
#
|
1121
|
-
def test_lm_power
|
1122
|
-
print "\ntest_lm_power [#{Time.now}]: "
|
1123
|
-
check_power_floated(1.001, 1.001, 10)
|
1124
|
-
check_power_floated(1.001, 2.001, 10)
|
1125
|
-
check_power_floated(2.001, 1.001, 10)
|
1126
|
-
check_power_floated(2.001, 2.001, 10)
|
1127
|
-
check_power_floated(100.001, 10.001, 10)
|
1128
|
-
check_power_floated(10.001, 100.001, 10)
|
1129
|
-
check_power_floated(10.001, 100.001, 100)
|
1130
|
-
check_power_floated(1e-20, 1.01, 19)
|
1131
|
-
check_power_floated(1.01, 1e-20, 19)
|
1132
|
-
check_power_floated(1e-20, 1.01, 20)
|
1133
|
-
check_power_floated(1.01, 1e-20, 20)
|
1134
|
-
check_power_floated(1e-20, 1.01, 21)
|
1135
|
-
check_power_floated(1.01, 1e-20, 21)
|
1136
|
-
|
1137
|
-
check_power_floated(1.001, -1.001, 10)
|
1138
|
-
check_power_floated(1.001, -2.001, 10)
|
1139
|
-
check_power_floated(2.001, -1.001, 10)
|
1140
|
-
check_power_floated(2.001, -2.001, 10)
|
1141
|
-
check_power_floated(100.001, -10.001, 10)
|
1142
|
-
check_power_floated(10.001, -100.001, 10)
|
1143
|
-
check_power_floated(1e-20, -1.01, 19)
|
1144
|
-
check_power_floated(1.01, -1e-20, 19)
|
1145
|
-
check_power_floated(1e-20, -1.01, 20)
|
1146
|
-
check_power_floated(1.01, -1e-20, 20)
|
1147
|
-
check_power_floated(1e-20, -1.01, 21)
|
1148
|
-
check_power_floated(1.01, -1e-20, 21)
|
1149
|
-
|
1150
|
-
# random tests that have failed
|
1151
|
-
end
|
1152
|
-
|
1153
|
-
def test_lm_power0a
|
1154
|
-
print "\ntest_lm_power0a [#{Time.now}]: "
|
1155
|
-
check_power_floated(LongDecimal("0.000000000077517987624900000000000000000000000000000000000000000000000000000000000000000000000000000014809051260000000000000000000000000000000000000000000000000000000000000000000000000000000000707281"),
|
1156
|
-
LongDecimal("26.627053911388694974442854299008649887946027550330988420533923061901183724914978160564862753777080769340"),
|
1157
|
-
29)
|
1158
|
-
puts "a"
|
1159
|
-
end
|
1160
|
-
|
1161
|
-
def test_lm_power0b
|
1162
|
-
print "\ntest_lm_power0b [#{Time.now}]: "
|
1163
|
-
check_power_floated(LongDecimal("1.000000000000000151000000000000000000000000000000000000000000000000000000000000057800000000205"),
|
1164
|
-
LongDecimal("-680.0000000000000000000013100000000000000000000000000000000000000165000000000000000000234"),
|
1165
|
-
26)
|
1166
|
-
puts "b"
|
1167
|
-
end
|
1168
|
-
|
1169
|
-
def test_lm_power0c
|
1170
|
-
print "\ntest_lm_power0c [#{Time.now}]: "
|
1171
|
-
check_power_floated(LongDecimal("1.0000000000000000000000000000000000000000000068000000000853000000000926"),
|
1172
|
-
LongDecimal("-536.000000000086100000000000000000000000000019200000000000000000000000000000000000000000000000166"),
|
1173
|
-
49)
|
1174
|
-
puts "c"
|
1175
|
-
end
|
1176
|
-
|
1177
|
-
def test_lm_power0d
|
1178
|
-
print "\ntest_lm_power0d [#{Time.now}]: "
|
1179
|
-
check_power_floated(LongDecimal("1.0000000000000000049000000000002090000000000447"),
|
1180
|
-
LongDecimal("-328.00000000000000000000000000000000567000000000000000026600000000000000000000000679"),
|
1181
|
-
24)
|
1182
|
-
puts "d"
|
1183
|
-
end
|
1184
|
-
|
1185
|
-
def test_lm_power0e
|
1186
|
-
print "\ntest_lm_power0e [#{Time.now}]: "
|
1187
|
-
check_power_floated(LongDecimal("1.0000000000000000000003580000000000000000000000376238"),
|
1188
|
-
LongDecimal("-359.0000000003910721000000000000000000000000000000000000000000000000000000000000000000000000479"),
|
1189
|
-
39)
|
1190
|
-
puts "e"
|
1191
|
-
end
|
1192
|
-
|
1193
|
-
def test_lm_power0f
|
1194
|
-
print "\ntest_lm_power0f [#{Time.now}]: "
|
1195
|
-
check_power_floated(LongDecimal("1.000000000000000000000032000000001500000000000000000000439"),
|
1196
|
-
LongDecimal("-252.00000000000000025500000000000176907"),
|
1197
|
-
39)
|
1198
|
-
puts "f"
|
1199
|
-
end
|
1200
|
-
|
1201
|
-
def test_lm_power0g
|
1202
|
-
print "\ntest_lm_power0g [#{Time.now}]: "
|
1203
|
-
check_power_floated(LongDecimal("1.0000000000000008590000521000000000000621"),
|
1204
|
-
LongDecimal("-135.0000000000000000000000000000000000000000000000000000000074400000000000000000000000000321"),
|
1205
|
-
50)
|
1206
|
-
puts "g"
|
1207
|
-
end
|
1208
|
-
|
1209
|
-
def test_lm_power0h
|
1210
|
-
print "\ntest_lm_power0h [#{Time.now}]: "
|
1211
|
-
check_power_floated(LongDecimal("1.000000000000000151000000000000000000000000000000000000000000000000000000000000057800000000205"),
|
1212
|
-
LongDecimal("-680.0000000000000000000013100000000000000000000000000000000000000165000000000000000000234"),
|
1213
|
-
26)
|
1214
|
-
puts "h"
|
1215
|
-
end
|
1216
|
-
|
1217
|
-
def test_lm_power0i
|
1218
|
-
print "\ntest_lm_power0i [#{Time.now}]: "
|
1219
|
-
check_power_floated(LongDecimal("1.02350000000000000000000356000000000000000000000000000000000000000000000000000000000104"),
|
1220
|
-
LongDecimal("-971.0000000000000000055400000000000000000000000000000000000000000000000000040900000000000000000000000603"),
|
1221
|
-
45)
|
1222
|
-
puts "i"
|
1223
|
-
end
|
1224
|
-
|
1225
|
-
def test_lm_power0j
|
1226
|
-
print "\ntest_lm_power0j [#{Time.now}]: "
|
1227
|
-
check_power_floated(LongDecimal("1.0023800000000000000000000000000000000000000000000000000000000000265000000000000000000000000000000453"),
|
1228
|
-
LongDecimal("-277.000000000000000000000000000000000000000000000000000000000000113000000000000000000041400000294"),
|
1229
|
-
22)
|
1230
|
-
puts "j"
|
1231
|
-
end
|
1232
|
-
|
1233
|
-
def test_lm_power0k
|
1234
|
-
print "\ntest_lm_power0k [#{Time.now}]: "
|
1235
|
-
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003422250001093950095910422515315300670761"),
|
1236
|
-
LongDecimal("-0.99999999999999999999999999999999999999999999999999997909999999999999999999999999667999957000000000000000065521500000000000000000000020816402696099999999999997719321110428280027729999999129874367303020000000000071412895105695789681563000036363932570289984431712381817869482773696988055442648559706239710901091550702341077381290973316336980640165855210736680"),
|
1237
|
-
46)
|
1238
|
-
puts "k"
|
1239
|
-
end
|
1240
|
-
|
1241
|
-
def test_lm_power0l
|
1242
|
-
print "\ntest_lm_power0l [#{Time.now}]: "
|
1243
|
-
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000049273899694369"),
|
1244
|
-
LongDecimal("-0.99999999999999999999999999999999999999988899963450000000000000000000000000000001847988671170038537499999999999999999999658146648184996349480690906250000000000066400422857493760370353798820585648437488207957808220483456569835670219978619056054192244103752969215743872596800486621906638928959243058783356441503226136251748249991020724187893339868"),
|
1245
|
-
40)
|
1246
|
-
puts "l"
|
1247
|
-
end
|
1248
|
-
|
1249
|
-
def test_lm_power0m
|
1250
|
-
print "\ntest_lm_power0m [#{Time.now}]: "
|
1251
|
-
check_power_floated(LongDecimal("0.0000000000000000000000000000003868840000000000000000000328416000000000000000000006969600000000000000000000000000000059338800000000000000000002518560000000000000000000000000000000000000000000000000000000227529"),
|
1252
|
-
LongDecimal("-0.999999999999999999999999999999999999999999999999999998264999999999999999999999999999616741000000000000000004515337500000000000000000000001994863094999999999999986943149282831191620999999999993077825060350000000000033980453035745280148525000000024019946927993617107497210600671335038418031107762499920991889855598841096454678838495791189026426859181655270271342"),
|
1253
|
-
31)
|
1254
|
-
puts "m"
|
1255
|
-
end
|
1256
|
-
|
1257
|
-
def test_lm_power0n
|
1258
|
-
print "\ntest_lm_power0n [#{Time.now}]: "
|
1259
|
-
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000435600000000000000000000000000000000000000000000000006204000000075240000000000000000000000000000000000000022090000000535800000003249"),
|
1260
|
-
LongDecimal("-4.50377349099168904759987513420506734335755704389619751192197520413005925604849718759451665302464588879636922713303481423460050066204079523260315868192642742903330525895063299416"),
|
1261
|
-
20)
|
1262
|
-
puts "n"
|
1263
|
-
end
|
1264
|
-
|
1265
|
-
def test_lm_power0o
|
1266
|
-
print "\ntest_lm_power0o [#{Time.now}]: "
|
1267
|
-
check_power_floated(LongDecimal("0.0000000000000000000000000000700720943029391693947940220429504569709269190190365416713568"),
|
1268
|
-
LongDecimal("-6.633249580710799698229865473341373367854177091179010213018664944871230"),
|
1269
|
-
7)
|
1270
|
-
puts "o"
|
1271
|
-
end
|
1272
|
-
|
1273
|
-
def test_lm_power0p
|
1274
|
-
print "\ntest_lm_power0p [#{Time.now}]: "
|
1275
|
-
check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000816700000697"),
|
1276
|
-
LongDecimal("-0.58685446009389671361502347417840375586854460093896713614906034406753510106019528753113359342280707917300359276157963863070992095386428055722936293804476401957909668625460628698383384886591034139"),
|
1277
|
-
36)
|
1278
|
-
puts "p"
|
1279
|
-
end
|
1280
|
-
|
1281
|
-
def test_lm_power0q
|
1282
|
-
print "\ntest_lm_power0q [#{Time.now}]: "
|
1283
|
-
check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
|
1284
|
-
LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
|
1285
|
-
3)
|
1286
|
-
puts "q"
|
1287
|
-
end
|
1288
|
-
|
1289
|
-
def test_lm_power0r
|
1290
|
-
print "\ntest_lm_power0r [#{Time.now}]: "
|
1291
|
-
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000002450257484405715360000000000000000097614149083200000000000000000000000972196"),
|
1292
|
-
LongDecimal("-1.00000008600000184900000000000000000000000000000000000000012640000543520000000000000000000013300000571900000000000000399424000000000000000000000000000840560000000000000000000000000000442225"),
|
1293
|
-
3)
|
1294
|
-
puts "r"
|
1295
|
-
end
|
1296
|
-
|
1297
|
-
def test_lm_power0s
|
1298
|
-
print "\ntest_lm_power0s [#{Time.now}]: "
|
1299
|
-
check_power_floated(LongDecimal("0.00000000000000000000000000000000000000000000000000000000000000000000367236000000000000000093202800000000000000005914074196000000000000000058905400000000000000000000146689"),
|
1300
|
-
LongDecimal("-1.000000000008800000000019360000000062800000000276320250000000001100000985960000000000007850000000000000015625"),
|
1301
|
-
4)
|
1302
|
-
puts "s"
|
1303
|
-
end
|
1304
|
-
|
1305
|
-
def test_lm_power0t
|
1306
|
-
print "\ntest_lm_power0t [#{Time.now}]: "
|
1307
|
-
check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000000000000000000000000000002777290000000006513720000000003819240000000000000000000000000000100340800000000117667200000000000000000000000000000000000000000000906304"),
|
1308
|
-
LongDecimal("-0.5773502691896257645091447198050641552797247036332110311421498194545129249630222981047763195372146430879281215100223411775138874331819083544781222838698051829302865547075365868655847179043571799566074987574406310154782766513220296853158689786573196010629608653145605201822170964422894732870490642190250948498852022304300879727510280657218553"),
|
1309
|
-
23)
|
1310
|
-
puts "t"
|
1311
|
-
end
|
1312
|
-
|
1313
|
-
def test_lm_power0u
|
1314
|
-
print "\ntest_lm_power0u [#{Time.now}]: "
|
1315
|
-
check_power_floated(LongDecimal("0.000000000000000000000000000000000000000000007350000295000915"),
|
1316
|
-
LongDecimal("-1.000002193000861"),
|
1317
|
-
2)
|
1318
|
-
puts "u"
|
1319
|
-
end
|
1320
|
-
|
1321
|
-
def test_lm_power0v
|
1322
|
-
print "\ntest_lm_power0v [#{Time.now}]: "
|
1323
|
-
check_power_floated(LongDecimal("0.0000000086862400000000000000015172960006039360000000662596000527472000104976"),
|
1324
|
-
LongDecimal("-0.999999999999999999999999999999999999999999999999999999999997169999999999996784999999999687000000000000000000000000000012013350000000027295350000002672874337500003018885000000146896669625999999845508318999984783776699499965759759873248317316431267825611053489338193758007138415641516991908731376997678345955102618540146326218008264916981179817214058767402196571"),
|
1325
|
-
11)
|
1326
|
-
puts "v"
|
1327
|
-
end
|
1328
|
-
|
1329
|
-
def test_lm_power0w
|
1330
|
-
print "\ntest_lm_power0w [#{Time.now}]: "
|
1331
|
-
check_power_floated(LongDecimal("0.00000000000000000000000000624000383000000000000000000000000000000000000000000000358"),
|
1332
|
-
LongDecimal("-1.0000004600000000000000000000000000000004210"),
|
1333
|
-
3)
|
1334
|
-
puts "w"
|
1335
|
-
end
|
1336
|
-
|
1337
|
-
def test_lm_power0x
|
1338
|
-
print "\ntest_lm_power0x [#{Time.now}]: "
|
1339
|
-
check_power_floated(LongDecimal("0.00000000006236994468492015585972291475115698519825552824875948893004062366348813472156776148562881057978611940708477498267201430163921921918813918304834563518614088250202460271818014152969"),
|
1340
|
-
LongDecimal("-21.81742422927144044215775880732087497227530694228658299334049542576403906256739064739549866577137008231569804502022381108724983114382624747999460445291671084230968250529511708947428208082234"),
|
1341
|
-
6)
|
1342
|
-
puts "x"
|
1343
|
-
end
|
1344
|
-
|
1345
|
-
def test_lm_power0y
|
1346
|
-
print "\ntest_lm_power0y [#{Time.now}]: "
|
1347
|
-
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000035600000000928000000000000000450"),
|
1348
|
-
LongDecimal("-0.70821529745042492917661444999959874487397062785764977666003279651340417551441776107007487983685090756343178115766012078677210548592741818458068450268168492334992979756923"),
|
1349
|
-
13)
|
1350
|
-
puts "y"
|
1351
|
-
end
|
1352
|
-
|
1353
|
-
def test_lm_power0z
|
1354
|
-
print "\ntest_lm_power0z [#{Time.now}]: "
|
1355
|
-
check_power_floated(LongDecimal("0.0000000000000000000000000000025900000000000000000000000000000000000000000022100000000000000000032"),
|
1356
|
-
LongDecimal("-0.999943403203378688766215832183174473300891276419706031790088430934495839737458766990116492"),
|
1357
|
-
4)
|
1358
|
-
puts "z"
|
1359
|
-
end
|
1360
|
-
|
1361
|
-
def test_lm_power1a
|
1362
|
-
print "\ntest_lm_power1a [#{Time.now}]: "
|
1363
|
-
check_power_floated(LongDecimal("0.002658925294303146195800785280451092866235470739838791730450519159432915"),
|
1364
|
-
LongDecimal("-87.0000000000000008330000000000000000000000000000000000000000000000000000000000000000000000000092046"),
|
1365
|
-
90)
|
1366
|
-
puts "a"
|
1367
|
-
end
|
1368
|
-
|
1369
|
-
def test_lm_power1b
|
1370
|
-
print "\ntest_lm_power1b [#{Time.now}]: "
|
1371
|
-
check_power_floated(LongDecimal("0.0014814814814814814812905349794238683127818125285779606767229367555739725854802645575188374989810195213530274617178142875856830586369415448003164084698537116523550097"),
|
1372
|
-
LongDecimal("-52.0000000000000000000000000000000000000000683000000000000000000238000000000228"),
|
1373
|
-
25)
|
1374
|
-
puts "b"
|
1375
|
-
end
|
1376
|
-
|
1377
|
-
def test_lm_power1c
|
1378
|
-
print "\ntest_lm_power1c [#{Time.now}]: "
|
1379
|
-
check_power_floated(LongDecimal("0.00000000000000000000047400000000000000000084700000892"),
|
1380
|
-
LongDecimal("-17.000000001310000000000000000000000000000000000000000000000000002800000000000000217"),
|
1381
|
-
56)
|
1382
|
-
puts "c"
|
1383
|
-
end
|
1384
|
-
|
1385
|
-
def test_lm_power1d
|
1386
|
-
print "\ntest_lm_power1d [#{Time.now}]: "
|
1387
|
-
check_power_floated(LongDecimal("0.00000000000000000000005110000000000000000004800000000000000000000000000000163"),
|
1388
|
-
LongDecimal("-37.000000009170000000000000000000000000000000000000000000000000000000000000055800048"),
|
1389
|
-
21)
|
1390
|
-
puts "d"
|
1391
|
-
end
|
1392
|
-
|
1393
|
-
# SLOW!!!
|
1394
|
-
def _test_lm_power1e
|
1395
|
-
print "\ntest_lm_power1e [#{Time.now}] (2 hours): "
|
1396
|
-
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000002450257484405715360000000000000000097614149083200000000000000000000000972196"),
|
1397
|
-
LongDecimal("-1.00000008600000184900000000000000000000000000000000000000012640000543520000000000000000000013300000571900000000000000399424000000000000000000000000000840560000000000000000000000000000442225"),
|
1398
|
-
3)
|
1399
|
-
puts "e"
|
1400
|
-
end
|
1401
|
-
|
1402
|
-
# SLOW!!!
|
1403
|
-
def _test_lm_power1f
|
1404
|
-
print "\ntest_lm_power1f [#{Time.now}] (2 hours): "
|
1405
|
-
check_power_floated(LongDecimal("0.999999999999983820000000000052544300000001372125483999980457478288050051600649560171986452284020178492146835403829341250837967306416835643061512149984415283328897050537606939603101940467080257495289168053434691062993302374332577706782680685214083677104079828206433042861334386773091111658939537092356816922764138900649581031721453211835260155666851398044388924204855221543729490461274063089475188763279119570"),
|
1406
|
-
LongDecimal("80321932.89024988628926432624765785135567744505377819122460049392916097399960142838065367057138986526363804"),
|
1407
|
-
40)
|
1408
|
-
puts "f"
|
1409
|
-
end
|
1410
|
-
|
1411
|
-
# SLOW!!!
|
1412
|
-
def _test_lm_power1g
|
1413
|
-
print "\ntest_lm_power1g [#{Time.now}] (3 hours): "
|
1414
|
-
check_power_floated(LongDecimal("0.999999999999999999999999999999998351999999999999983020000000000002036927999998210041974559999999997978335404004424810825925120045592892314014072707890311225042124730264194167337496376801852022987153782535008598977724682635285958668331865904517437818865287190004735483899633845078360662820274644903126498781970492928578903950"),
|
1415
|
-
LongDecimal("24449877750611246943765281173.594132029339853300733454400081300326994697544849684064538112517261374573394648075725881734888526076256999828217542217625441301525934675012853453406806380262764050867999"),
|
1416
|
-
5)
|
1417
|
-
puts "g"
|
1418
|
-
end
|
1419
|
-
|
1420
|
-
# FAILURE!!! (needs to be fixed)
|
1421
|
-
def test_lm_power1h
|
1422
|
-
# 32) Failure:
|
1423
|
-
# test_lm_power1h(TestLongDecimalExtra_class) [/home/bk1/ruby/long-decimal/ruby/long-decimal/test/testlongdeclib.rb:537]:
|
1424
|
-
# u=log(z,7)=0.0000000 and yv=y*v=y*log(x,67)=-0.0000785 should be almost equal (unit=0.0000001 x=0.9999999999999999999999999999999999999999999999999999999999999992419999999999601999999916300000000000000000000000000000000000005745640000000603368000126905040400006662520000700569 y=103626942927112137297398420916877844574257389450065434211636.290893349001885021464207122860891972260613740163376239637940672943781241170230437221414760788160997546494517494155287108299429330120640311594334671250673655216674953919962963363315956632 z=1.0000000 u=0.0000000 v=-0.0000000000000000000000000000000000000000000000000000000000000007580 lprec=7 prec=7)
|
1425
|
-
|
1426
|
-
print "\ntest_lm_power1h [#{Time.now}]: "
|
1427
|
-
check_power_floated(LongDecimal("0.999999999999999862599981980000014159073713922242243328677707050386499779178242565766291900177208859765599761583988066205590104341111429059119646260524293805643133602429678974677397380813589741657940554009198199034562447106122960905140273768835224006261013069576237942279008951360618433986"),
|
1428
|
-
LongDecimal("10266940451745.37987679671457905534956086166404546967839388790271998098584221166751699838745542116653920000125768690393028114699714286512441385099525"),
|
1429
|
-
14)
|
1430
|
-
puts "h"
|
1431
|
-
end
|
1432
|
-
|
1433
|
-
# FAILURE!!! (needs to be fixed)
|
1434
|
-
def test_lm_power1i
|
1435
|
-
# 33) Failure:
|
1436
|
-
# test_lm_power1i(TestLongDecimalExtra_class) [/home/bk1/ruby/long-decimal/ruby/long-decimal/test/testlongdeclib.rb:537]:
|
1437
|
-
# u=log(z,13)=-0.0111941165167 and yv=y*v=y*log(x,76)=-0.0111941184373 should be almost equal (unit=0.0000000000001 x=1.000000000000000000000000000000000000000000000000000000000000000040632256971361441675364911547119523862617306023293961145667519711601390076843063624462699881424344873551296525030641685492629965401733250018815534188264352396285608689080041860127898254008134983805964167477328233064049446442345195928792206909976566059881698019 y=-275498317635275642242287018621310530812854589333829844444179465.026486828659378492893391926808279692889516447254926463357381523771105223660032617000227932272791794838690719013665737808233622061943268216888533855404111493288875534126178784830550654618969484969704069638284634725831920698820381864995363361738394367829090059556279914810540013438298547827401014937988931120431027937060054429855616000850263332145848273205542636020219974448846631834726343291615390210989854686573686051987947338952241558404158600234046969306176292822304779868899689391647661253521411090531104030615753856329486732170039585239348687257061864897478622958348189113878179294939392893585430107561210696450698403851795968372396462047808473453132852141249623740994995021422532249082127739 z=0.98886830447251 u=-0.0111941165167 v=0.0000000000000000000000000000000000000000000000000000000000000000406322569714 lprec=13 prec=14)
|
1438
|
-
print "\ntest_lm_power1i [#{Time.now}]: "
|
1439
|
-
check_power_floated(LongDecimal("0.999999999999999981500000000000000256687499999999996834187500000000036604706930449997823687754750325053502286291757658419972795166437108241085949094447949893401640711985948839881287077716265593625727522425306777978451009970778400655052736724232660803755458234164496101454557290134193942433026948513566480800350007916601440691706219670728270104113540"),
|
1440
|
-
LongDecimal("41380294430118397.455148144857963343847598908617723236165122243380531570432704458595232182042029429597565318650987561380534985825811466980798564531839364855305381553585381037046185516421336524897364607404185776449463"),
|
1441
|
-
26)
|
1442
|
-
puts "i"
|
1443
|
-
end
|
1444
|
-
|
1445
|
-
def test_lm_power1j
|
1446
|
-
print "\ntest_lm_power1j [#{Time.now}]: "
|
1447
|
-
check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
|
1448
|
-
LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
|
1449
|
-
23)
|
1450
|
-
puts "j"
|
1451
|
-
end
|
1452
|
-
|
1453
|
-
def test_lm_power1k
|
1454
|
-
print "\ntest_lm_power1k [#{Time.now}]: "
|
1455
|
-
check_power_floated(LongDecimal("0.999999955000001687499940937501993359309219142762877860969997307557898777919131305606255214050322693251861572813240921773249050643887299214365089256902862200379712695062301304665207421015981915226866332635406597037254705387928614026219686983926304930980563519261869550253533841712248417739856791299844197817284010721773168197981077997089850680475101280715114294984559298890080189837019"),
|
1456
|
-
LongDecimal("1152073732.71889400921658986175115207373271889400921658986175115207373271192582125814946165771199218501136146446091443861623733780713117713266372156187325484891985619348320999757983534072600830"),
|
1457
|
-
34)
|
1458
|
-
puts "k"
|
1459
|
-
end
|
1460
|
-
|
1461
|
-
def test_lm_power1l
|
1462
|
-
print "\ntest_lm_power1l [#{Time.now}]: "
|
1463
|
-
check_power_floated(LongDecimal("0.9999999999999999790000000000000003307499999999999953571199999534000611652825014678992260416924691741095240984082153184971715719141172674714489939586322093325704050326051366867179642182008596501250357001333611677371975442553576183439891558582498678369021915"),
|
1464
|
-
LongDecimal("723078346985052524411124.9942153732241195797916759141992675639370468905781573122561996247342863251769951237981444054472420932945762836317152649920140953979776753551488373967949714070011978110437743347922047335540909708006357292133505068791464115479823527616"),
|
1465
|
-
12);
|
1466
|
-
puts "l"
|
1467
|
-
end
|
1468
|
-
|
1469
|
-
def test_lm_power1m
|
1470
|
-
print "\ntest_lm_power1m [#{Time.now}]: "
|
1471
|
-
check_power_floated(LongDecimal("0.0000000496000000000000000000000005130181"),
|
1472
|
-
LongDecimal("4.481689070338064822602055460119275819005749868369667078288462665422608992659321754902779723364868999617977618563052671037918163226699981361015453605440282335627715767767332447975568034896269722320687889640"),
|
1473
|
-
53)
|
1474
|
-
puts "m"
|
1475
|
-
end
|
1476
|
-
|
1477
|
-
def test_lm_power1n
|
1478
|
-
print "\ntest_lm_power1n [#{Time.now}]: "
|
1479
|
-
check_power_floated(LongDecimal("0.99999996920000071147998520954428850500259566957301785488841492770856751549533360159782111532707660143588897363762546661839650329823327036644"),
|
1480
|
-
LongDecimal("5136654.9693748423207184796146471922038482162171466427358132415227272949550162107575"),
|
1481
|
-
35)
|
1482
|
-
puts "n"
|
1483
|
-
end
|
1484
|
-
|
1485
|
-
def test_lm_power1o
|
1486
|
-
print "\ntest_lm_power1o [#{Time.now}]: "
|
1487
|
-
check_power_floated(LongDecimal("0.999999999999999999999999999999999999999999999999990849999999999997459999999999999999999999999999514083722500000000046482000000000006451600000000008893033939125002468242034549999999822903580000236058"),
|
1488
|
-
LongDecimal("0.0000000000000000000000000000000"),
|
1489
|
-
20)
|
1490
|
-
puts "o"
|
1491
|
-
end
|
1492
|
-
|
1493
|
-
def test_lm_power1p
|
1494
|
-
print "\ntest_lm_power1p [#{Time.now}]: "
|
1495
|
-
check_power_floated(LongDecimal("0.999999999999999999999999999999999999999999999999990849999999999997459999999999999999999999999999514083722500000000046482000000000006451600000000008893033939125002468242034549999999822903580000236058"),
|
1496
|
-
LongDecimal("0.0000000000000000000000000000000"),
|
1497
|
-
40)
|
1498
|
-
puts "p"
|
1499
|
-
end
|
1500
|
-
|
1501
|
-
def test_lm_power1q
|
1502
|
-
print "\ntest_lm_power1q [#{Time.now}]: "
|
1503
|
-
check_power_floated(LongDecimal("0.999999999999999999999999999999999999999999999999990849999999999997459999999999999999999999999999514083722500000000046482000000000006451600000000008893033939125002468242034549999999822903580000236058"),
|
1504
|
-
LongDecimal("0.0000000000000000000000000000000"),
|
1505
|
-
6)
|
1506
|
-
puts "q"
|
1507
|
-
end
|
1508
|
-
|
1509
|
-
def test_lm_power1r
|
1510
|
-
print "\ntest_lm_power1r [#{Time.now}]: "
|
1511
|
-
check_power_floated(LongDecimal("0.9999998980000104039989387921082432049591930941623043954449516646149302092771178487340615327073490985245976137220657507850136754851390337493573677445898517902642450071877694654887775650"),
|
1512
|
-
LongDecimal("-0.00000010199999479800035373597293919820816141870627986580"),
|
1513
|
-
20)
|
1514
|
-
puts "r"
|
1515
|
-
end
|
1516
|
-
|
1517
|
-
def test_lm_power1s
|
1518
|
-
print "\ntest_lm_power1s [#{Time.now}]: "
|
1519
|
-
check_power_floated(LongDecimal("0.9999998980000104039989387921082432049591930941623043954449516646149302092771178487340615327073490985245976137220657507850136754851390337493573677445898517902642450071877694654887775650"),
|
1520
|
-
LongDecimal("-0.00000010199999479800035373597293919820816141870627986580"),
|
1521
|
-
40)
|
1522
|
-
puts "s"
|
1523
|
-
end
|
1524
|
-
|
1525
|
-
def test_lm_power1t
|
1526
|
-
print "\ntest_lm_power1t [#{Time.now}]: "
|
1527
|
-
check_power_floated(LongDecimal("0.9999998980000104039989387921082432049591930941623043954449516646149302092771178487340615327073490985245976137220657507850136754851390337493573677445898517902642450071877694654887775650"),
|
1528
|
-
LongDecimal("-0.00000010199999479800035373597293919820816141870627986580"),
|
1529
|
-
60)
|
1530
|
-
puts "t"
|
1531
|
-
end
|
1532
|
-
|
1533
|
-
# SLOW!!!
|
1534
|
-
def _test_lm_power1u
|
1535
|
-
print "\ntest_lm_power1u [#{Time.now}] (2 hours): "
|
1536
|
-
check_power_floated(LongDecimal("0.99999999999999999999999999999999999999999999999999992269999999999999999990289999999999999999450000000000597529000000000000001501166000000000000085972840999953811008406809999999825939805325"),
|
1537
|
-
LongDecimal("714285714285714285714285714.2857142367346938756989795918367346938775543790087466096793002963472667638481661974177164821324438268046647105967619250931245847564869975795833510071"),
|
1538
|
-
25)
|
1539
|
-
puts "u"
|
1540
|
-
end
|
1541
|
-
|
1542
|
-
# SLOW!!!
|
1543
|
-
def _test_lm_power1v
|
1544
|
-
print "\ntest_lm_power1v [#{Time.now}] (2 hours): "
|
1545
|
-
check_power_floated(LongDecimal("0.999999999999999999072867000000000000859575599688999999203059095533538363738068211580703976213177165458547180420859035425970198975506846513796073745523480165"),
|
1546
|
-
LongDecimal("34260010678356060340110500.7153234888531563303375970232929042708037751160246890208435860708347495272359620209409070219221760532838693330228630931194027855701638117625325214394917620590686906959334466842413732434252133614001314264745394120941492068918606855981807681794442879762888899961878810388388032398007558964413624601333106812667470835155455035290542870179962369969203293410746331815980"),
|
1547
|
-
4)
|
1548
|
-
puts "v"
|
1549
|
-
end
|
1550
|
-
|
1551
|
-
def test_lm_power1w
|
1552
|
-
print "\ntest_lm_power1w [#{Time.now}]: "
|
1553
|
-
check_power_floated(LongDecimal("0.999999955000001687499940937501993359309219142762877860969997307557898777919131305606255214050322693251861572813240921773249050643887299214365089256902862200379712695062301304665207421015981915226866332635406597037254705387928614026219686983926304930980563519261869550253533841712248417739856791299844197817284010721773168197981077997089850680475101280715114294984559298890080189837019"),
|
1554
|
-
LongDecimal("1152073732.71889400921658986175115207373271889400921658986175115207373271192582125814946165771199218501136146446091443861623733780713117713266372156187325484891985619348320999757983534072600830"),
|
1555
|
-
34)
|
1556
|
-
puts "w"
|
1557
|
-
end
|
1558
|
-
|
1559
|
-
def test_lm_power1x
|
1560
|
-
print "\ntest_lm_power1x [#{Time.now}]: "
|
1561
|
-
check_power_floated(LongDecimal("0.9999999999999999064168934619655513256941764460425414729252240962626457779773851512889793738821624571066326550143425938244580355705073371363498199960410647291522935828683767303102466756569778099219013139392035"),
|
1562
|
-
LongDecimal("10940919037196297324861503538918892464840.3800411376419061644237297393478808698419759633900911655114302630926763678029075600021060757487171800272518085362"),
|
1563
|
-
31)
|
1564
|
-
puts "x"
|
1565
|
-
end
|
1566
|
-
|
1567
|
-
# SLOW!!!
|
1568
|
-
def _test_lm_power1y
|
1569
|
-
print "\ntest_lm_power1y [#{Time.now}] (3 hours): "
|
1570
|
-
check_power_floated(LongDecimal("0.9999999999999999999999999999999999999999999938200000000000000000000000000000000000000000379683968899999999999999999999999999999999997667396464396000000000000000000000000000000014330439460181976721"),
|
1571
|
-
LongDecimal("2277904328018223234624145785876970127.80132938289029176166582780311904615875187470778863280340852479308725681566723062546696023632646350474949485203212931524794058129718906431046410107451255702719381563833303042603168923"),
|
1572
|
-
29)
|
1573
|
-
puts "y"
|
1574
|
-
end
|
1575
|
-
|
1576
|
-
def test_lm_power1z
|
1577
|
-
print "\ntest_lm_power1z [#{Time.now}]: "
|
1578
|
-
check_power_floated(LongDecimal("0.999999999999999999999999999999999999999999921999999999022000000000000000000000000000004562456000114426000000717362999999999999999762787647991075570047888091371999532279324011562240678532015324522910310739147205531819744871729906561958405090975079783409588877137073074435963740549942065227793722398369867644224486056519686420388938836344615901685525200381485995400522678667"),
|
1579
|
-
LongDecimal("251896264925304377034350.0456973701263557812685942497288369797184140257647711785792872260304633895246908954737965005622561558677304225230618944035174740629720501757778145343269720425431792498286712042768306433898613430002918272371991628626003640130802094416142868825298695247199911145446388281612176850992412410783824332967890487347362798155764095915034449097990865463350294815436981248914797801550176"),
|
1580
|
-
35)
|
1581
|
-
puts "z"
|
1582
|
-
end
|
1583
|
-
|
1584
|
-
def test_lm_power1a
|
1585
|
-
print "\ntest_lm_power1a [#{Time.now}]: "
|
1586
|
-
check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
|
1587
|
-
LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
|
1588
|
-
20)
|
1589
|
-
puts "a"
|
1590
|
-
end
|
1591
|
-
|
1592
|
-
def test_lm_power1b
|
1593
|
-
print "\ntest_lm_power1b [#{Time.now}]: "
|
1594
|
-
check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
|
1595
|
-
LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
|
1596
|
-
40)
|
1597
|
-
puts "b"
|
1598
|
-
end
|
1599
|
-
|
1600
|
-
def test_lm_power1c
|
1601
|
-
print "\ntest_lm_power1c [#{Time.now}]: "
|
1602
|
-
check_power_floated(LongDecimal("0.000000000000000000000000000000000000046500000000000015087"),
|
1603
|
-
LongDecimal("-1.0000000037300000000000000000000000000000000000000000003924"),
|
1604
|
-
60)
|
1605
|
-
puts "c"
|
1606
|
-
end
|
1607
|
-
|
1608
|
-
def test_lm_power1d
|
1609
|
-
print "\ntest_lm_power1d [#{Time.now}]: "
|
1610
|
-
check_power_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000839040721742199946496057135094908790087131086768769514275053742150410299262922831017525963255748365635401006943680692892935684091800542751473902211475954311868825323737772210353295492066820457541121321"),
|
1611
|
-
LongDecimal("2.828427124746193491715927143848192103847391807094579920269011137128713363765124971278"),
|
1612
|
-
18)
|
1613
|
-
puts "d"
|
1614
|
-
end
|
1615
|
-
|
1616
|
-
def test_lm_power1e
|
1617
|
-
print "\ntest_lm_power1e [#{Time.now}]: "
|
1618
|
-
check_power_floated(LongDecimal("0.99999999999999999957080000000000000013815947999999999996046796745599999999068446772992800001009363347018894143517944326551369536327300875532667540019363271336013307136215732697434336575655193825816793693484735543517962560133437707866565666368082465969956371712599637541755027515672768774646443956623736866833"),
|
1619
|
-
LongDecimal("1628664495113750809027151521859950785.982561401863566922682596781753765470394912797043370321097687714712745442876309819766690333961107251381272682168155358789120923845170161713855374636824144351065708845142153775687292"),
|
1620
|
-
25)
|
1621
|
-
puts "e"
|
1622
|
-
end
|
1623
|
-
|
1624
|
-
def test_lm_power1f
|
1625
|
-
print "\ntest_lm_power1f [#{Time.now}]: "
|
1626
|
-
check_power_floated(LongDecimal("0.9999999999999999999996170000000000000000001466889999999999999995988181130000000000002857876622509999999998399356205378770000001997124082800492789998249134043407016130331222803769176235159503"),
|
1627
|
-
LongDecimal("10080628902211448045469261303.5133048444625606725923502869474154814472661420686348619932383678206438602596885342965949921926737285"),
|
1628
|
-
40)
|
1629
|
-
puts "f"
|
1630
|
-
end
|
1631
|
-
|
1632
|
-
def test_lm_power1g
|
1633
|
-
print "\ntest_lm_power1g [#{Time.now}]: "
|
1634
|
-
check_power_floated(LongDecimal("0.99999999999999999999999999999999999999999999999999999567999999999999999999999999993280680000000000000000001866240000000000000000000000058054924799999999999999991938294692612624"),
|
1635
|
-
LongDecimal("172711571675280380383067706300721798.164293576729518909754806389655985463898067955382434334508821341973697474920186895196633042535349353452630898625575004836357975433177114954313031033076280846"),
|
1636
|
-
29)
|
1637
|
-
puts "g"
|
1638
|
-
end
|
1639
|
-
|
1640
|
-
def test_lm_power1h
|
1641
|
-
print "\ntest_lm_power1h [#{Time.now}]: "
|
1642
|
-
check_power_floated(LongDecimal("0.9999999999999999999999999999999999999999999999999999999999999992419999999999601999999916300000000000000000000000000000000000005745640000000603368000126905040400006662520000700569"),
|
1643
|
-
LongDecimal("103626942927112137297398420916877844574257389450065434211636.290893349001885021464207122860891972260613740163376239637940672943781241170230437221414760788160997546494517494155287108299429330120640311594334671250673655216674953919962963363315956632"),
|
1644
|
-
7)
|
1645
|
-
puts "h"
|
1646
|
-
end
|
1647
|
-
|
1648
|
-
def test_lm_power1i
|
1649
|
-
print "\ntest_lm_power1i [#{Time.now}]: "
|
1650
|
-
check_power_floated(LongDecimal("1.000000000000000000000000000000000000000000000000000000000000000040632256971361441675364911547119523862617306023293961145667519711601390076843063624462699881424344873551296525030641685492629965401733250018815534188264352396285608689080041860127898254008134983805964167477328233064049446442345195928792206909976566059881698019"),
|
1651
|
-
LongDecimal("-275498317635275642242287018621310530812854589333829844444179465.026486828659378492893391926808279692889516447254926463357381523771105223660032617000227932272791794838690719013665737808233622061943268216888533855404111493288875534126178784830550654618969484969704069638284634725831920698820381864995363361738394367829090059556279914810540013438298547827401014937988931120431027937060054429855616000850263332145848273205542636020219974448846631834726343291615390210989854686573686051987947338952241558404158600234046969306176292822304779868899689391647661253521411090531104030615753856329486732170039585239348687257061864897478622958348189113878179294939392893585430107561210696450698403851795968372396462047808473453132852141249623740994995021422532249082127739"),
|
1652
|
-
14)
|
1653
|
-
puts "i"
|
1654
|
-
end
|
1655
|
-
|
1656
|
-
#
|
1657
|
-
# test the calculation of the base-10-logarithm function
|
1658
|
-
#
|
1659
|
-
def test_log10
|
1660
|
-
print "\ntest_log10 [#{Time.now}]: "
|
1661
|
-
check_log10_floated(10**2000, 30)
|
1662
|
-
check_log10_floated(100, 30)
|
1663
|
-
check_log10_floated(1, 30)
|
1664
|
-
check_log10_floated(0.01, 30)
|
1665
|
-
check_log10_floated(1e-10, 30)
|
1666
|
-
check_log10_floated(1e-90, 30)
|
1667
|
-
check_log10_floated(1e-300, 30)
|
1668
|
-
check_log10_floated(LongDecimal(1, 2000), 30)
|
1669
|
-
|
1670
|
-
check_log10_exact(10**2000, 2000, 30)
|
1671
|
-
check_log10_exact(10**0, 0, 30)
|
1672
|
-
check_log10_exact(10**1, 1, 30)
|
1673
|
-
check_log10_exact(10**10, 10, 30)
|
1674
|
-
|
1675
|
-
# random tests that have failed
|
1676
|
-
check_log10_floated(LongDecimal("587.00000000000000000095700000000000000000000000000000000000000000000000000000000000000000000001206"), 21)
|
1677
|
-
check_log10_floated(LongDecimal("543.0000002480000900000000000000000000000000000000000000000000000000000000000000000000847"), 2)
|
1678
|
-
check_log10_floated(LongDecimal("180.0000000000000000003570000000000000000000000000000000000000000000000577000000000000000000000000000637"), 2)
|
1679
|
-
check_log10_floated(LongDecimal("0.0000000000000000000000000000000000000000180000000063000000000000000000000000000000000025"), 74)
|
1680
|
-
check_log10_floated(LongDecimal("0.0000000000000000000000000006200000000000000000000000000000000000000000000000007940000015"), 74)
|
1681
|
-
check_log10_floated(LongDecimal("0.00000000000000000000000000000000000000000032900000000000000000000233000000000000000000000000000000254"), 10)
|
1682
|
-
check_log10_floated(LongDecimal("0.00000000000000000000000233000000094800000000000000000000000000000000000000000000000000000000000000682"), 100)
|
1683
|
-
check_log10_floated(LongDecimal("0.000000000000000000000000000000000000097000000041500000000000000000784"), 97)
|
1684
|
-
check_log10_floated(LongDecimal("185.000025300000000000000006320000000000000000000000000000737"), 27)
|
1685
|
-
check_log10_floated(LongDecimal("0.00000000000000000000000000000302000000000000000000000000000000000000000000000000000000060673"), 100)
|
1686
|
-
check_log10_floated(LongDecimal("442.000000000000045300000000000000000000000000000000000000000000000000000000000000000000000721000000000752"), 97)
|
1687
|
-
check_log10_floated(LongDecimal("0.001030927835051546391752577284408545010096715910298651428936221023301883588097777204212461151695109779555577162172"), 62)
|
1688
|
-
|
1689
|
-
end
|
1690
|
-
|
1691
|
-
#
|
1692
|
-
# test the calculation of the base-10-logarithm function
|
1693
|
-
#
|
1694
|
-
def test_log2
|
1695
|
-
print "\ntest_log2 [#{Time.now}]: "
|
1696
|
-
check_log2_floated(10**2000, 30)
|
1697
|
-
check_log2_floated(2**2000, 30)
|
1698
|
-
check_log2_floated(100, 30)
|
1699
|
-
check_log2_floated(1, 30)
|
1700
|
-
check_log2_floated(0.01, 30)
|
1701
|
-
check_log2_floated(1e-10, 30)
|
1702
|
-
check_log2_floated(1e-90, 30)
|
1703
|
-
check_log2_floated(1e-300, 30)
|
1704
|
-
check_log2_floated(LongDecimal(1, 2000), 30)
|
1705
|
-
|
1706
|
-
check_log2_exact(2**2000, 2000, 30)
|
1707
|
-
check_log2_exact(2**0, 0, 30)
|
1708
|
-
check_log2_exact(2**1, 1, 30)
|
1709
|
-
check_log2_exact(2**10, 10, 30)
|
1710
|
-
|
1711
|
-
# random tests that have failed
|
1712
|
-
check_log2_floated(LongDecimal("341.00000739000000000000000000000000000000000000000000000000000000000000171"), 3)
|
1713
|
-
check_log2_floated(LongDecimal("504.00000000000000000000000000000000000000000000000000000000000000000000000000000000000327400000000000828"), 1)
|
1714
|
-
check_log2_floated(LongDecimal("0.0033222591362126245847176079734219269102990032888157967351353737817463383406363175903135730345286354858609181999523961456225622835123748782987926188031081"), 48)
|
1715
|
-
check_log2_floated(LongDecimal("0.000802000000000000000000197000000000000000000000302"), 84)
|
1716
|
-
check_log2_floated(LongDecimal("0.00000000000000000000000000000000000000000000000000000000000000000000000452000000000069480"), 3)
|
1717
|
-
check_log2_floated(LongDecimal("0.0000000000000000000000000000000000000000000000000000930000000000000000000000000983000000000000300"), 61)
|
1718
|
-
check_log2_floated(LongDecimal("0.000000000000000000000000000000000000000000000000000000000086000133000000000000000000000000947"), 106)
|
1719
|
-
check_log2_floated(LongDecimal("0.00000000000000000000000000000276000000000000000000000000000000000008560000000000000000000000000000161"), 81)
|
1720
|
-
|
1721
|
-
end
|
1722
|
-
|
1723
|
-
#
|
1724
|
-
# test the calculation of the base-x-logarithm of sqrt(x)
|
1725
|
-
#
|
1726
|
-
def test_log_2_10_of_sqrt
|
1727
|
-
print "\ntest_log_2_10_of_sqrt [#{Time.now}]: "
|
1728
|
-
# n = 125
|
1729
|
-
n = 30
|
1730
|
-
m = 5
|
1731
|
-
x2 = LongMath.sqrt(2, n)
|
1732
|
-
x10 = LongMath.sqrt(10, n)
|
1733
|
-
|
1734
|
-
(2*m).times do |i|
|
1735
|
-
check_log2_floated(x2, n+m-i)
|
1736
|
-
check_log10_floated(x10, n+m-i)
|
1737
|
-
end
|
1738
|
-
|
1739
|
-
y2 = check_log2_floated(x2, n)
|
1740
|
-
assert((y2*2).one?, "xe=#{x2} ye=#{y2}")
|
1741
|
-
y10 = check_log10_floated(x10, n)
|
1742
|
-
assert((y10*2).one?, "xe=#{x10} ye=#{y10}")
|
1743
|
-
|
1744
|
-
end
|
1745
|
-
|
1746
|
-
end
|
1747
|
-
|
1748
|
-
# RUNIT::CUI::TestRunner.run(TestLongDecimalExtra_class.suite)
|
1749
|
-
|
1750
|
-
# end of file testlongdecimal.rb
|