continued_fractions 1.8.4 → 1.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/continued_fractions.rb +31 -29
- metadata +8 -9
- data/lib/continued_fractions/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7aa696a6a061c921c1513ffeb7d17ce641a4936e89174e61accd3cf0615ca9f
|
4
|
+
data.tar.gz: 46d89b9a7a7242ec10bd5074858b443ea2b4e01101c6a1f005e512aceb4f880e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3388b0c412ace93cc15958c11afa99e4e08059e2be6f4726c37121c6eded00a725406218b14f8679ab252d6c565c5ccbdb4c9e276cef5c1bd8d6a26cc6edf8c5
|
7
|
+
data.tar.gz: fd8308ba053a0e2c09d146e720b5fd195b76fc78903236bb7335f6520e17551a4598905f6f667f35d046f41486e99969b599de16b96b0feb1a204945857f44b0
|
data/lib/continued_fractions.rb
CHANGED
@@ -26,11 +26,10 @@ class ContinuedFraction
|
|
26
26
|
# @convergents=[[0, 1], [1, 0], [3, 1], [22, 7], [333, 106],
|
27
27
|
# [355, 113], [103993, 33102], [104348, 33215], [208341, 66317], [312689, 99532], [833719, 265381], [1146408, 364913]]>
|
28
28
|
#
|
29
|
-
def initialize(number,limit=DEFAULT_LIMIT)
|
29
|
+
def initialize(number, limit=DEFAULT_LIMIT)
|
30
30
|
@number = number
|
31
|
-
@
|
32
|
-
@quotients =
|
33
|
-
@convergents = calculate_convergents
|
31
|
+
@ratioed_number = number.to_r
|
32
|
+
@quotients, @convergents, @limit = calculate_quotients_and_convergents(number, limit)
|
34
33
|
end
|
35
34
|
|
36
35
|
# Return nth convergent.
|
@@ -133,34 +132,37 @@ class ContinuedFraction
|
|
133
132
|
yield(num,prec)
|
134
133
|
end
|
135
134
|
|
136
|
-
def
|
137
|
-
|
138
|
-
|
139
|
-
limit.times do |i|
|
140
|
-
qs[i] = n.to_i
|
141
|
-
break if ((divisor = n-qs[i]) == 0.0)
|
142
|
-
n = 1.0/divisor
|
143
|
-
end
|
144
|
-
self.limit = qs.compact.length
|
145
|
-
end.compact
|
146
|
-
end
|
135
|
+
def calculate_quotients_and_convergents(x, limit)
|
136
|
+
_quotients = []
|
137
|
+
_convergents = []
|
147
138
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end[2...nth+2]
|
158
|
-
end
|
139
|
+
# Initialize the initial values for p and q
|
140
|
+
p_minus_1, q_minus_1 = 0, 1
|
141
|
+
p_0, q_0 = 1, 0
|
142
|
+
|
143
|
+
n = x.to_i
|
144
|
+
|
145
|
+
# Loop for maximum specified terms or until the fractional part becomes zero
|
146
|
+
limit.times do
|
147
|
+
_quotients << n
|
159
148
|
|
160
|
-
|
161
|
-
|
162
|
-
|
149
|
+
# Calculate the new p and q
|
150
|
+
p_n = n * p_0 + p_minus_1
|
151
|
+
q_n = n * q_0 + q_minus_1
|
152
|
+
|
153
|
+
_convergents << [p_n, q_n]
|
154
|
+
|
155
|
+
# Recalculate the fractional part
|
156
|
+
x = 1.0 / (x - n)
|
157
|
+
break if x.infinite? || _convergents.include?([@ratioed_number.numerator, @ratioed_number.denominator])
|
158
|
+
|
159
|
+
# Update the old values
|
160
|
+
p_minus_1, q_minus_1 = p_0, q_0
|
161
|
+
p_0, q_0 = p_n, q_n
|
162
|
+
n = x.to_i
|
163
163
|
end
|
164
|
+
|
165
|
+
return _quotients, _convergents, _quotients.length
|
164
166
|
end
|
165
167
|
end
|
166
168
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: continued_fractions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Hales-Garcia
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '11.1'
|
41
41
|
description: Class for working with continued fractions
|
42
|
-
email:
|
42
|
+
email: jose@halesgarcia.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files:
|
@@ -51,13 +51,12 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- lib/continued_fractions.rb
|
53
53
|
- lib/continued_fractions/include.rb
|
54
|
-
|
55
|
-
homepage: http://jolohaga.github.io/continued_fractions
|
54
|
+
homepage: https://jolohaga.github.io/continued_fractions
|
56
55
|
licenses:
|
57
56
|
- MIT
|
58
57
|
metadata:
|
59
58
|
source_code_uri: https://github.com/jolohaga/continued_fractions
|
60
|
-
post_install_message:
|
59
|
+
post_install_message:
|
61
60
|
rdoc_options:
|
62
61
|
- "--line-numbers"
|
63
62
|
- "--title"
|
@@ -77,8 +76,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
76
|
- !ruby/object:Gem::Version
|
78
77
|
version: '1.2'
|
79
78
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
81
|
-
signing_key:
|
79
|
+
rubygems_version: 3.4.19
|
80
|
+
signing_key:
|
82
81
|
specification_version: 4
|
83
82
|
summary: Generate continued fractions
|
84
83
|
test_files: []
|