float-formats 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/config/hoe.rb DELETED
@@ -1,73 +0,0 @@
1
- require 'float-formats/version'
2
-
3
- AUTHOR = 'Javier Goizueta' # can also be an array of Authors
4
- EMAIL = "javier@goizueta.info"
5
- DESCRIPTION = "Floating-Point Formats"
6
- GEM_NAME = 'float-formats' # what ppl will type to install your gem
7
- RUBYFORGE_PROJECT = 'float-formats' # The unix name for your project
8
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
- DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
-
11
- @config_file = "C:/Documents and Settings/jgoizueta/.rubyforge/user-config.yml"
12
- @config = nil
13
- RUBYFORGE_USERNAME = "jgoizueta"
14
- def rubyforge_username
15
- unless @config
16
- begin
17
- @config = YAML.load(File.read(File.expand_path(@config_file)))
18
- rescue
19
- puts <<-EOS
20
- ERROR: No rubyforge config file found: #{@config_file}
21
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
- - See http://newgem.rubyforge.org/rubyforge.html for more details
23
- EOS
24
- exit
25
- end
26
- end
27
- RUBYFORGE_USERNAME.replace @config["username"]
28
- end
29
-
30
-
31
- REV = nil
32
- # UNCOMMENT IF REQUIRED:
33
- # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
- VERS = FltPnt::VERSION::STRING + (REV ? ".#{REV}" : "")
35
- RDOC_OPTS = ['--quiet', '--title', 'float-formats documentation',
36
- "--opname", "index.html",
37
- "--line-numbers",
38
- "--main", "README",
39
- "--inline-source"]
40
-
41
- class Hoe
42
- def extra_deps
43
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
- @extra_deps
45
- end
46
- end
47
-
48
- # Generate all the Rake tasks
49
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
- hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
- p.author = AUTHOR
52
- p.description = DESCRIPTION
53
- p.email = EMAIL
54
- p.summary = DESCRIPTION
55
- p.url = HOMEPATH
56
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
- p.test_globs = ["test/**/test_*.rb"]
58
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
-
60
- # == Optional
61
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
62
- p.extra_deps = [
63
- ['nio', '>=0.2.1']
64
- ]
65
-
66
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
-
68
- end
69
-
70
- CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
71
- PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
72
- hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
73
- hoe.rsync_args = '-av --delete --ignore-errors'
@@ -1,17 +0,0 @@
1
- require 'fileutils'
2
- include FileUtils
3
-
4
- require 'rubygems'
5
- %w[rake hoe newgem rubigen].each do |req_gem|
6
- begin
7
- require req_gem
8
- rescue LoadError
9
- puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
- puts "Installation: gem install #{req_gem} -y"
11
- exit
12
- end
13
- end
14
-
15
- $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
-
17
- require 'float-formats'
data/script/destroy DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/destroy'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
14
- RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/destroy.cmd DELETED
@@ -1 +0,0 @@
1
- @ruby script/destroy %*
data/script/generate DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/generate'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
14
- RubiGen::Scripts::Generate.new.run(ARGV)
data/script/generate.cmd DELETED
@@ -1 +0,0 @@
1
- @ruby script/generate %*
data/script/txt2html DELETED
@@ -1,74 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- begin
5
- require 'newgem'
6
- rescue LoadError
7
- puts "\n\nGenerating the website requires the newgem RubyGem"
8
- puts "Install: gem install newgem\n\n"
9
- exit(1)
10
- end
11
- require 'redcloth'
12
- require 'syntax/convertors/html'
13
- require 'erb'
14
- require File.dirname(__FILE__) + '/../lib/float-formats/version.rb'
15
-
16
- version = Float-formats::VERSION::STRING
17
- download = 'http://rubyforge.org/projects/float-formats'
18
-
19
- class Fixnum
20
- def ordinal
21
- # teens
22
- return 'th' if (10..19).include?(self % 100)
23
- # others
24
- case self % 10
25
- when 1: return 'st'
26
- when 2: return 'nd'
27
- when 3: return 'rd'
28
- else return 'th'
29
- end
30
- end
31
- end
32
-
33
- class Time
34
- def pretty
35
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
- end
37
- end
38
-
39
- def convert_syntax(syntax, source)
40
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
- end
42
-
43
- if ARGV.length >= 1
44
- src, template = ARGV
45
- template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
-
47
- else
48
- puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
49
- exit!
50
- end
51
-
52
- template = ERB.new(File.open(template).read)
53
-
54
- title = nil
55
- body = nil
56
- File.open(src) do |fsrc|
57
- title_text = fsrc.readline
58
- body_text = fsrc.read
59
- syntax_items = []
60
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
- ident = syntax_items.length
62
- element, syntax, source = $1, $2, $3
63
- syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
- "syntax-temp-#{ident}"
65
- }
66
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
- body = RedCloth.new(body_text).to_html
68
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
- end
70
- stat = File.stat(src)
71
- created = stat.ctime
72
- modified = stat.mtime
73
-
74
- $stdout << template.result(binding)
data/script/txt2html.cmd DELETED
@@ -1 +0,0 @@
1
- @ruby script/txt2html %*
@@ -1,34 +0,0 @@
1
- desc 'Release the website and new gem version'
2
- task :deploy => [:check_version, :website, :release] do
3
- puts "Remember to create SVN tag:"
4
- puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
- "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
- puts "Suggested comment:"
7
- puts "Tagging release #{CHANGES}"
8
- end
9
-
10
- desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
- task :local_deploy => [:website_generate, :install_gem]
12
-
13
- task :check_version do
14
- unless ENV['VERSION']
15
- puts 'Must pass a VERSION=x.y.z release version'
16
- exit
17
- end
18
- unless ENV['VERSION'] == VERS
19
- puts "Please update your version.rb to match the release version, currently #{VERS}"
20
- exit
21
- end
22
- end
23
-
24
- desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
- task :install_gem_no_doc => [:clean, :package] do
26
- sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
- end
28
-
29
- namespace :manifest do
30
- desc 'Recreate Manifest.txt to include ALL files'
31
- task :refresh do
32
- `rake check_manifest | patch -p0 > Manifest.txt`
33
- end
34
- end
@@ -1,7 +0,0 @@
1
- task :ruby_env do
2
- RUBY_APP = if RUBY_PLATFORM =~ /java/
3
- "jruby"
4
- else
5
- "ruby"
6
- end unless defined? RUBY_APP
7
- end
data/tasks/website.rake DELETED
@@ -1,17 +0,0 @@
1
- desc 'Generate website files'
2
- task :website_generate => :ruby_env do
3
- (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
- sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
- end
6
- end
7
-
8
- desc 'Upload website files to rubyforge'
9
- task :website_upload do
10
- host = "#{rubyforge_username}@rubyforge.org"
11
- remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
- local_dir = 'website'
13
- sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
- end
15
-
16
- desc 'Generate and upload website files'
17
- task :website => [:website_generate, :website_upload, :publish_docs]
@@ -1,169 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
- require 'yaml'
3
-
4
- include FltPnt
5
-
6
- class TestFloatFormats < Test::Unit::TestCase
7
-
8
- def setup
9
- end
10
-
11
- def test_nextprev
12
- for tn in %w{IEEE_SINGLE IEEE_DOUBLE IEEE_EXTENDED IEEE_DEC32 IEEE_DEC64 IEEE_DEC128}
13
- t = eval(tn)
14
- z = t.from_fmt('0')
15
- assert t.prev_float(t.min_value)==z,"#{tn}: prv min == 0"
16
- assert t.next_float(z)==t.min_value,"#{tn}: nxt 0 == min"
17
-
18
- mz = t.from_fmt('-0')
19
- assert t.next_float(t.min_value(1))==mz,"#{tn}: nxt -min == -0"
20
- assert t.prev_float(mz)==t.min_value(1),"#{tn}: prv -0 == -min"
21
-
22
- assert t.prev_float(z)==t.min_value(1),"#{tn}: prv 0 == -min"
23
- assert t.next_float(mz)==t.min_value,"#{tn}: nxt -0 == min"
24
- end
25
-
26
- for tn in %w{
27
- APPLE XS128
28
- BORLAND48
29
- MBF_SINGLE MBF_DOUBLE
30
- IEEE_SINGLE IEEE_DOUBLE IEEE_EXTENDED IEEE_128
31
- IEEE_DEC32 IEEE_DEC64 IEEE_DEC128
32
- XS256 XS256_DOUBLE
33
- SATURN SATURN_X HP_CLASSIC
34
- VAX_F VAX_D PDP11_F PDP11_D VAX_G VAX_H
35
- IBM32 IBM64 IBM128 IBMX
36
- CDC_SINGLE CDC_DOUBLE
37
- CRAY
38
- UNIVAC_SINGLE UNIVAC_DOUBLE
39
- WANG2200
40
- C51_BCD_FLOAT C51_BCD_DOUBLE C51_BCD_LONG_DOUBLE
41
- }
42
- t = eval(tn)
43
- u = t.from_fmt('1')
44
- mu = t.from_fmt('-1')
45
- assert t.neg(t.next_float(u)) == t.prev_float(mu),"#{tn}: -nxt 1 == prv -1"
46
- assert t.next_float(mu) == t.neg(t.prev_float(u)),"#{tn}: nxt -1 == -prv 1"
47
-
48
- end
49
-
50
- end
51
-
52
- TEST_DATA = YAML.load(File.read(File.join(File.dirname(__FILE__),'test_data.yaml')))
53
-
54
-
55
- def test_all
56
-
57
- TEST_DATA.keys.each do |t|
58
-
59
- flt = eval(t)
60
-
61
- base = TEST_DATA[t]['base']
62
-
63
- td = TEST_DATA[t]['parameters']
64
-
65
- #puts "def test_#{t}_parameters"
66
- for pair in td
67
- attrb,v = pair.to_a.first
68
- #puts " assert_equal #{v}, #{t}.#{attrb}"
69
- assert_equal v, flt.send(attrb), "#{t}.#{attrb} == #{v}"
70
- end
71
- #puts "end"
72
-
73
-
74
- td = TEST_DATA[t]['numerals']
75
- #puts "def test_#{t}_numerals"
76
- for pair in td
77
- v,rep = pair.to_a.first
78
- v_expr = "#{t}.from_fmt('#{v}')"
79
- expr = base==:bytes ? "#{t}.to_hex(#{v_expr},true)" : "#{t}.to_bits_text(#{v_expr},#{base}).upcase"
80
- #puts " assert_equal '#{rep}', #{expr}"
81
- assert_equal rep, eval(expr), "#{expr} == '#{rep}'"
82
- end
83
- #puts "end"
84
-
85
-
86
- td = TEST_DATA[t]['special']
87
- #puts "def test_#{t}_special"
88
- for pair in td
89
- v,rep = pair.to_a.first
90
- #next if v=='epsilon'
91
- v_expr = "#{t}.#{v}"
92
- expr = base==:bytes ? "#{t}.to_hex(#{v_expr},true)" : "#{t}.to_bits_text(#{v_expr},#{base}).upcase"
93
- assert_equal rep, eval(expr), "#{expr} == '#{rep}'"
94
- end
95
- #puts "end"
96
-
97
-
98
- td = TEST_DATA[t]['values']
99
- #puts "def test_#{t}_values"
100
- for pair in td
101
- v,rep = pair.to_a.first
102
- v_expr = "#{t}.from_number(#{v})"
103
- expr = base==:bytes ? "#{t}.to_hex(#{v_expr},true)" : "#{t}.to_bits_text(#{v_expr},#{base}).upcase"
104
- assert_equal rep, eval(expr), "#{expr} == '#{rep}'"
105
- end
106
- #puts "end"
107
-
108
-
109
- end
110
-
111
- end
112
-
113
- def test_hp71b
114
- assert_equal(-499, HP71B.radix_min_exp)
115
- assert_equal(499, HP71B.radix_max_exp)
116
-
117
- fmt = Nio::Fmt.prec(12)
118
- assert_equal '9.99999999999E499', HP71B.max_value.to_fmt(fmt)
119
- assert_equal '0000000000001501', HP71B.min_value.to_bits_text(16)
120
- assert_equal '1E-510', HP71B.min_value.to_fmt(fmt)
121
- assert_equal '1E-499', HP71B.min_normalized_value.to_fmt(fmt)
122
-
123
- assert_equal '9210000000000999',HP71B.from_fmt('-0.21').to_bits_text(16)
124
- assert_equal '0100000000000001',HP71B.from_fmt('10').to_bits_text(16)
125
- assert_equal '9000000000000000',HP71B.from_fmt('-0').to_bits_text(16)
126
- assert_equal '0000510000000501', HP71B.from_fmt('0.0051E-499').to_bits_text(16)
127
-
128
- assert_equal '0000000000000F01',HP71B.nan.to_bits_text(16).upcase
129
- assert_equal 'NAN', HP71B.nan.to_fmt.upcase
130
- assert_equal '0000000000000F00', HP71B.infinity.to_bits_text(16).upcase
131
- assert_equal '+INFINITY', HP71B.infinity.to_fmt.upcase
132
- assert_equal '9000000000000F00', HP71B.infinity.neg.to_bits_text(16).upcase
133
- end
134
- def test_quad
135
- assert_equal "3fff 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.from_fmt('1').to_hex.downcase
136
- assert_equal "7ffe ffff ffff ffff ffff ffff ffff ffff".tr(' ',''), IEEE_binary128_BE.max_value.to_hex.downcase
137
- assert_equal '1.19E4932', IEEE_binary128.max_value.to_fmt(Nio::Fmt.prec(4))
138
- assert_equal "c000 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.from_fmt('-2').to_hex.downcase
139
- assert_equal "0000 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.from_fmt('0').to_hex.downcase
140
- assert_equal "8000 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.from_fmt('-0').to_hex.downcase
141
- assert_equal "7fff 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.infinity.to_hex.downcase
142
- assert_equal "ffff 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.infinity(1).to_hex.downcase
143
- assert_equal "3ffd 5555 5555 5555 5555 5555 5555 5555".tr(' ',''), IEEE_binary128_BE.from_number(Rational(1,3)).to_hex.downcase
144
- assert_equal "3fff 0000 0000 0000 0000 0000 0000 0001".tr(' ',''), IEEE_binary128_BE.from_fmt('1').next.to_hex.downcase
145
- end
146
- def test_half
147
- assert_equal "3c00", IEEE_binary16_BE.from_fmt('1').to_hex.downcase
148
- assert_equal "7bff", IEEE_binary16_BE.max_value.to_hex.downcase
149
- assert_equal '65504', IEEE_binary16_BE.max_value.to_fmt
150
- assert_equal "0400", IEEE_binary16_BE.min_normalized_value.to_hex.downcase
151
- assert_equal "6.103515625E-5", IEEE_binary16_BE.min_normalized_value.to_fmt
152
- assert_equal "0001", IEEE_binary16_BE.min_value.to_hex.downcase
153
- assert_equal "5.9604644775390625E-8", IEEE_binary16_BE.min_value.to_fmt
154
- assert_equal "0000", IEEE_binary16_BE.from_fmt('0').to_hex.downcase
155
- assert_equal "8000", IEEE_binary16_BE.from_fmt('-0').to_hex.downcase
156
- assert_equal "7c00".tr(' ',''), IEEE_binary16_BE.infinity.to_hex.downcase
157
- assert_equal "fc00".tr(' ',''), IEEE_binary16_BE.infinity(1).to_hex.downcase
158
- end
159
- def test_special
160
- assert_equal '+Infinity', IEEE_binary32.from_number(1.0/0.0).to_fmt
161
- assert_equal '-Infinity', IEEE_binary32.from_number(-1.0/0.0).to_fmt
162
- assert_equal '+Infinity', IEEE_binary32.from_fmt('+Infinity').to_fmt
163
- assert_equal '-Infinity', IEEE_binary32.from_fmt('-Infinity').to_fmt
164
- assert_equal 'NAN', IEEE_binary32.from_number(0.0/0.0).to_fmt.upcase
165
- assert_equal 'NAN', IEEE_binary32.from_fmt('NaN').to_fmt.upcase
166
- end
167
-
168
-
169
- end