fixed_point 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +11 -0
- data/Rakefile +95 -5
- data/lib/fixed_point.rb +1 -1
- data/lib/fixed_point/number.rb +4 -0
- data/spec/fixed_point_spec.rb +29 -9
- metadata +18 -40
data/HISTORY.md
CHANGED
data/Rakefile
CHANGED
@@ -2,10 +2,100 @@ require 'rspec/core/rake_task'
|
|
2
2
|
|
3
3
|
file_list = FileList['spec/*_spec.rb']
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
namespace :test do
|
6
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
7
|
+
t.pattern = file_list
|
8
|
+
t.rspec_opts = ["--colour", "--format progress"]
|
9
|
+
end
|
8
10
|
end
|
9
|
-
|
10
11
|
desc 'Default: run specs.'
|
11
|
-
task :default => 'spec'
|
12
|
+
task :default => 'test:spec'
|
13
|
+
|
14
|
+
namespace :deploy do
|
15
|
+
|
16
|
+
## name and versio taken from
|
17
|
+
## https://github.com/mojombo/rakegem
|
18
|
+
def name
|
19
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
20
|
+
end
|
21
|
+
|
22
|
+
def version
|
23
|
+
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
24
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
25
|
+
end
|
26
|
+
|
27
|
+
#Dir.chdir( './lib/')
|
28
|
+
#puts require NAME
|
29
|
+
#Dir.chdir( './../')
|
30
|
+
|
31
|
+
|
32
|
+
desc 'Run Spec'
|
33
|
+
#file_list = FileList['spec/*_spec.rb']
|
34
|
+
html_path = "spec_results.html"
|
35
|
+
RSpec::Core::RakeTask.new('run_spec') do |t|
|
36
|
+
t.pattern = file_list
|
37
|
+
t.rspec_opts = ["--format html", "--out #{html_path}"]
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
desc 'Check that the spec passes'
|
42
|
+
task :spec_passes => :run_spec do
|
43
|
+
# find out how many errors were found
|
44
|
+
html = open(html_path).read
|
45
|
+
examples = html.match(/(\d+) examples/)[0].to_i rescue 0
|
46
|
+
failures = html.match(/(\d+) failures/)[0].to_i rescue 0
|
47
|
+
pending = html.match(/(\d+) pending/)[0].to_i rescue 0
|
48
|
+
|
49
|
+
if failures.zero?
|
50
|
+
puts "0 failures! #{examples} run, #{pending} pending"
|
51
|
+
else
|
52
|
+
$stderr.puts "\aSpecs did not pass deploy aborted!"
|
53
|
+
$stderr.puts "View spec results at #{File.expand_path(html_path)}"
|
54
|
+
$stderr.puts
|
55
|
+
$stderr.puts "#{failures} failures! #{examples} run, #{pending} pending"
|
56
|
+
exit -1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
task :build_gem do
|
61
|
+
puts "Building Gem"
|
62
|
+
`gem build #{name}.gemspec`
|
63
|
+
unless $?.success?
|
64
|
+
$stderr.puts "Gem Build Failed"
|
65
|
+
exit -1
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
task :push_gem do
|
71
|
+
puts "Pushing Gem #{name}-#{version}"
|
72
|
+
#`gem push`
|
73
|
+
unless $?.success?
|
74
|
+
$stderr.puts "Gem Push Failed"
|
75
|
+
exit -1
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
task :create_git_tag do
|
80
|
+
puts "Tagging #{name}-#{version}"
|
81
|
+
#`git tag -a #{version} -m 'Tagging gem release #{version}'`
|
82
|
+
unless $?.success?
|
83
|
+
$stderr.puts "Tagging Git Failed"
|
84
|
+
exit -1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
task :push_tag do
|
89
|
+
puts "Push Tag #{version}"
|
90
|
+
#`git push origin #{version}`
|
91
|
+
unless $?.success?
|
92
|
+
$stderr.puts "Pushing Git Tag Failed"
|
93
|
+
exit -1
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
task :gem => [:spec_passes, :build_gem, :push_gem, :create_git_tag, :push_tag] do
|
98
|
+
puts "Deployed #{name} Version #{version} !"
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
data/lib/fixed_point.rb
CHANGED
data/lib/fixed_point/number.rb
CHANGED
data/spec/fixed_point_spec.rb
CHANGED
@@ -16,6 +16,7 @@ describe FixedPoint do
|
|
16
16
|
|
17
17
|
fixt.source.should == 0.0
|
18
18
|
fixt.to_f.should == 0.0
|
19
|
+
fixt.to_s.should == "0.0"
|
19
20
|
fixt.to_i.should == 0
|
20
21
|
fixt.frac.should == 0.0
|
21
22
|
fixt.to_h.should == "00000000"
|
@@ -28,6 +29,7 @@ it "Integers 0 " do
|
|
28
29
|
|
29
30
|
fixt.source.should == 7.0
|
30
31
|
fixt.to_f.should == 7.0
|
32
|
+
fixt.to_s.should == "7.0"
|
31
33
|
fixt.to_i.should == 7
|
32
34
|
fixt.frac.should == 0.0
|
33
35
|
fixt.to_h.should == "07"
|
@@ -40,6 +42,7 @@ it "Different Decimal Mark _ instead of ." do
|
|
40
42
|
|
41
43
|
fixt.source.should == 0.0
|
42
44
|
fixt.to_f.should == 0.0
|
45
|
+
fixt.to_s.should == "0.0"
|
43
46
|
fixt.to_i.should == 0
|
44
47
|
fixt.frac.should == 0.0
|
45
48
|
fixt.to_h.should == "00000000"
|
@@ -55,6 +58,7 @@ end
|
|
55
58
|
|
56
59
|
fixt.source.should == 0.0
|
57
60
|
fixt.to_f.should == 0.0
|
61
|
+
fixt.to_s.should == "0.0"
|
58
62
|
fixt.to_i.should == 0
|
59
63
|
fixt.frac.should == 0.0
|
60
64
|
#Calculate hex length and fill with 0's
|
@@ -76,8 +80,9 @@ it "Zero fractional bits " do
|
|
76
80
|
|
77
81
|
fixt.source.should == 0.0
|
78
82
|
fixt.to_f.should == 0.0
|
83
|
+
fixt.to_s.should == "0.0"
|
79
84
|
fixt.to_i.should == 0
|
80
|
-
fixt.frac.should
|
85
|
+
fixt.frac.should == 0.0
|
81
86
|
fixt.to_h.should == "000"
|
82
87
|
fixt.to_b.should == "000000000000"
|
83
88
|
end
|
@@ -88,8 +93,9 @@ it "returns 2.5 for initalise of 2.5" do
|
|
88
93
|
|
89
94
|
fixt.source.should == 2.5
|
90
95
|
fixt.to_f.should == 2.5
|
96
|
+
fixt.to_s.should == "2.5"
|
91
97
|
fixt.to_i.should == 2
|
92
|
-
fixt.frac.should
|
98
|
+
fixt.frac.should == 0.5
|
93
99
|
fixt.to_h.should == "00280000"
|
94
100
|
fixt.to_b.should == "000000000010.10000000000000000000"
|
95
101
|
end
|
@@ -101,8 +107,9 @@ it "returns 2.5 for initalise of 2.5" do
|
|
101
107
|
|
102
108
|
fixt.source.should == 2.501
|
103
109
|
fixt.to_f.should == 2.5
|
110
|
+
fixt.to_s.should == "2.5"
|
104
111
|
fixt.to_i.should == 2
|
105
|
-
fixt.frac.should
|
112
|
+
fixt.frac.should == 0.5
|
106
113
|
fixt.to_h.should == "0005"
|
107
114
|
fixt.to_b.should == "000000000010.1"
|
108
115
|
end
|
@@ -114,12 +121,13 @@ it "returns 2.5 for initalise of 2.5" do
|
|
114
121
|
format = FixedPoint::Format.new(1, 4, 0)
|
115
122
|
fixt = FixedPoint::Number.new(2**3, format, "_")
|
116
123
|
|
117
|
-
fixt.source.should
|
118
|
-
fixt.to_f.should
|
119
|
-
fixt.
|
120
|
-
fixt.
|
121
|
-
fixt.
|
122
|
-
fixt.
|
124
|
+
fixt.source.should == 2**3
|
125
|
+
fixt.to_f.should == 2**3-1
|
126
|
+
fixt.to_s.should == "7.0"
|
127
|
+
fixt.to_i.should == 2**3-1
|
128
|
+
fixt.frac.should == 0.0
|
129
|
+
fixt.to_h.should == "7"
|
130
|
+
fixt.to_b.should == "0111"
|
123
131
|
fixt.overflow?.should == true
|
124
132
|
fixt.underflow?.should == false
|
125
133
|
end
|
@@ -130,6 +138,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
130
138
|
|
131
139
|
fixt.source.should == 2**11
|
132
140
|
fixt.to_f.should == 2**11-1
|
141
|
+
fixt.to_s.should == "2047.0"
|
133
142
|
fixt.to_i.should == 2**11-1
|
134
143
|
fixt.frac.should == 0.0
|
135
144
|
fixt.to_h.should == "7ff"
|
@@ -146,6 +155,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
146
155
|
|
147
156
|
fixt.source.should == 2**11
|
148
157
|
fixt.to_f.should == 2**11 -1 + max_fractional_value
|
158
|
+
fixt.to_s.should == "2047.9375"
|
149
159
|
fixt.to_i.should == 2**11 -1
|
150
160
|
fixt.frac.should == max_fractional_value
|
151
161
|
fixt.to_h.should == "7fff"
|
@@ -163,6 +173,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
163
173
|
max_fractional_value = (1.0/2) + (1.0/4) + (1.0/8) + (1.0/16)
|
164
174
|
|
165
175
|
fixt.to_f.should == 2**11 -1 + max_fractional_value
|
176
|
+
fixt.to_s.should == "2047.9375"
|
166
177
|
fixt.to_i.should == 2**11 -1
|
167
178
|
fixt.frac.should == max_fractional_value
|
168
179
|
fixt.to_h.should == "7fff"
|
@@ -181,6 +192,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
181
192
|
|
182
193
|
fixt.source.should == -2**11
|
183
194
|
fixt.to_f.should == -2**11
|
195
|
+
fixt.to_s.should == "-2048"
|
184
196
|
fixt.to_i.should == -2**11
|
185
197
|
fixt.frac.should == 0.0
|
186
198
|
fixt.to_h.should == "800"
|
@@ -195,6 +207,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
195
207
|
|
196
208
|
fixt.source.should == -2**11-1
|
197
209
|
fixt.to_f.should == -2**11
|
210
|
+
fixt.to_s.should == "-2048"
|
198
211
|
fixt.to_i.should == -2**11
|
199
212
|
fixt.frac.should == 0.0
|
200
213
|
fixt.to_h.should == "800"
|
@@ -209,6 +222,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
209
222
|
|
210
223
|
fixt.source.should == -2**11-1
|
211
224
|
fixt.to_f.should == -2**11
|
225
|
+
fixt.to_s.should == "-2048"
|
212
226
|
fixt.to_i.should == -2**11
|
213
227
|
fixt.frac.should == 0.0
|
214
228
|
fixt.to_h.should == "8000"
|
@@ -224,6 +238,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
224
238
|
|
225
239
|
fixt.source.should == -2**17
|
226
240
|
fixt.to_f.should == -2**11
|
241
|
+
fixt.to_s.should == "-2048"
|
227
242
|
fixt.to_i.should == -2**11
|
228
243
|
fixt.frac.should == 0.0
|
229
244
|
fixt.to_h.should == "8000"
|
@@ -239,6 +254,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
239
254
|
fixt.binary = "011_01"
|
240
255
|
fixt.source.should == 3.25
|
241
256
|
fixt.to_f.should == 3.25
|
257
|
+
fixt.to_s.should == "3.25"
|
242
258
|
fixt.to_i.should == 3
|
243
259
|
fixt.frac.should == 0.25
|
244
260
|
fixt.to_h.should == "0d"
|
@@ -253,6 +269,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
253
269
|
fixt.binary = "0_1"
|
254
270
|
fixt.source.should == 0.5
|
255
271
|
fixt.to_f.should == 0.5
|
272
|
+
fixt.to_s.should == "0.5"
|
256
273
|
fixt.to_i.should == 0
|
257
274
|
fixt.frac.should == 0.5
|
258
275
|
fixt.to_h.should == "1"
|
@@ -267,6 +284,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
267
284
|
fixt.binary = "1000_1"
|
268
285
|
fixt.source.should == -7.5
|
269
286
|
fixt.to_f.should == -7.5
|
287
|
+
fixt.to_s.should == "-7.5"
|
270
288
|
fixt.to_i.should == -7
|
271
289
|
fixt.frac.should == -0.5
|
272
290
|
fixt.to_h.should == "11"
|
@@ -282,6 +300,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
282
300
|
fixt.binary = "1000_1"
|
283
301
|
fixt.source.should == 8.5
|
284
302
|
fixt.to_f.should == 8.5
|
303
|
+
fixt.to_s.should == "8.5"
|
285
304
|
fixt.to_i.should == 8
|
286
305
|
fixt.frac.should == 0.5
|
287
306
|
fixt.to_h.should == "11"
|
@@ -297,6 +316,7 @@ it "returns 2.5 for initalise of 2.5" do
|
|
297
316
|
fixt.binary = "1000_1"
|
298
317
|
fixt.source.should == 8.5
|
299
318
|
fixt.to_f.should == 8.5
|
319
|
+
fixt.to_s.should == "8.5"
|
300
320
|
fixt.to_i.should == 8
|
301
321
|
fixt.frac.should == 0.5
|
302
322
|
fixt.to_h.should == "11"
|
metadata
CHANGED
@@ -1,33 +1,22 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixed_point
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 0.1.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Morgan Prior
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-01-22 00:00:00 +00:00
|
19
|
-
default_executable:
|
12
|
+
date: 2012-05-10 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
14
|
description: Fixed Point numerical type for simulating fixed point calculations
|
23
15
|
email: fixed_point_gem@amaras-tech.co.uk
|
24
16
|
executables: []
|
25
|
-
|
26
17
|
extensions: []
|
27
|
-
|
28
18
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
19
|
+
files:
|
31
20
|
- LICENSE
|
32
21
|
- README.md
|
33
22
|
- HISTORY.md
|
@@ -40,39 +29,28 @@ files:
|
|
40
29
|
- spec/fixed_point_negative_spec.rb
|
41
30
|
- spec/fixed_point_spec.rb
|
42
31
|
- spec/spec_helper.rb
|
43
|
-
has_rdoc: true
|
44
32
|
homepage: http://amaras-tech.co.uk/software/fixed_point
|
45
33
|
licenses: []
|
46
|
-
|
47
34
|
post_install_message:
|
48
35
|
rdoc_options: []
|
49
|
-
|
50
|
-
require_paths:
|
36
|
+
require_paths:
|
51
37
|
- lib
|
52
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
39
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
|
59
|
-
- 0
|
60
|
-
version: "0"
|
61
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
45
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
|
67
|
-
segments:
|
68
|
-
- 0
|
69
|
-
version: "0"
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
70
50
|
requirements: []
|
71
|
-
|
72
51
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.
|
52
|
+
rubygems_version: 1.8.23
|
74
53
|
signing_key:
|
75
54
|
specification_version: 3
|
76
55
|
summary: Fixed Point numerical type
|
77
56
|
test_files: []
|
78
|
-
|