continued_fractions 1.7.0 → 1.8.0
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/README.md +11 -8
- data/lib/continued_fractions.rb +7 -1
- data/spec/continued_fractions/continued_fraction_spec.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9253bbf7cf75a29375e99c2bdec92f643413eba529a1d360e0165d2ce98fbdd7
|
4
|
+
data.tar.gz: '09063bf865028894dd41c43bc47118d8445dd79811154f7c862cf1ab696cff93'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce2f1dbad5629bef37ea84ceaa549005e0c0c73931ecbf54e36f3f779b22c3256505e4719fe3095fbaa116937ed01307eeded90547491db96084994a6459e77b
|
7
|
+
data.tar.gz: 1b881899377e3ba060db5d03666ac3451703a169bf768bee1aebc5e512b91c8bc1c5c15373669514854b33cf623449e8588a329f6a68026a22363d268efae2c7
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
1
|
+
# ContinuedFractions
|
2
2
|
|
3
3
|
* http://rubygems.org/gems/continued_fractions
|
4
4
|
|
5
|
-
|
5
|
+
## Description
|
6
6
|
|
7
7
|
Generates quotients and convergents for a given number.
|
8
8
|
|
9
|
-
|
9
|
+
## Synopsis
|
10
10
|
|
11
11
|
require 'continued_fractions'
|
12
12
|
|
@@ -38,17 +38,20 @@ Generates quotients and convergents for a given number.
|
|
38
38
|
cf + cf2
|
39
39
|
=> #<ContinuedFractions::ContinuedFraction:0x000001009d2708 @number=3.1799344075396196, @limit=20, @quotients=[3, 5, 1, 1, 3, 1, 5, 3, 7, 25, 1, 2, 15, 6, 1, 1, 2, 3, 1, 2], @convergents=[[3, 1], [16, 5], [19, 6], [35, 11], [124, 39], [159, 50], [919, 289], [2916, 917], [21331, 6708], [536191, 168617], [557522, 175325], [1651235, 519267], [25326047, 7964330], [153607517, 48305247], [178933564, 56269577], [332541081, 104574824], [844015726, 265419225], [2864588259, 900832499], [3708603985, 1166251724], [10281796229, 3233335947]]>
|
40
40
|
|
41
|
-
|
41
|
+
## Install
|
42
42
|
|
43
43
|
sudo gem install continued_fractions
|
44
44
|
|
45
|
-
|
45
|
+
## Requirements/Dependencies
|
46
46
|
|
47
47
|
* Ruby 2.2+
|
48
48
|
* Depends on Ruby's Rational class
|
49
49
|
|
50
|
-
|
50
|
+
## Developers
|
51
51
|
|
52
52
|
* RSpec required to run tests
|
53
|
-
|
54
|
-
|
53
|
+
|
54
|
+
## Contributors
|
55
|
+
|
56
|
+
* [Jose Hales-Garcia](https://github.com/jolohaga)
|
57
|
+
* [Eoin Kelly](https://github.com/eoinkelly)
|
data/lib/continued_fractions.rb
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
#
|
8
8
|
#
|
9
9
|
class ContinuedFraction
|
10
|
+
include ::Comparable
|
11
|
+
|
10
12
|
attr_accessor :number, :quotients, :limit
|
11
13
|
|
12
14
|
# For a given number calculate its continued fraction quotients and convergents up to limit.
|
@@ -99,6 +101,10 @@ class ContinuedFraction
|
|
99
101
|
evaluate("#{number} * #{num}",prec)
|
100
102
|
end
|
101
103
|
end
|
104
|
+
|
105
|
+
def <=>(other)
|
106
|
+
number <=> other.number
|
107
|
+
end
|
102
108
|
|
103
109
|
def convergent_to_rational(convergent) #:nodoc:
|
104
110
|
Rational(convergent[0],convergent[1])
|
@@ -108,7 +114,7 @@ class ContinuedFraction
|
|
108
114
|
def evaluate(exp, prec) #:nodoc:
|
109
115
|
ContinuedFraction.new(eval(exp), prec)
|
110
116
|
end
|
111
|
-
|
117
|
+
|
112
118
|
def number_of(n) #:nodoc:
|
113
119
|
num = nil
|
114
120
|
prec = nil
|
@@ -68,4 +68,23 @@ describe ContinuedFraction do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
describe 'comparing' do
|
73
|
+
context 'when numbers are the same' do
|
74
|
+
let(:cf2) { described_class.new(cf.number) }
|
75
|
+
|
76
|
+
it "the ContinuedFractions are equal" do
|
77
|
+
expect(cf).to eq cf2
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when numbers are different' do
|
82
|
+
let(:cond) { [['+', '<'], ['-', '>']].sample }
|
83
|
+
let(:cf2) { described_class.new(cf.number.send(cond[0], 1.0)) }
|
84
|
+
|
85
|
+
it "the ContinuedFractions are unequal" do
|
86
|
+
expect(cf.send(cond[1], cf2)).to be true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
71
90
|
end
|