float-formats 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ class TestFloatFormats < Test::Unit::TestCase
7
7
 
8
8
  def setup
9
9
  end
10
-
10
+
11
11
  def test_nextprev
12
12
  for tn in %w{IEEE_SINGLE IEEE_DOUBLE IEEE_EXTENDED IEEE_DEC32 IEEE_DEC64 IEEE_DEC128}
13
13
  t = eval(tn)
@@ -22,14 +22,14 @@ class TestFloatFormats < Test::Unit::TestCase
22
22
  assert z.next_minus==t.min_value(-1),"#{tn}: prv 0 == -min"
23
23
  assert mz.next_plus==t.min_value,"#{tn}: nxt -0 == min"
24
24
  end
25
-
25
+
26
26
  for tn in %w{
27
- APPLE XS128
27
+ APPLE XS128
28
28
  BORLAND48
29
- MBF_SINGLE MBF_DOUBLE
30
- IEEE_SINGLE IEEE_DOUBLE IEEE_EXTENDED IEEE_128
29
+ MBF_SINGLE MBF_DOUBLE
30
+ IEEE_SINGLE IEEE_DOUBLE IEEE_EXTENDED IEEE_128
31
31
  IEEE_DEC32 IEEE_DEC64 IEEE_DEC128
32
- XS256 XS256_DOUBLE
32
+ XS256 XS256_DOUBLE
33
33
  SATURN SATURN_X HP_CLASSIC
34
34
  VAX_F VAX_D PDP11_F PDP11_D VAX_G VAX_H
35
35
  IBM32 IBM64 IBM128 IBMX
@@ -44,38 +44,40 @@ class TestFloatFormats < Test::Unit::TestCase
44
44
  mu = t.from_text('-1')
45
45
  assert u.next_plus.minus == mu.next_minus,"#{tn}: -nxt 1 == prv -1"
46
46
  assert mu.next_plus == u.next_minus.minus,"#{tn}: nxt -1 == -prv 1"
47
-
48
- end
49
-
47
+
48
+ end
49
+
50
50
  end
51
-
51
+
52
52
  TEST_DATA = YAML.load(File.read(File.join(File.dirname(__FILE__),'test_data.yaml')))
53
53
 
54
54
 
55
55
  def test_all
56
56
 
57
57
  TEST_DATA.keys.each do |t|
58
-
58
+
59
59
  flt = eval(t)
60
-
60
+
61
61
  base = TEST_DATA[t]['base']
62
-
62
+
63
63
  td = TEST_DATA[t]['parameters']
64
-
64
+
65
65
  #puts "def test_#{t}_parameters"
66
- for pair in td
67
- attrb,v = pair.to_a.first
66
+ for pair in td
67
+ attrb,v = pair.to_a.first
68
68
  #puts " assert_equal #{v}, #{t}.#{attrb}"
69
69
  assert_equal v, flt.send(attrb), "#{t}.#{attrb} == #{v}"
70
- end
70
+ end
71
71
  #puts "end"
72
-
73
-
72
+
73
+
74
74
  td = TEST_DATA[t]['numerals']
75
75
  #puts "def test_#{t}_numerals"
76
76
  for pair in td
77
- v,rep = pair.to_a.first
77
+ v,rep = pair.to_a.first
78
+ # v_expr = "#{t}.from_text('#{v}', :free, exact_input: false)"
78
79
  v_expr = "#{t}.from_text('#{v}')"
80
+
79
81
  expr = base==:bytes ? "(#{v_expr}).to_hex(true)" : "(#{v_expr}).to_bits_text(#{base}).upcase"
80
82
  #puts " assert_equal '#{rep}', #{expr}"
81
83
  assert_equal rep, eval(expr), "#{expr} == '#{rep}'"
@@ -87,19 +89,19 @@ class TestFloatFormats < Test::Unit::TestCase
87
89
  td = TEST_DATA[t]['special']
88
90
  #puts "def test_#{t}_special"
89
91
  for pair in td
90
- v,rep = pair.to_a.first
92
+ v,rep = pair.to_a.first
91
93
  #next if v=='epsilon'
92
94
  v_expr = "#{t}.#{v}"
93
95
  expr = base==:bytes ? "(#{v_expr}).to_hex(true)" : "(#{v_expr}).to_bits_text(#{base}).upcase"
94
96
  assert_equal rep, eval(expr), "#{expr} == '#{rep}'"
95
97
  end
96
98
  #puts "end"
97
-
99
+
98
100
 
99
101
  td = TEST_DATA[t]['values']
100
102
  #puts "def test_#{t}_values"
101
103
  for pair in td
102
- v,rep = pair.to_a.first
104
+ v,rep = pair.to_a.first
103
105
  v_expr = "#{t}.from_number(#{v})"
104
106
  expr = base==:bytes ? "(#{v_expr}).to_hex(true)" : "(#{v_expr}).to_bits_text(#{base}).upcase"
105
107
  assert_equal rep, eval(expr), "#{expr} == '#{rep}'"
@@ -107,9 +109,9 @@ class TestFloatFormats < Test::Unit::TestCase
107
109
  #puts "end"
108
110
 
109
111
 
110
- end
111
-
112
- end
112
+ end
113
+
114
+ end
113
115
 
114
116
 
115
117
 
@@ -117,11 +119,11 @@ class TestFloatFormats < Test::Unit::TestCase
117
119
  assert_equal(-499, HP71B.radix_min_exp)
118
120
  assert_equal(499, HP71B.radix_max_exp)
119
121
 
120
- fmt = Nio::Fmt.prec(12)
122
+ fmt = Numerals::Format[precision: 12, symbols: [uppercase: true]]
121
123
  assert_equal '9.99999999999E499', HP71B.max_value.to_text(fmt)
122
124
  assert_equal '0000000000001501', HP71B.min_value.to_bits_text(16)
123
- assert_equal '1E-510', HP71B.min_value.to_text(fmt)
124
- assert_equal '1E-499', HP71B.min_normalized_value.to_text(fmt)
125
+ assert_equal '1.0E-510', HP71B.min_value.to_text(fmt)
126
+ assert_equal '1.00000000000E-499', HP71B.min_normalized_value.to_text(fmt)
125
127
 
126
128
  assert_equal '9210000000000999',HP71B.from_text('-0.21').to_bits_text(16)
127
129
  assert_equal '0100000000000001',HP71B.from_text('10').to_bits_text(16)
@@ -137,39 +139,39 @@ class TestFloatFormats < Test::Unit::TestCase
137
139
  def test_quad
138
140
  assert_equal "3fff 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.from_text('1').to_hex.downcase
139
141
  assert_equal "7ffe ffff ffff ffff ffff ffff ffff ffff".tr(' ',''), IEEE_binary128_BE.max_value.to_hex.downcase
140
- assert_equal '1.19E4932', IEEE_binary128.max_value.to_text(Nio::Fmt.prec(4))
142
+ assert_equal '1.190e4932', IEEE_binary128.max_value.to_text(Numerals::Format[precision: 4])
141
143
  assert_equal "c000 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.from_text('-2').to_hex.downcase
142
144
  assert_equal "0000 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.from_text('0').to_hex.downcase
143
145
  assert_equal "8000 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.from_text('-0').to_hex.downcase
144
146
  assert_equal "7fff 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.infinity.to_hex.downcase
145
147
  assert_equal "ffff 0000 0000 0000 0000 0000 0000 0000".tr(' ',''), IEEE_binary128_BE.infinity(-1).to_hex.downcase
146
148
  assert_equal "3ffd 5555 5555 5555 5555 5555 5555 5555".tr(' ',''), IEEE_binary128_BE.from_number(Rational(1,3)).to_hex.downcase
147
- assert_equal "3fff 0000 0000 0000 0000 0000 0000 0001".tr(' ',''), IEEE_binary128_BE.from_text('1').next_plus.to_hex.downcase
149
+ assert_equal "3fff 0000 0000 0000 0000 0000 0000 0001".tr(' ',''), IEEE_binary128_BE.from_text('1').next_plus.to_hex.downcase
148
150
  end
149
151
  def test_half
150
152
  assert_equal "3c00", IEEE_binary16_BE.from_text('1').to_hex.downcase
151
153
  assert_equal "7bff", IEEE_binary16_BE.max_value.to_hex.downcase
152
- assert_equal '65504', IEEE_binary16_BE.max_value.to_text(Nio::Fmt.approx_mode(:exact))
154
+ assert_equal '65504', IEEE_binary16_BE.max_value.to_text(Numerals::Format[:exact_input])
153
155
  assert_equal "0400", IEEE_binary16_BE.min_normalized_value.to_hex.downcase
154
- assert_equal "6.103515625E-5", IEEE_binary16_BE.min_normalized_value.to_text(Nio::Fmt.approx_mode(:exact))
156
+ assert_equal "6.103515625e-5", IEEE_binary16_BE.min_normalized_value.to_text(Numerals::Format[:sci, :exact_input])
155
157
  assert_equal "0001", IEEE_binary16_BE.min_value.to_hex.downcase
156
- assert_equal "5.9604644775390625E-8", IEEE_binary16_BE.min_value.to_text(Nio::Fmt.approx_mode(:exact))
158
+ assert_equal "5.9604644775390625e-8", IEEE_binary16_BE.min_value.to_text(Numerals::Format[:sci, :exact_input])
157
159
  assert_equal "0000", IEEE_binary16_BE.from_text('0').to_hex.downcase
158
160
  assert_equal "8000", IEEE_binary16_BE.from_text('-0').to_hex.downcase
159
161
  assert_equal "7c00".tr(' ',''), IEEE_binary16_BE.infinity.to_hex.downcase
160
162
  assert_equal "fc00".tr(' ',''), IEEE_binary16_BE.infinity(-1).to_hex.downcase
161
163
  end
162
164
  def test_special
163
- assert_equal '+Infinity', IEEE_binary32.from_number(1.0/0.0).to_text
164
- assert_equal '-Infinity', IEEE_binary32.from_number(-1.0/0.0).to_text
165
- assert_equal '+Infinity', IEEE_binary32.from_text('+Infinity').to_text
166
- assert_equal '-Infinity', IEEE_binary32.from_text('-Infinity').to_text
165
+ assert_equal '+Infinity', IEEE_binary32.from_number(1.0/0.0).to_text
166
+ assert_equal '-Infinity', IEEE_binary32.from_number(-1.0/0.0).to_text
167
+ assert_equal '+Infinity', IEEE_binary32.from_text('+Infinity').to_text
168
+ assert_equal '-Infinity', IEEE_binary32.from_text('-Infinity').to_text
167
169
  assert_equal 'NAN', IEEE_binary32.from_number(0.0/0.0).to_text.upcase
168
170
  assert_equal 'NAN', IEEE_binary32.from_text('NaN').to_text.upcase
169
171
  end
170
-
172
+
171
173
  def test_double_double
172
-
174
+
173
175
  assert_equal 128, IEEE_DOUBLE_DOUBLE.total_bits
174
176
  assert_equal 16, IEEE_DOUBLE_DOUBLE.total_bytes
175
177
  assert_equal 107, IEEE_DOUBLE_DOUBLE.significand_digits
@@ -179,30 +181,30 @@ class TestFloatFormats < Test::Unit::TestCase
179
181
  assert_equal(-307, IEEE_DOUBLE_DOUBLE.decimal_min_exp)
180
182
  assert_equal 1023, IEEE_DOUBLE_DOUBLE.radix_max_exp
181
183
  assert_equal(-1022, IEEE_DOUBLE_DOUBLE.radix_min_exp)
182
- fmt = Nio::Fmt.prec(2).approx_mode(:exact).approx_mode(:exact)
184
+ fmt = Numerals::Format[:exact_input, precision: 2, symbols:[uppercase: true]]
183
185
  assert_equal '1.8E308', IEEE_DOUBLE_DOUBLE.max_value.to_text(fmt)
184
186
  assert_equal '2.2E-308', IEEE_DOUBLE_DOUBLE.min_normalized_value.to_text(fmt)
185
187
  assert_equal '4.9E-324', IEEE_DOUBLE_DOUBLE.half.min_value.to_text(fmt)
186
-
188
+
187
189
  assert_equal "0.5", IEEE_DOUBLE_DOUBLE('0.5').to_text
188
190
  assert_equal "000000000000E03F0000000000000000", IEEE_DOUBLE_DOUBLE('0.5').to_hex
189
191
  assert_equal "000000000000E03F0000000000004039", IEEE_DOUBLE_DOUBLE('0.5').next_plus.to_hex
190
192
  assert_equal "9A9999999999B93F9A999999999959BC", IEEE_DOUBLE_DOUBLE('0.1').to_hex
191
193
  assert_equal "9A9999999999B93F99999999999959BC", IEEE_DOUBLE_DOUBLE('0.1').next_plus.to_hex
192
-
194
+
193
195
  assert_equal IEEE_DOUBLE_DOUBLE('0.5'), IEEE_DOUBLE_DOUBLE.join_halfs(*IEEE_DOUBLE_DOUBLE('0.5').split_halfs)
194
196
  assert_equal IEEE_DOUBLE_DOUBLE('0.5').next_plus, IEEE_DOUBLE_DOUBLE.join_halfs(*IEEE_DOUBLE_DOUBLE('0.5').next_plus.split_halfs)
195
197
  assert_equal IEEE_DOUBLE_DOUBLE('0.1'), IEEE_DOUBLE_DOUBLE.join_halfs(*IEEE_DOUBLE_DOUBLE('0.1').split_halfs)
196
198
  assert_equal IEEE_DOUBLE_DOUBLE('0.1').next_plus, IEEE_DOUBLE_DOUBLE.join_halfs(*IEEE_DOUBLE_DOUBLE('0.1').next_plus.split_halfs)
197
-
198
- assert_equal "00000000000050390000000000000000", IEEE_DOUBLE_DOUBLE.epsilon.to_hex
199
+
200
+ assert_equal "00000000000050390000000000000000", IEEE_DOUBLE_DOUBLE.epsilon.to_hex
199
201
  assert_equal "000000000000F87F0000000000000000", IEEE_DOUBLE_DOUBLE.nan.to_hex
200
202
  assert_equal "NAN", IEEE_DOUBLE_DOUBLE.nan.to_text.upcase
201
203
  assert_equal "000000000000F07F0000000000000000", IEEE_DOUBLE_DOUBLE.infinity.to_hex
202
204
  assert_equal "+INFINITY", IEEE_DOUBLE_DOUBLE.infinity.to_text.upcase
203
205
  assert_equal "00000000000000000000000000000000", IEEE_DOUBLE_DOUBLE.zero.to_hex
204
- assert_equal "0", IEEE_DOUBLE_DOUBLE.zero.to_text.upcase
206
+ assert_equal "0", IEEE_DOUBLE_DOUBLE.zero.to_text.upcase
205
207
  end
206
-
208
+
207
209
 
208
210
  end
@@ -29,7 +29,7 @@ class TestNativeFloat < Test::Unit::TestCase
29
29
  def test_hex
30
30
  if Float::RADIX==2 && Float::MANT_DIG==53
31
31
  assert_equal((1.0+Float::EPSILON),hex_to_float('0x1.0000000000001p0'))
32
- assert_equal '0x10000000000001p-52', hex_from_float(1.0+Float::EPSILON)
32
+ assert_equal '0x1.0000000000001p0', hex_from_float(1.0+Float::EPSILON)
33
33
  end
34
34
  assert_equal 1.0, hex_to_float(hex_from_float(1.0))
35
35
  assert_equal(-1.0, hex_to_float(hex_from_float(-1.0)))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: float-formats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Goizueta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-31 00:00:00.000000000 Z
11
+ date: 2015-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flt
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.2
19
+ version: 1.4.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.1.2
26
+ version: 1.4.7
27
27
  - !ruby/object:Gem::Dependency
28
- name: nio
28
+ name: numerals
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.4
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.4
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nio
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.2.4
69
83
  description: Floating-Point Formats
70
84
  email:
71
85
  - jgoizueta@gmail.com
@@ -109,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
123
  requirements:
110
124
  - - ">="
111
125
  - !ruby/object:Gem::Version
112
- version: '0'
126
+ version: 1.9.3
113
127
  required_rubygems_version: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="