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/History.txt +27 -32
- data/Manifest.txt +10 -18
- data/README.txt +330 -327
- data/Rakefile +38 -4
- data/lib/float-formats.rb +9 -9
- data/lib/float-formats/bytes.rb +463 -303
- data/lib/float-formats/classes.rb +1950 -1605
- data/lib/float-formats/formats.rb +633 -669
- data/lib/float-formats/native.rb +144 -272
- data/lib/float-formats/version.rb +4 -4
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +192 -0
- data/tasks/git.rake +40 -0
- data/tasks/manifest.rake +48 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +39 -0
- data/tasks/rdoc.rake +50 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +279 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/test/gen_test_data.rb +119 -119
- data/test/test_arithmetic.rb +36 -0
- data/test/test_bytes.rb +43 -0
- data/test/test_data.yaml +1667 -1667
- data/test/test_float_formats.rb +208 -0
- data/test/test_helper.rb +2 -1
- data/test/test_native-float.rb +84 -77
- metadata +123 -60
- data/config/hoe.rb +0 -73
- data/config/requirements.rb +0 -17
- data/script/destroy +0 -14
- data/script/destroy.cmd +0 -1
- data/script/generate +0 -14
- data/script/generate.cmd +0 -1
- data/script/txt2html +0 -74
- data/script/txt2html.cmd +0 -1
- data/tasks/deployment.rake +0 -34
- data/tasks/environment.rake +0 -7
- data/tasks/website.rake +0 -17
- data/test/test_float-formats.rb +0 -169
data/tasks/setup.rb
ADDED
@@ -0,0 +1,279 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'ostruct'
|
7
|
+
|
8
|
+
class OpenStruct; undef :gem; end
|
9
|
+
|
10
|
+
# TODO: make my own openstruct type object that includes descriptions
|
11
|
+
# TODO: use the descriptions to output help on the available bones options
|
12
|
+
|
13
|
+
PROJ = OpenStruct.new(
|
14
|
+
# Project Defaults
|
15
|
+
:name => nil,
|
16
|
+
:summary => nil,
|
17
|
+
:description => nil,
|
18
|
+
:changes => nil,
|
19
|
+
:authors => nil,
|
20
|
+
:email => nil,
|
21
|
+
:url => "\000",
|
22
|
+
:version => ENV['VERSION'] || '0.0.0',
|
23
|
+
:exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git/ ^pkg/),
|
24
|
+
:release_name => ENV['RELEASE'],
|
25
|
+
|
26
|
+
# System Defaults
|
27
|
+
:ruby_opts => %w(-w),
|
28
|
+
:libs => [],
|
29
|
+
:history_file => 'History.txt',
|
30
|
+
:manifest_file => 'Manifest.txt',
|
31
|
+
:readme_file => 'README.txt',
|
32
|
+
|
33
|
+
# Announce
|
34
|
+
:ann => OpenStruct.new(
|
35
|
+
:file => 'announcement.txt',
|
36
|
+
:text => nil,
|
37
|
+
:paragraphs => [],
|
38
|
+
:email => {
|
39
|
+
:from => nil,
|
40
|
+
:to => %w(ruby-talk@ruby-lang.org),
|
41
|
+
:server => 'localhost',
|
42
|
+
:port => 25,
|
43
|
+
:domain => ENV['HOSTNAME'],
|
44
|
+
:acct => nil,
|
45
|
+
:passwd => nil,
|
46
|
+
:authtype => :plain
|
47
|
+
}
|
48
|
+
),
|
49
|
+
|
50
|
+
# Gem Packaging
|
51
|
+
:gem => OpenStruct.new(
|
52
|
+
:dependencies => [],
|
53
|
+
:development_dependencies => [],
|
54
|
+
:executables => nil,
|
55
|
+
:extensions => FileList['ext/**/extconf.rb'],
|
56
|
+
:files => nil,
|
57
|
+
:need_tar => true,
|
58
|
+
:need_zip => false,
|
59
|
+
:extras => {}
|
60
|
+
),
|
61
|
+
|
62
|
+
# File Annotations
|
63
|
+
:notes => OpenStruct.new(
|
64
|
+
:exclude => %w(^tasks/setup\.rb$),
|
65
|
+
:extensions => %w(.txt .rb .erb .rdoc) << '',
|
66
|
+
:tags => %w(FIXME OPTIMIZE TODO)
|
67
|
+
),
|
68
|
+
|
69
|
+
# Rcov
|
70
|
+
:rcov => OpenStruct.new(
|
71
|
+
:dir => 'coverage',
|
72
|
+
:opts => %w[--sort coverage -T],
|
73
|
+
:threshold => 90.0,
|
74
|
+
:threshold_exact => false
|
75
|
+
),
|
76
|
+
|
77
|
+
# Rdoc
|
78
|
+
:rdoc => OpenStruct.new(
|
79
|
+
:opts => [],
|
80
|
+
:include => %w(^lib/ ^bin/ ^ext/ \.txt$ \.rdoc$),
|
81
|
+
:exclude => %w(extconf\.rb$),
|
82
|
+
:main => nil,
|
83
|
+
:dir => 'doc',
|
84
|
+
:remote_dir => nil
|
85
|
+
),
|
86
|
+
|
87
|
+
# Rubyforge
|
88
|
+
:rubyforge => OpenStruct.new(
|
89
|
+
:name => "\000"
|
90
|
+
),
|
91
|
+
|
92
|
+
# Rspec
|
93
|
+
:spec => OpenStruct.new(
|
94
|
+
:files => FileList['spec/**/*_spec.rb'],
|
95
|
+
:opts => []
|
96
|
+
),
|
97
|
+
|
98
|
+
# Subversion Repository
|
99
|
+
:svn => OpenStruct.new(
|
100
|
+
:root => nil,
|
101
|
+
:path => '',
|
102
|
+
:trunk => 'trunk',
|
103
|
+
:tags => 'tags',
|
104
|
+
:branches => 'branches'
|
105
|
+
),
|
106
|
+
|
107
|
+
# Test::Unit
|
108
|
+
:test => OpenStruct.new(
|
109
|
+
:files => FileList['test/**/test_*.rb'],
|
110
|
+
:file => 'test/all.rb',
|
111
|
+
:opts => []
|
112
|
+
)
|
113
|
+
)
|
114
|
+
|
115
|
+
# Load the other rake files in the tasks folder
|
116
|
+
tasks_dir = File.expand_path(File.dirname(__FILE__))
|
117
|
+
post_load_fn = File.join(tasks_dir, 'post_load.rake')
|
118
|
+
rakefiles = Dir.glob(File.join(tasks_dir, '*.rake')).sort
|
119
|
+
rakefiles.unshift(rakefiles.delete(post_load_fn)).compact!
|
120
|
+
import(*rakefiles)
|
121
|
+
|
122
|
+
# Setup the project libraries
|
123
|
+
%w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
|
124
|
+
|
125
|
+
# Setup some constants
|
126
|
+
WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
|
127
|
+
|
128
|
+
DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
|
129
|
+
|
130
|
+
def quiet( &block )
|
131
|
+
io = [STDOUT.dup, STDERR.dup]
|
132
|
+
STDOUT.reopen DEV_NULL
|
133
|
+
STDERR.reopen DEV_NULL
|
134
|
+
block.call
|
135
|
+
ensure
|
136
|
+
STDOUT.reopen io.first
|
137
|
+
STDERR.reopen io.last
|
138
|
+
$stdout, $stderr = STDOUT, STDERR
|
139
|
+
end
|
140
|
+
|
141
|
+
DIFF = if WIN32 then 'diff.exe'
|
142
|
+
else
|
143
|
+
if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
|
144
|
+
else 'diff' end
|
145
|
+
end unless defined? DIFF
|
146
|
+
|
147
|
+
SUDO = if WIN32 then ''
|
148
|
+
else
|
149
|
+
if quiet {system 'which sudo'} then 'sudo'
|
150
|
+
else '' end
|
151
|
+
end
|
152
|
+
|
153
|
+
RCOV = WIN32 ? 'rcov.bat' : 'rcov'
|
154
|
+
RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
|
155
|
+
GEM = WIN32 ? 'gem.bat' : 'gem'
|
156
|
+
|
157
|
+
%w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
|
158
|
+
begin
|
159
|
+
require lib
|
160
|
+
Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
|
161
|
+
rescue LoadError
|
162
|
+
Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
|
163
|
+
end
|
164
|
+
end
|
165
|
+
HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
|
166
|
+
system("svn --version 2>&1 > #{DEV_NULL}"))
|
167
|
+
HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
|
168
|
+
system("git --version 2>&1 > #{DEV_NULL}"))
|
169
|
+
|
170
|
+
# Add bones as a development dependency
|
171
|
+
#
|
172
|
+
if HAVE_BONES
|
173
|
+
PROJ.gem.development_dependencies << ['bones', ">= #{Bones::VERSION}"]
|
174
|
+
end
|
175
|
+
|
176
|
+
# Reads a file at +path+ and spits out an array of the +paragraphs+
|
177
|
+
# specified.
|
178
|
+
#
|
179
|
+
# changes = paragraphs_of('History.txt', 0..1).join("\n\n")
|
180
|
+
# summary, *description = paragraphs_of('README.txt', 3, 3..8)
|
181
|
+
#
|
182
|
+
def paragraphs_of( path, *paragraphs )
|
183
|
+
title = String === paragraphs.first ? paragraphs.shift : nil
|
184
|
+
ary = File.read(path).delete("\r").split(/\n\n+/)
|
185
|
+
|
186
|
+
result = if title
|
187
|
+
tmp, matching = [], false
|
188
|
+
rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
|
189
|
+
paragraphs << (0..-1) if paragraphs.empty?
|
190
|
+
|
191
|
+
ary.each do |val|
|
192
|
+
if val =~ rgxp
|
193
|
+
break if matching
|
194
|
+
matching = true
|
195
|
+
rgxp = %r/^=+/i
|
196
|
+
elsif matching
|
197
|
+
tmp << val
|
198
|
+
end
|
199
|
+
end
|
200
|
+
tmp
|
201
|
+
else ary end
|
202
|
+
|
203
|
+
result.values_at(*paragraphs)
|
204
|
+
end
|
205
|
+
|
206
|
+
# Adds the given gem _name_ to the current project's dependency list. An
|
207
|
+
# optional gem _version_ can be given. If omitted, the newest gem version
|
208
|
+
# will be used.
|
209
|
+
#
|
210
|
+
def depend_on( name, version = nil )
|
211
|
+
spec = Gem.source_index.find_name(name).last
|
212
|
+
version = spec.version.to_s if version.nil? and !spec.nil?
|
213
|
+
|
214
|
+
PROJ.gem.dependencies << case version
|
215
|
+
when nil; [name]
|
216
|
+
when %r/^\d/; [name, ">= #{version}"]
|
217
|
+
else [name, version] end
|
218
|
+
end
|
219
|
+
|
220
|
+
# Adds the given arguments to the include path if they are not already there
|
221
|
+
#
|
222
|
+
def ensure_in_path( *args )
|
223
|
+
args.each do |path|
|
224
|
+
path = File.expand_path(path)
|
225
|
+
$:.unshift(path) if test(?d, path) and not $:.include?(path)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# Find a rake task using the task name and remove any description text. This
|
230
|
+
# will prevent the task from being displayed in the list of available tasks.
|
231
|
+
#
|
232
|
+
def remove_desc_for_task( names )
|
233
|
+
Array(names).each do |task_name|
|
234
|
+
task = Rake.application.tasks.find {|t| t.name == task_name}
|
235
|
+
next if task.nil?
|
236
|
+
task.instance_variable_set :@comment, nil
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
# Change working directories to _dir_, call the _block_ of code, and then
|
241
|
+
# change back to the original working directory (the current directory when
|
242
|
+
# this method was called).
|
243
|
+
#
|
244
|
+
def in_directory( dir, &block )
|
245
|
+
curdir = pwd
|
246
|
+
begin
|
247
|
+
cd dir
|
248
|
+
return block.call
|
249
|
+
ensure
|
250
|
+
cd curdir
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
# Scans the current working directory and creates a list of files that are
|
255
|
+
# candidates to be in the manifest.
|
256
|
+
#
|
257
|
+
def manifest_files
|
258
|
+
files = []
|
259
|
+
exclude = Regexp.new(PROJ.exclude.join('|'))
|
260
|
+
Find.find '.' do |path|
|
261
|
+
path.sub! %r/^(\.\/|\/)/o, ''
|
262
|
+
next unless test ?f, path
|
263
|
+
next if path =~ exclude
|
264
|
+
files << path
|
265
|
+
end
|
266
|
+
files.sort!
|
267
|
+
end
|
268
|
+
|
269
|
+
# We need a "valid" method thtat determines if a string is suitable for use
|
270
|
+
# in the gem specification.
|
271
|
+
#
|
272
|
+
class Object
|
273
|
+
def valid?
|
274
|
+
return !(self.empty? or self == "\000") if self.respond_to?(:to_str)
|
275
|
+
return false
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
# EOF
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
|
3
|
+
require 'spec/rake/verify_rcov'
|
4
|
+
|
5
|
+
namespace :spec do
|
6
|
+
|
7
|
+
desc 'Run all specs with basic output'
|
8
|
+
Spec::Rake::SpecTask.new(:run) do |t|
|
9
|
+
t.ruby_opts = PROJ.ruby_opts
|
10
|
+
t.spec_opts = PROJ.spec.opts
|
11
|
+
t.spec_files = PROJ.spec.files
|
12
|
+
t.libs += PROJ.libs
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run all specs with text output'
|
16
|
+
Spec::Rake::SpecTask.new(:specdoc) do |t|
|
17
|
+
t.ruby_opts = PROJ.ruby_opts
|
18
|
+
t.spec_opts = PROJ.spec.opts + ['--format', 'specdoc']
|
19
|
+
t.spec_files = PROJ.spec.files
|
20
|
+
t.libs += PROJ.libs
|
21
|
+
end
|
22
|
+
|
23
|
+
if HAVE_RCOV
|
24
|
+
desc 'Run all specs with RCov'
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
26
|
+
t.ruby_opts = PROJ.ruby_opts
|
27
|
+
t.spec_opts = PROJ.spec.opts
|
28
|
+
t.spec_files = PROJ.spec.files
|
29
|
+
t.libs += PROJ.libs
|
30
|
+
t.rcov = true
|
31
|
+
t.rcov_dir = PROJ.rcov.dir
|
32
|
+
t.rcov_opts = PROJ.rcov.opts + ['--exclude', 'spec']
|
33
|
+
end
|
34
|
+
|
35
|
+
RCov::VerifyTask.new(:verify) do |t|
|
36
|
+
t.threshold = PROJ.rcov.threshold
|
37
|
+
t.index_html = File.join(PROJ.rcov.dir, 'index.html')
|
38
|
+
t.require_exact_threshold = PROJ.rcov.threshold_exact
|
39
|
+
end
|
40
|
+
|
41
|
+
task :verify => :rcov
|
42
|
+
remove_desc_for_task %w(spec:clobber_rcov)
|
43
|
+
end
|
44
|
+
|
45
|
+
end # namespace :spec
|
46
|
+
|
47
|
+
desc 'Alias to spec:run'
|
48
|
+
task :spec => 'spec:run'
|
49
|
+
|
50
|
+
task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
|
51
|
+
|
52
|
+
end # if HAVE_SPEC_RAKE_SPECTASK
|
53
|
+
|
54
|
+
# EOF
|
data/tasks/svn.rake
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
if HAVE_SVN
|
3
|
+
|
4
|
+
unless PROJ.svn.root
|
5
|
+
info = %x/svn info ./
|
6
|
+
m = %r/^Repository Root:\s+(.*)$/.match(info)
|
7
|
+
PROJ.svn.root = (m.nil? ? '' : m[1])
|
8
|
+
end
|
9
|
+
PROJ.svn.root = File.join(PROJ.svn.root, PROJ.svn.path) unless PROJ.svn.path.empty?
|
10
|
+
|
11
|
+
namespace :svn do
|
12
|
+
|
13
|
+
# A prerequisites task that all other tasks depend upon
|
14
|
+
task :prereqs
|
15
|
+
|
16
|
+
desc 'Show tags from the SVN repository'
|
17
|
+
task :show_tags => 'svn:prereqs' do |t|
|
18
|
+
tags = %x/svn list #{File.join(PROJ.svn.root, PROJ.svn.tags)}/
|
19
|
+
tags.gsub!(%r/\/$/, '')
|
20
|
+
tags = tags.split("\n").sort {|a,b| b <=> a}
|
21
|
+
puts tags
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Create a new tag in the SVN repository'
|
25
|
+
task :create_tag => 'svn:prereqs' do |t|
|
26
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
27
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
28
|
+
|
29
|
+
svn = PROJ.svn
|
30
|
+
trunk = File.join(svn.root, svn.trunk)
|
31
|
+
tag = "%s-%s" % [PROJ.name, PROJ.version]
|
32
|
+
tag = File.join(svn.root, svn.tags, tag)
|
33
|
+
msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
|
34
|
+
|
35
|
+
puts "Creating SVN tag '#{tag}'"
|
36
|
+
unless system "svn cp -m '#{msg}' #{trunk} #{tag}"
|
37
|
+
abort "Tag creation failed"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end # namespace :svn
|
42
|
+
|
43
|
+
task 'gem:release' => 'svn:create_tag'
|
44
|
+
|
45
|
+
end # if PROJ.svn.path
|
46
|
+
|
47
|
+
# EOF
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
|
7
|
+
Rake::TestTask.new(:run) do |t|
|
8
|
+
t.libs = PROJ.libs
|
9
|
+
t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
|
10
|
+
else PROJ.test.files end
|
11
|
+
t.ruby_opts += PROJ.ruby_opts
|
12
|
+
t.ruby_opts += PROJ.test.opts
|
13
|
+
end
|
14
|
+
|
15
|
+
if HAVE_RCOV
|
16
|
+
desc 'Run rcov on the unit tests'
|
17
|
+
task :rcov => :clobber_rcov do
|
18
|
+
opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
|
19
|
+
opts = opts.join(' ')
|
20
|
+
files = if test(?f, PROJ.test.file) then [PROJ.test.file]
|
21
|
+
else PROJ.test.files end
|
22
|
+
files = files.join(' ')
|
23
|
+
sh "#{RCOV} #{files} #{opts}"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :clobber_rcov do
|
27
|
+
rm_r 'coverage' rescue nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end # namespace :test
|
32
|
+
|
33
|
+
desc 'Alias to test:run'
|
34
|
+
task :test => 'test:run'
|
35
|
+
|
36
|
+
task :clobber => 'test:clobber_rcov' if HAVE_RCOV
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
# EOF
|
data/test/gen_test_data.rb
CHANGED
@@ -1,119 +1,119 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../lib/float-formats'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
include
|
5
|
-
include Nio
|
6
|
-
|
7
|
-
|
8
|
-
TVALUES = [
|
9
|
-
'+0', '-0', '+1','-1','+0.1','-0.1',
|
10
|
-
'0.5','-0.5',
|
11
|
-
'29.2','-29.2','0.03125','-0.03125','-0.3125',
|
12
|
-
'1.234E2','-1.234E-6','65536.0','-65536.0',
|
13
|
-
'-7.50'
|
14
|
-
]
|
15
|
-
|
16
|
-
VALUES = [
|
17
|
-
Rational(1,3),
|
18
|
-
Rational(1,10),
|
19
|
-
Rational(2,3),
|
20
|
-
Rational(1,1024),
|
21
|
-
Rational(1,1000),
|
22
|
-
Rational(1024,1),
|
23
|
-
Rational(1024,1)
|
24
|
-
]
|
25
|
-
|
26
|
-
TEST_DATA = {}
|
27
|
-
|
28
|
-
def is_power_of_two(n)
|
29
|
-
nbits = 0
|
30
|
-
while n>0
|
31
|
-
nbits += 1 if n&1==1
|
32
|
-
n >>= 1
|
33
|
-
end
|
34
|
-
nbits==1
|
35
|
-
end
|
36
|
-
|
37
|
-
EXCEPTIONS = {
|
38
|
-
UNIVAC_DOUBLE=>16,
|
39
|
-
UNIVAC_SINGLE=>16,
|
40
|
-
SATURN_X=>16
|
41
|
-
}
|
42
|
-
def rep_mode(type)
|
43
|
-
m = EXCEPTIONS[type]
|
44
|
-
if m.nil?
|
45
|
-
if type.total_bits % 8 == 0 # is_power_of_two(flt.total_bits)
|
46
|
-
m = :bytes
|
47
|
-
elsif type.total_bits % 4 == 0
|
48
|
-
m = 16
|
49
|
-
elsif type.total_bits % 3 == 0
|
50
|
-
m = 8
|
51
|
-
else
|
52
|
-
m = 2
|
53
|
-
end
|
54
|
-
end
|
55
|
-
m
|
56
|
-
end
|
57
|
-
|
58
|
-
%w{IEEE_SINGLE IEEE_DOUBLE IEEE_EXTENDED IEEE_128 XS128 XS256 XS256_DOUBLE
|
59
|
-
BORLAND48
|
60
|
-
MBF_SINGLE MBF_DOUBLE
|
61
|
-
VAX_F VAX_D VAX_G VAX_H
|
62
|
-
PDP11_F PDP11_D
|
63
|
-
SATURN SATURN_X HP_CLASSIC
|
64
|
-
IEEE_DEC32 IEEE_DEC64 IEEE_DEC128
|
65
|
-
IBM32 IBM64 IBM128
|
66
|
-
CRAY
|
67
|
-
UNIVAC_SINGLE UNIVAC_DOUBLE
|
68
|
-
CDC_SINGLE CDC_DOUBLE
|
69
|
-
APPLE
|
70
|
-
WANG2200
|
71
|
-
C51_BCD_FLOAT C51_BCD_DOUBLE C51_BCD_LONG_DOUBLE
|
72
|
-
}.each do |t|
|
73
|
-
|
74
|
-
puts t
|
75
|
-
flt = eval(t)
|
76
|
-
|
77
|
-
base = rep_mode(flt)
|
78
|
-
TEST_DATA[t] = {'base'=>base}
|
79
|
-
|
80
|
-
print "."
|
81
|
-
|
82
|
-
TEST_DATA[t]['parameters'] = []
|
83
|
-
for attrb in [:total_bits, :radix, :significand_digits, :radix_min_exp, :radix_max_exp,
|
84
|
-
:decimal_digits_stored, :decimal_digits_necessary,:decimal_min_exp,:decimal_max_exp]
|
85
|
-
TEST_DATA[t]['parameters'] << {attrb.to_s=>flt.send(attrb)}
|
86
|
-
end
|
87
|
-
|
88
|
-
print "."
|
89
|
-
TEST_DATA[t]['numerals'] = []
|
90
|
-
fmt = Fmt.mode(:gen,flt.decimal_digits_necessary)
|
91
|
-
#fmt = Fmt.default
|
92
|
-
for v in TVALUES + [:min_normalized_value, :max_value, :epsilon, :strict_epsilon].collect{|s| flt.to_fmt(flt.send(s),fmt)}
|
93
|
-
val = flt.from_fmt(v)
|
94
|
-
rep = base==:bytes ? flt.to_hex(val,true) : flt.to_bits_text(val,base).upcase
|
95
|
-
TEST_DATA[t]['numerals'] << {v => rep}
|
96
|
-
end
|
97
|
-
|
98
|
-
print "."
|
99
|
-
TEST_DATA[t]['special'] = []
|
100
|
-
[:min_value, :min_normalized_value, :max_value, :epsilon, :strict_epsilon].each do |v|
|
101
|
-
val = flt.send(v)
|
102
|
-
rep = base==:bytes ? flt.to_hex(val,true) : flt.to_bits_text(val,base).upcase
|
103
|
-
TEST_DATA[t]['special'] << {v.to_s=>rep}
|
104
|
-
end
|
105
|
-
|
106
|
-
print "."
|
107
|
-
TEST_DATA[t]['values'] = []
|
108
|
-
for v in VALUES
|
109
|
-
val = flt.from_number(v)
|
110
|
-
rep = base==:bytes ? flt.to_hex(val,true) : flt.to_bits_text(val,base).upcase
|
111
|
-
TEST_DATA[t]['values'] << {v.inspect=>rep}
|
112
|
-
end
|
113
|
-
puts ""
|
114
|
-
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
File.open(File.join(File.dirname(__FILE__),"test_data0.yaml"),"w"){|f| f.write TEST_DATA.to_yaml}
|
119
|
-
|
1
|
+
require File.dirname(__FILE__) + '/../lib/float-formats'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
include Flt
|
5
|
+
include Nio
|
6
|
+
|
7
|
+
|
8
|
+
TVALUES = [
|
9
|
+
'+0', '-0', '+1','-1','+0.1','-0.1',
|
10
|
+
'0.5','-0.5',
|
11
|
+
'29.2','-29.2','0.03125','-0.03125','-0.3125',
|
12
|
+
'1.234E2','-1.234E-6','65536.0','-65536.0',
|
13
|
+
'-7.50'
|
14
|
+
]
|
15
|
+
|
16
|
+
VALUES = [
|
17
|
+
Rational(1,3),
|
18
|
+
Rational(1,10),
|
19
|
+
Rational(2,3),
|
20
|
+
Rational(1,1024),
|
21
|
+
Rational(1,1000),
|
22
|
+
Rational(1024,1),
|
23
|
+
Rational(1024,1)
|
24
|
+
]
|
25
|
+
|
26
|
+
TEST_DATA = {}
|
27
|
+
|
28
|
+
def is_power_of_two(n)
|
29
|
+
nbits = 0
|
30
|
+
while n>0
|
31
|
+
nbits += 1 if n&1==1
|
32
|
+
n >>= 1
|
33
|
+
end
|
34
|
+
nbits==1
|
35
|
+
end
|
36
|
+
|
37
|
+
EXCEPTIONS = {
|
38
|
+
UNIVAC_DOUBLE=>16,
|
39
|
+
UNIVAC_SINGLE=>16,
|
40
|
+
SATURN_X=>16
|
41
|
+
}
|
42
|
+
def rep_mode(type)
|
43
|
+
m = EXCEPTIONS[type]
|
44
|
+
if m.nil?
|
45
|
+
if type.total_bits % 8 == 0 # is_power_of_two(flt.total_bits)
|
46
|
+
m = :bytes
|
47
|
+
elsif type.total_bits % 4 == 0
|
48
|
+
m = 16
|
49
|
+
elsif type.total_bits % 3 == 0
|
50
|
+
m = 8
|
51
|
+
else
|
52
|
+
m = 2
|
53
|
+
end
|
54
|
+
end
|
55
|
+
m
|
56
|
+
end
|
57
|
+
|
58
|
+
%w{IEEE_SINGLE IEEE_DOUBLE IEEE_EXTENDED IEEE_128 XS128 XS256 XS256_DOUBLE
|
59
|
+
BORLAND48
|
60
|
+
MBF_SINGLE MBF_DOUBLE
|
61
|
+
VAX_F VAX_D VAX_G VAX_H
|
62
|
+
PDP11_F PDP11_D
|
63
|
+
SATURN SATURN_X HP_CLASSIC
|
64
|
+
IEEE_DEC32 IEEE_DEC64 IEEE_DEC128
|
65
|
+
IBM32 IBM64 IBM128
|
66
|
+
CRAY
|
67
|
+
UNIVAC_SINGLE UNIVAC_DOUBLE
|
68
|
+
CDC_SINGLE CDC_DOUBLE
|
69
|
+
APPLE
|
70
|
+
WANG2200
|
71
|
+
C51_BCD_FLOAT C51_BCD_DOUBLE C51_BCD_LONG_DOUBLE
|
72
|
+
}.each do |t|
|
73
|
+
|
74
|
+
puts t
|
75
|
+
flt = eval(t)
|
76
|
+
|
77
|
+
base = rep_mode(flt)
|
78
|
+
TEST_DATA[t] = {'base'=>base}
|
79
|
+
|
80
|
+
print "."
|
81
|
+
|
82
|
+
TEST_DATA[t]['parameters'] = []
|
83
|
+
for attrb in [:total_bits, :radix, :significand_digits, :radix_min_exp, :radix_max_exp,
|
84
|
+
:decimal_digits_stored, :decimal_digits_necessary,:decimal_min_exp,:decimal_max_exp]
|
85
|
+
TEST_DATA[t]['parameters'] << {attrb.to_s=>flt.send(attrb)}
|
86
|
+
end
|
87
|
+
|
88
|
+
print "."
|
89
|
+
TEST_DATA[t]['numerals'] = []
|
90
|
+
fmt = Fmt.mode(:gen,flt.decimal_digits_necessary)
|
91
|
+
#fmt = Fmt.default
|
92
|
+
for v in TVALUES + [:min_normalized_value, :max_value, :epsilon, :strict_epsilon].collect{|s| flt.to_fmt(flt.send(s),fmt)}
|
93
|
+
val = flt.from_fmt(v)
|
94
|
+
rep = base==:bytes ? flt.to_hex(val,true) : flt.to_bits_text(val,base).upcase
|
95
|
+
TEST_DATA[t]['numerals'] << {v => rep}
|
96
|
+
end
|
97
|
+
|
98
|
+
print "."
|
99
|
+
TEST_DATA[t]['special'] = []
|
100
|
+
[:min_value, :min_normalized_value, :max_value, :epsilon, :strict_epsilon].each do |v|
|
101
|
+
val = flt.send(v)
|
102
|
+
rep = base==:bytes ? flt.to_hex(val,true) : flt.to_bits_text(val,base).upcase
|
103
|
+
TEST_DATA[t]['special'] << {v.to_s=>rep}
|
104
|
+
end
|
105
|
+
|
106
|
+
print "."
|
107
|
+
TEST_DATA[t]['values'] = []
|
108
|
+
for v in VALUES
|
109
|
+
val = flt.from_number(v)
|
110
|
+
rep = base==:bytes ? flt.to_hex(val,true) : flt.to_bits_text(val,base).upcase
|
111
|
+
TEST_DATA[t]['values'] << {v.inspect=>rep}
|
112
|
+
end
|
113
|
+
puts ""
|
114
|
+
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
File.open(File.join(File.dirname(__FILE__),"test_data0.yaml"),"w"){|f| f.write TEST_DATA.to_yaml}
|
119
|
+
|