continued_fractions 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Rakefile +4 -4
- data/continued_fractions.gemspec +4 -1
- data/lib/continued_fractions.rb +23 -6
- metadata +15 -4
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -2,13 +2,13 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('continued_fractions', '0.1.
|
6
|
-
config.
|
5
|
+
Echoe.new('continued_fractions', '0.1.8') do |config|
|
6
|
+
config.summary = 'Generate continued fractions.'
|
7
7
|
config.author = 'Jose Hales-Garcia'
|
8
8
|
config.url = 'http://bitbucket.org/jolohaga/continued_fractions/'
|
9
9
|
config.email = 'jolohaga@me.com'
|
10
|
-
config.ignore_pattern = ["tmp/*",".hg/*"]
|
11
|
-
config.development_dependencies = []
|
10
|
+
config.ignore_pattern = ["tmp/*",".hg/*", ".pkg/*"]
|
11
|
+
config.development_dependencies = ['rspec']
|
12
12
|
end
|
13
13
|
|
14
14
|
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each{|ext| load ext}
|
data/continued_fractions.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{continued_fractions}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.8"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jose Hales-Garcia"]
|
@@ -23,8 +23,11 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.specification_version = 3
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
26
27
|
else
|
28
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
27
29
|
end
|
28
30
|
else
|
31
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
29
32
|
end
|
30
33
|
end
|
data/lib/continued_fractions.rb
CHANGED
@@ -1,24 +1,41 @@
|
|
1
|
+
# ContinuedFractions
|
2
|
+
#
|
3
|
+
# Generates quotients and convergents for a given number.
|
4
|
+
#
|
5
|
+
# Requires Ruby 1.9+
|
6
|
+
#
|
7
|
+
# Author:: Jose Hales-Garcia (mailto:jolohaga@me.com)
|
8
|
+
# Copyright:: Copyright (c) 2010 Jose Hales-Garcia
|
9
|
+
#
|
10
|
+
#
|
1
11
|
module ContinuedFractions #:nodoc:
|
2
|
-
# Requires Ruby 1.9
|
3
12
|
class ContinuedFraction
|
4
13
|
attr_accessor :number, :quotients, :limit
|
5
14
|
attr_writer :convergents
|
6
|
-
|
15
|
+
|
16
|
+
# For a given number, n, calculate its continued fraction quotients and convergents.
|
17
|
+
#
|
7
18
|
def initialize(n,l=5)
|
8
19
|
@number = n
|
9
20
|
@limit = l
|
10
21
|
@quotients = calculate_quotients
|
11
22
|
@convergents = calculate_convergents
|
12
23
|
end
|
13
|
-
|
24
|
+
|
25
|
+
# Return nth (pre-calculated) convergent.
|
26
|
+
#
|
14
27
|
def convergent(n)
|
15
28
|
convergents[n]
|
16
29
|
end
|
17
|
-
|
30
|
+
|
31
|
+
# Return array of convergents as Rationals.
|
32
|
+
#
|
18
33
|
def convergents
|
19
34
|
_convergents.map{|c| Rational(c[0],c[1])}
|
20
35
|
end
|
21
|
-
|
36
|
+
|
37
|
+
# Return array of convergents, each as a two-element array with the numerator in [i,0] and denominator in [i,1].
|
38
|
+
#
|
22
39
|
def convergents_array
|
23
40
|
_convergents
|
24
41
|
end
|
@@ -49,7 +66,7 @@ module ContinuedFractions #:nodoc:
|
|
49
66
|
end
|
50
67
|
end
|
51
68
|
|
52
|
-
class << self
|
69
|
+
class << self #:nodoc:
|
53
70
|
def convergence_matrix(n,m,fill=nil)
|
54
71
|
conv_mat = Array.new(n).map!{Array.new(m,fill)}
|
55
72
|
conv_mat[0][0],conv_mat[1][1] = 0,0
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 8
|
9
|
+
version: 0.1.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jose Hales-Garcia
|
@@ -16,8 +16,19 @@ cert_chain: []
|
|
16
16
|
|
17
17
|
date: 2010-03-15 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
21
32
|
description: Generate continued fractions.
|
22
33
|
email: jolohaga@me.com
|
23
34
|
executables: []
|