float-formats 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/License.txt +20 -0
- data/Manifest.txt +29 -0
- data/README.txt +211 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +17 -0
- data/lib/float-formats.rb +11 -0
- data/lib/float-formats/bytes.rb +304 -0
- data/lib/float-formats/classes.rb +1550 -0
- data/lib/float-formats/formats.rb +580 -0
- data/lib/float-formats/native.rb +169 -0
- data/lib/float-formats/version.rb +9 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/destroy.cmd +1 -0
- data/script/generate +14 -0
- data/script/generate.cmd +1 -0
- data/script/txt2html +74 -0
- data/script/txt2html.cmd +1 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/gen_test_data.rb +119 -0
- data/test/test_data.yaml +1716 -0
- data/test/test_float-formats.rb +112 -0
- data/test/test_helper.rb +2 -0
- data/test/test_native-float.rb +25 -0
- metadata +88 -0
@@ -0,0 +1,112 @@
|
|
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
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/float-formats/native.rb'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
include FltPnt
|
8
|
+
|
9
|
+
class TestNativeFloat < Test::Unit::TestCase
|
10
|
+
def test_nextprev
|
11
|
+
assert Float::MIN_N.prev==Float::MAX_D
|
12
|
+
assert Float::MIN_N==Float::MAX_D.next
|
13
|
+
assert Float::MIN_D.prev==0.0
|
14
|
+
assert Float::MIN_D==0.0.next
|
15
|
+
|
16
|
+
assert((-Float::MIN_N).next==-Float::MAX_D)
|
17
|
+
assert(-(Float::MIN_N.prev)==-Float::MAX_D)
|
18
|
+
assert((-Float::MIN_D).next==0.0)
|
19
|
+
assert((-Float::MIN_D)==0.0.prev)
|
20
|
+
|
21
|
+
|
22
|
+
assert(-(1.0.next) == (-1.0).prev)
|
23
|
+
assert((-1.0).next == -(1.0.prev))
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: float-formats
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-11-04 00:00:00 +01:00
|
8
|
+
summary: Floating-Point Formats
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: javier@goizueta.info
|
12
|
+
homepage: http://float-formats.rubyforge.org
|
13
|
+
rubyforge_project: float-formats
|
14
|
+
description: Floating-Point Formats
|
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
|
+
- Javier Goizueta
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- License.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
- Rakefile
|
37
|
+
- config/hoe.rb
|
38
|
+
- config/requirements.rb
|
39
|
+
- lib/float-formats.rb
|
40
|
+
- lib/float-formats/version.rb
|
41
|
+
- lib/float-formats/bytes.rb
|
42
|
+
- lib/float-formats/classes.rb
|
43
|
+
- lib/float-formats/formats.rb
|
44
|
+
- lib/float-formats/native.rb
|
45
|
+
- log/debug.log
|
46
|
+
- script/destroy
|
47
|
+
- script/destroy.cmd
|
48
|
+
- script/generate
|
49
|
+
- script/generate.cmd
|
50
|
+
- script/txt2html
|
51
|
+
- script/txt2html.cmd
|
52
|
+
- setup.rb
|
53
|
+
- tasks/deployment.rake
|
54
|
+
- tasks/environment.rake
|
55
|
+
- tasks/website.rake
|
56
|
+
- test/test_float-formats.rb
|
57
|
+
- test/test_helper.rb
|
58
|
+
- test/test_data.yaml
|
59
|
+
- test/gen_test_data.rb
|
60
|
+
- test/test_native-float.rb
|
61
|
+
test_files:
|
62
|
+
- test/test_float-formats.rb
|
63
|
+
- test/test_helper.rb
|
64
|
+
- test/test_native-float.rb
|
65
|
+
rdoc_options:
|
66
|
+
- --main
|
67
|
+
- README.txt
|
68
|
+
extra_rdoc_files:
|
69
|
+
- History.txt
|
70
|
+
- License.txt
|
71
|
+
- Manifest.txt
|
72
|
+
- README.txt
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
dependencies:
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: nio
|
82
|
+
version_requirement:
|
83
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.2.0
|
88
|
+
version:
|