three141 1.0.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.
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 1.0.0 / 2007-06-24
2
+
3
+ * First Version
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/three141
6
+ lib/three141.rb
7
+ test/test_three141.rb
data/README.txt ADDED
@@ -0,0 +1,50 @@
1
+ three141
2
+ by Sandro Paganotti
3
+ www.314159265358979323846264338327950288419716939937510.net
4
+
5
+ == DESCRIPTION:
6
+
7
+ The BBP algorithm is very powerful because it let you calculate the nth pi digit without the need to store the previous n-1th digits. In this website is avaiable ruby-bbp, a ruby porting of the bbp algorithm.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ It calculates the tenth pi digits starting at a given position
12
+
13
+ == SYNOPSIS:
14
+
15
+ a = Three141.new
16
+ a.digits(2)
17
+ # => ["3", "F", "6", "A", "8", "8", "8", "5", "A", "3", "0", "8", "E", "0", "0", "0"]
18
+
19
+ == REQUIREMENTS:
20
+
21
+ Ruby 1.8.5 or above
22
+
23
+ == INSTALL:
24
+
25
+ sudo gem install three141
26
+
27
+ == LICENSE:
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2007 FIX
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ 'Software'), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
48
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
50
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/three141.rb'
6
+
7
+ Hoe.new('three141', Three141::VERSION) do |p|
8
+ p.rubyforge_name = 'three141'
9
+ p.author = 'Sandro Paganotti'
10
+ p.email = 'info@314159265358979323846264338327950288419716939937510.net'
11
+ p.summary = 'A BBP Porting in Ruby'
12
+ p.remote_rdoc_dir = 'three141' # Release to root
13
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
14
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
15
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
16
+ end
17
+
18
+ # vim: syntax=Ruby
data/bin/three141 ADDED
File without changes
data/lib/three141.rb ADDED
@@ -0,0 +1,123 @@
1
+ class Three141
2
+
3
+ VERSION = '1.0.0'
4
+
5
+ def initialize
6
+ @tp = Array.new
7
+ @tp1 = 0
8
+ end
9
+
10
+
11
+ # It returns the first 10 pi digits (hex) starting from position = id
12
+ #
13
+ # eg: Bbp.new.digits(2)
14
+ # => ["3", "F", "6", "A", "8", "8", "8", "5", "A", "3", "0", "8", "E", "0", "0", "0"]
15
+
16
+ def digits(id)
17
+ s1 = series(1, id).to_f;
18
+ s2 = series(4, id).to_f;
19
+ s3 = series(5, id).to_f;
20
+ s4 = series(6, id).to_f;
21
+
22
+ pid = (4.0 * s1 - 2.0 * s2 - s3 - s4).to_f;
23
+ pid = pid - pid.to_i;
24
+ if (pid < 0.0)
25
+ pid = pid + 1.0;
26
+ end
27
+ chx = ihex(pid, 16);
28
+ return chx[0..10]
29
+ end
30
+
31
+ private
32
+
33
+ def ihex(x,nhx)
34
+ hx = %w(0 1 2 3 4 5 6 7 8 9 A B C D E F)
35
+ y= x.abs.to_f
36
+ chx = Array.new
37
+ (0...nhx).to_a.each do |i|
38
+ y = 16.0 * (y - y.floor);
39
+ chx[i] = hx[y.to_i];
40
+ end
41
+ return chx
42
+ end
43
+
44
+
45
+ def series(m,id)
46
+ s =0.0
47
+ ak=0.0
48
+ p=0.0
49
+ s=0.0
50
+ t=0.0
51
+ eps = (10**(-17)).to_f
52
+
53
+ (0...id).to_a.each do |k|
54
+ ak = 8 * k + m;
55
+ p = id - k;
56
+ t = expm(p, ak);
57
+ s = s + t / ak;
58
+ s = s - s.to_i;
59
+ end
60
+
61
+ (id...(id +100)).to_a.each do |k|
62
+ ak = 8 * k + m;
63
+ t = (16.0 ** (id - k).to_f) / ak;
64
+ if (t < eps)
65
+ break;
66
+ end
67
+ s = s + t;
68
+ s = s - s.to_i;
69
+ end
70
+
71
+ return s
72
+ end
73
+
74
+ def expm(p,ak)
75
+ ntp = 25
76
+ exi = 0
77
+ p1 = 0.0
78
+ pt = 0.0
79
+ r = 0.0
80
+
81
+ if (@tp1 == 0)
82
+ @tp1 = 1
83
+ @tp[0] = 1.0
84
+
85
+ (1...ntp).to_a.each do |i|
86
+ @tp[i] = 2.0 * @tp[i-1];
87
+ end
88
+ exi = ntp
89
+ end
90
+
91
+ if (ak == 1.0)
92
+ return 0.0
93
+ end
94
+
95
+ exi = ntp
96
+ (1...ntp).to_a.each do |i|
97
+ exi = i
98
+ if (@tp[i] > p)
99
+ break
100
+ end
101
+ end
102
+
103
+ pt = @tp[exi-1].to_f;
104
+ p1 = p;
105
+ r = 1.0;
106
+
107
+ (1..exi).to_a.each do |j|
108
+ if (p1 >= pt)
109
+ r = 16.0 * r;
110
+ r = r - ((r / ak).to_i * ak).to_i
111
+ p1 = p1 - pt
112
+ end
113
+ pt = 0.5 * pt
114
+ if (pt >= 1.0)
115
+ r = r * r
116
+ r = r - ((r / ak).to_i * ak).to_i
117
+ end
118
+ end
119
+
120
+ return r;
121
+ end
122
+
123
+ end
File without changes
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: three141
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2007-06-24 00:00:00 +02:00
8
+ summary: A BBP Porting in Ruby
9
+ require_paths:
10
+ - lib
11
+ email: info@314159265358979323846264338327950288419716939937510.net
12
+ homepage: " by Sandro Paganotti"
13
+ rubyforge_project: three141
14
+ description: "== FEATURES/PROBLEMS: It calculates the tenth pi digits starting at a given position == SYNOPSIS: a = Three141.new a.digits(2) # => [\"3\", \"F\", \"6\", \"A\", \"8\", \"8\", \"8\", \"5\", \"A\", \"3\", \"0\", \"8\", \"E\", \"0\", \"0\", \"0\"] == REQUIREMENTS:"
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Sandro Paganotti
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - bin/three141
37
+ - lib/three141.rb
38
+ - test/test_three141.rb
39
+ test_files:
40
+ - test/test_three141.rb
41
+ rdoc_options:
42
+ - --main
43
+ - README.txt
44
+ extra_rdoc_files:
45
+ - History.txt
46
+ - Manifest.txt
47
+ - README.txt
48
+ executables:
49
+ - three141
50
+ extensions: []
51
+
52
+ requirements: []
53
+
54
+ dependencies:
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ version_requirement:
58
+ version_requirements: !ruby/object:Gem::Version::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.2.1
63
+ version: