flt 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +8 -0
  3. data/README.md +765 -0
  4. data/expand.rb +2 -0
  5. data/flt.gemspec +1 -0
  6. data/lib/flt.rb +1 -1
  7. data/lib/flt/bigdecimal.rb +2 -5
  8. data/lib/flt/bin_num.rb +1 -4
  9. data/lib/flt/complex.rb +10 -9
  10. data/lib/flt/dec_num.rb +9 -10
  11. data/lib/flt/float.rb +4 -6
  12. data/lib/flt/math.rb +3 -4
  13. data/lib/flt/num.rb +54 -21
  14. data/lib/flt/sugar.rb +1 -2
  15. data/lib/flt/support.rb +5 -2
  16. data/lib/flt/support/flag_values.rb +1 -1
  17. data/lib/flt/support/rationalizer.rb +3 -3
  18. data/lib/flt/support/rationalizer_extra.rb +6 -6
  19. data/lib/flt/support/reader.rb +1 -1
  20. data/lib/flt/tolerance.rb +2 -7
  21. data/lib/flt/trigonometry.rb +0 -2
  22. data/lib/flt/version.rb +1 -1
  23. data/setup.rb +1 -2
  24. data/test/generate_trig_data.rb +6 -6
  25. data/test/helper.rb +11 -5
  26. data/test/reader.rb +1 -1
  27. data/test/test_base_digits.rb +4 -2
  28. data/test/test_basic.rb +7 -7
  29. data/test/test_big_decimal.rb +21 -21
  30. data/test/test_bin.rb +1 -1
  31. data/test/test_bin_arithmetic.rb +1 -1
  32. data/test/test_binfloat_conversion.rb +1 -1
  33. data/test/test_coercion.rb +1 -1
  34. data/test/test_comparisons.rb +4 -4
  35. data/test/test_dectest.rb +2 -2
  36. data/test/test_define_conversions.rb +10 -10
  37. data/test/test_epsilon.rb +1 -1
  38. data/test/test_exact.rb +12 -11
  39. data/test/test_flags.rb +1 -1
  40. data/test/test_float.rb +23 -25
  41. data/test/test_format.rb +1 -1
  42. data/test/test_formatter.rb +6 -8
  43. data/test/test_hex_format.rb +2 -2
  44. data/test/test_multithreading.rb +1 -1
  45. data/test/test_normalized.rb +1 -1
  46. data/test/test_num_constructor.rb +6 -1
  47. data/test/test_odd_even.rb +1 -1
  48. data/test/test_rationalizer.rb +1 -1
  49. data/test/test_round.rb +36 -1
  50. data/test/test_sugar.rb +6 -6
  51. data/test/test_to_int.rb +4 -4
  52. data/test/test_to_rf.rb +126 -1
  53. data/test/test_tol.rb +1 -1
  54. data/test/test_trig.rb +1 -1
  55. data/test/test_ulp.rb +3 -3
  56. metadata +18 -4
  57. data/README.rdoc +0 -614
@@ -1,40 +1,38 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
- class TestFloat < Test::Unit::TestCase
4
-
3
+ class TestFloat < Minitest::Test
5
4
  def setup
6
5
  initialize_context
7
6
  end
8
7
 
9
8
  def test_sign
10
- assert_equal -1, Float.context.sign(-1.0)
11
- assert_equal -1, Float.context.sign(-100.0)
12
- assert_equal -1, Float.context.sign(-0.0)
13
- assert_equal -1, Float.context.sign(-Float::MIN)
14
- assert_equal -1, Float.context.sign(-Float::MAX)
15
- assert_equal -1, Float.context.sign(-Float::EPSILON)
16
- assert_equal -1, Float.context.sign(-Float::INFINITY)
9
+ assert_equal(-1, Float.context.sign(-1.0))
10
+ assert_equal(-1, Float.context.sign(-100.0))
11
+ assert_equal(-1, Float.context.sign(-0.0))
12
+ assert_equal(-1, Float.context.sign(-Float::MIN))
13
+ assert_equal(-1, Float.context.sign(-Float::MAX))
14
+ assert_equal(-1, Float.context.sign(-Float::EPSILON))
15
+ assert_equal(-1, Float.context.sign(-Float::INFINITY))
17
16
 
18
- assert_equal +1, Float.context.sign(+1.0)
19
- assert_equal +1, Float.context.sign(+100.0)
20
- assert_equal +1, Float.context.sign(+0.0)
21
- assert_equal +1, Float.context.sign(Float::MIN)
22
- assert_equal +1, Float.context.sign(Float::MAX)
23
- assert_equal +1, Float.context.sign(Float::EPSILON)
24
- assert_equal +1, Float.context.sign(Float::INFINITY)
17
+ assert_equal(+1, Float.context.sign(+1.0))
18
+ assert_equal(+1, Float.context.sign(+100.0))
19
+ assert_equal(+1, Float.context.sign(+0.0))
20
+ assert_equal(+1, Float.context.sign(Float::MIN))
21
+ assert_equal(+1, Float.context.sign(Float::MAX))
22
+ assert_equal(+1, Float.context.sign(Float::EPSILON))
23
+ assert_equal(+1, Float.context.sign(Float::INFINITY))
25
24
 
26
25
  assert_nil Float.context.sign(Float.context.nan)
27
26
  end
28
27
 
29
28
  def copy_sign
30
- assert_equal -1.23, BigDecimal.context.copy_sign(1.23, -1)
31
- assert_equal -1.23, BigDecimal.context.copy_sign(1.23, -10.0)
32
- assert_equal -1.23, BigDecimal.context.copy_sign(-1.23, -1)
33
- assert_equal -1.23, BigDecimal.context.copy_sign(-1.23, -10.0)
34
- assert_equal 1.23, BigDecimal.context.copy_sign(-1.23, +1)
35
- assert_equal 1.23, BigDecimal.context.copy_sign(-1.23, 10.0)
36
- assert_equal 1.23, BigDecimal.context.copy_sign(1.23, +1)
37
- assert_equal 1.23, BigDecimal.context.copy_sign(1.23, 10.0)
29
+ assert_equal(-1.23, BigDecimal.context.copy_sign(1.23, -1))
30
+ assert_equal(-1.23, BigDecimal.context.copy_sign(1.23, -10.0))
31
+ assert_equal(-1.23, BigDecimal.context.copy_sign(-1.23, -1))
32
+ assert_equal(-1.23, BigDecimal.context.copy_sign(-1.23, -10.0))
33
+ assert_equal(1.23, BigDecimal.context.copy_sign(-1.23, +1))
34
+ assert_equal(1.23, BigDecimal.context.copy_sign(-1.23, 10.0))
35
+ assert_equal(1.23, BigDecimal.context.copy_sign(1.23, +1))
36
+ assert_equal(1.23, BigDecimal.context.copy_sign(1.23, 10.0))
38
37
  end
39
-
40
38
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
- class TestFormat < Test::Unit::TestCase
3
+ class TestFormat < Minitest::Test
4
4
 
5
5
  def setup
6
6
  initialize_context
@@ -1,9 +1,7 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
3
 
4
- class TestExact < Test::Unit::TestCase
5
-
6
-
4
+ class TestFormatter < Minitest::Test
7
5
  def setup
8
6
  initialize_context
9
7
  end
@@ -25,7 +23,7 @@ class TestExact < Test::Unit::TestCase
25
23
  digits = formatter.format(x, f, e, :up, BinNum.context.precision, false)
26
24
  assert_equal [1], digits
27
25
 
28
- assert_raise(Flt::Support::InfiniteLoopError) { formatter.format(x, f, e, :up, BinNum.context.precision, true) }
26
+ assert_raises(Flt::Support::InfiniteLoopError) { formatter.format(x, f, e, :up, BinNum.context.precision, true) }
29
27
 
30
28
  digits = formatter.format(x, f, e, :down, BinNum.context.precision, false)
31
29
  assert_equal [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
@@ -48,7 +46,7 @@ class TestExact < Test::Unit::TestCase
48
46
  digits = formatter.format(x, f, e, :up, BinNum.context.precision, false)
49
47
  assert_equal [5], digits
50
48
 
51
- assert_raise(Flt::Support::InfiniteLoopError) { formatter.format(x, f, e, :up, BinNum.context.precision, true) }
49
+ assert_raises(Flt::Support::InfiniteLoopError) { formatter.format(x, f, e, :up, BinNum.context.precision, true) }
52
50
 
53
51
  digits = formatter.format(x, f, e, :down, BinNum.context.precision, false)
54
52
  assert_equal [5], digits
@@ -58,7 +56,7 @@ class TestExact < Test::Unit::TestCase
58
56
  refute formatter.round_up
59
57
  end
60
58
 
61
- def test_binary_to_repeating_decimal_formatter
59
+ def test_binary_to_repeating_decimal_formatter
62
60
  Flt::BinNum.context = Flt::BinNum::IEEEDoubleContext
63
61
  formatter = Flt::Support::Formatter.new(BinNum.radix, BinNum.context.etiny, 10, :raise_on_repeat => false)
64
62
 
@@ -144,12 +142,12 @@ def test_binary_to_repeating_decimal_formatter
144
142
  digits = formatter.format(x, f, e, :up, DecNum.context.precision, false)
145
143
  assert_equal [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], digits
146
144
 
147
- assert_raise(Support::InfiniteLoopError) { formatter.format(x, f, e, :up, DecNum.context.precision, true) }
145
+ assert_raises(Support::InfiniteLoopError) { formatter.format(x, f, e, :up, DecNum.context.precision, true) }
148
146
 
149
147
  digits = formatter.format(x, f, e, :down, DecNum.context.precision, false)
150
148
  assert_equal [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1], digits
151
149
 
152
- assert_raise(Support::InfiniteLoopError) { formatter.format(x, f, e, :down, DecNum.context.precision, true) }
150
+ assert_raises(Support::InfiniteLoopError) { formatter.format(x, f, e, :down, DecNum.context.precision, true) }
153
151
  end
154
152
 
155
153
  def test_decimal_to_repeating_binary_formatter
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
- class TestHexFormat< Test::Unit::TestCase
3
+ class TestHexFormat< Minitest::Test
4
4
 
5
5
  def setup
6
6
  @hex_test_data = [0.1, 1.0/3, 0.1e10, 1e10/3.0, 0.1e-10, 1e-10/3.0, 123456.789,
@@ -32,7 +32,7 @@ class TestHexFormat< Test::Unit::TestCase
32
32
  BinNum.context(BinNum::FloatContext) do
33
33
  @hex_test_data.each do |number|
34
34
  hex_upcase = "%A" % number
35
- hex_downcase = "%a" % number
35
+ hex_downcase = "%a" % number
36
36
  number = BinNum(number)
37
37
  # text = number.to_s(:base => :hex_bin, :all_digits => false, :output_rounding => BinNum.context.rounding)
38
38
  text_up = BinNum.context(:capitals => true){
@@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
3
 
4
4
 
5
- class TestMultithreading < Test::Unit::TestCase
5
+ class TestMultithreading < Minitest::Test
6
6
 
7
7
  def setup
8
8
  initialize_context
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
3
 
4
- class TestNormalized < Test::Unit::TestCase
4
+ class TestNormalized < Minitest::Test
5
5
 
6
6
  include Flt
7
7
 
@@ -1,15 +1,20 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
- class TestNumConstructor < Test::Unit::TestCase
3
+ class TestNumConstructor < Minitest::Test
4
4
 
5
5
 
6
6
  def setup
7
7
  initialize_context
8
+ @old_prec = DecNum.context.precision
8
9
  DecNum.context.precision = 28
9
10
  @dprec5 = DecNum::Context(:precision=>5)
10
11
  @bprec5 = BinNum::Context(:precision=>5)
11
12
  end
12
13
 
14
+ def teardown
15
+ DecNum.context.precision = @old_prec
16
+ end
17
+
13
18
  def test_direct
14
19
  assert_equal [1, 1234, -2], DecNum(+1, 1234, -2).split
15
20
  assert_equal [1, 1234, -2], DecNum(+1, 1234, -2, @dprec5).split
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
- class TestOddEven < Test::Unit::TestCase
3
+ class TestOddEven < Minitest::Test
4
4
 
5
5
 
6
6
  def setup
@@ -11,7 +11,7 @@ else
11
11
  end
12
12
  end
13
13
 
14
- class TestRationalizer < Test::Unit::TestCase
14
+ class TestRationalizer < Minitest::Test
15
15
 
16
16
  def setup
17
17
  initialize_context
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
3
 
4
- class TestRound < Test::Unit::TestCase
4
+ class TestRound < Minitest::Test
5
5
 
6
6
 
7
7
  def setup
@@ -50,6 +50,41 @@ class TestRound < Test::Unit::TestCase
50
50
 
51
51
  end
52
52
 
53
+ def test_ruby_2_4_round
54
+ assert_equal 100, DecNum('100.5').round(:half => :even)
55
+ assert_equal 101, DecNum('100.5000001').round(:half => :even)
56
+ assert_equal 102, DecNum('101.5').round(:half => :even)
57
+ assert_equal 101, DecNum('101.4999999999').round(:half => :even)
58
+
59
+ assert_equal 100, DecNum('100.5').round(:half => :down)
60
+ assert_equal 101, DecNum('100.5000001').round(:half => :down)
61
+ assert_equal 101, DecNum('101.5').round(:half => :down)
62
+ assert_equal 101, DecNum('101.4999999999').round(:half => :down)
63
+
64
+ assert_equal 101, DecNum('100.5').round(:half => :up)
65
+ assert_equal 101, DecNum('100.5000001').round(:half => :up)
66
+ assert_equal 102, DecNum('101.5').round(:half => :up)
67
+ assert_equal 101, DecNum('101.4999999999').round(:half => :up)
68
+
69
+ assert_equal 101, DecNum('100.5').round(0)
70
+ assert_equal DecNum('100.5'), DecNum('100.5').round(1)
71
+ assert_equal 100, DecNum('100.5').round(-1)
72
+ assert_equal DecNum('100.1235'), DecNum('100.1235'), DecNum('100.12345').round(4)
73
+
74
+ assert_equal 100, DecNum('100.5').round(0, :half => :even)
75
+ assert_equal 101, DecNum('100.5').round(0, :half => :up)
76
+ assert_equal 100, DecNum('100.5').round(0, :half => :down)
77
+ assert_equal DecNum('100.5'), DecNum('100.5').round(1, half: :even)
78
+ assert_equal DecNum('100.5'), DecNum('100.5').round(1, half: :up)
79
+ assert_equal DecNum('100.5'), DecNum('100.5').round(1, half: :down)
80
+ assert_equal 100, DecNum('100.5').round(-1, half: :even)
81
+ assert_equal 100, DecNum('100.5').round(-1, half: :down)
82
+ assert_equal 100, DecNum('100.5').round(-1, half: :up)
83
+ assert_equal DecNum('100.1234'), DecNum('100.12345').round(4, half: :even)
84
+ assert_equal DecNum('100.1235'), DecNum('100.12345').round(4, half: :up)
85
+ assert_equal DecNum('100.1234'), DecNum('100.12345').round(4, half: :down)
86
+ end
87
+
53
88
  def detect_rounding(type)
54
89
  x = type.new(1)*type.int_radix_power(type.context.precision+1)
55
90
  y = x + type.int_radix_power(2)
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
  require File.dirname(__FILE__) + '/../lib/flt/sugar'
3
3
 
4
- class TestSugar < Test::Unit::TestCase
4
+ class TestSugar < Minitest::Test
5
5
 
6
6
  def test_pseudo_literals
7
7
  assert_equal Flt::DecNum, 10._3223.class
@@ -14,11 +14,11 @@ class TestSugar < Test::Unit::TestCase
14
14
  123456789123._01234567890123456789012345678901234567890123456789
15
15
  assert_equal Flt::DecNum('-123456789123.01234567890123456789012345678901234567890123456789'),
16
16
  -123456789123._01234567890123456789012345678901234567890123456789
17
- assert_raise(NoMethodError,NameError){3._x}
18
- assert_raise(NoMethodError,NameError){3._3233x}
19
- assert_raise(NoMethodError,NameError){3._3233x34333}
20
- assert_raise(NoMethodError,NameError){3.__}
21
- assert_raise(NoMethodError,NameError){3._}
17
+ assert_raises(NoMethodError,NameError){3._x}
18
+ assert_raises(NoMethodError,NameError){3._3233x}
19
+ assert_raises(NoMethodError,NameError){3._3233x34333}
20
+ assert_raises(NoMethodError,NameError){3.__}
21
+ assert_raises(NoMethodError,NameError){3._}
22
22
  assert_equal Flt::DecNum, 10._32_23.class
23
23
  assert_equal Flt::DecNum('10.3223'), 10._32_23
24
24
  assert_equal Flt::DecNum('3.01234567890123456789012345678901234567890123456789'),
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
- class TestToInt < Test::Unit::TestCase
3
+ class TestToInt < Minitest::Test
4
4
 
5
5
 
6
6
  def setup
@@ -16,7 +16,7 @@ class TestToInt < Test::Unit::TestCase
16
16
  assert_same(-123, DecNum('-0.0123000E4').to_i)
17
17
  assert(-1234567890.eql?(DecNum('-123456789E1').to_i))
18
18
  assert(-1234567890.eql?(DecNum('-123456789000E-2').to_i))
19
- assert_raise(DecNum::Error) { DecNum.infinity.to_i }
19
+ assert_raises(DecNum::Error) { DecNum.infinity.to_i }
20
20
  assert_nil DecNum.nan.to_i
21
21
  assert_same(1, DecNum('1.9').to_i)
22
22
  assert_same(-1, DecNum('-1.9').to_i)
@@ -74,10 +74,10 @@ class TestToInt < Test::Unit::TestCase
74
74
  assert_equal DecNum('-1234567890'), DecNum('-123456789000E-2').to_integral_exact
75
75
  assert DecNum.context.flags[DecNum::Rounded]
76
76
  DecNum.context.flags[DecNum::Rounded] = false
77
- assert_raise(DecNum::Inexact) { DecNum('1.9').to_integral_exact }
77
+ assert_raises(DecNum::Inexact) { DecNum('1.9').to_integral_exact }
78
78
  assert DecNum.context.flags[DecNum::Rounded]
79
79
  DecNum.context.flags[DecNum::Rounded] = false
80
- assert_raise(DecNum::Inexact) { DecNum('-1.9').to_integral_exact }
80
+ assert_raises(DecNum::Inexact) { DecNum('-1.9').to_integral_exact }
81
81
  assert DecNum.nan.to_integral_exact.nan?
82
82
  assert_equal DecNum.infinity, DecNum.infinity.to_integral_exact
83
83
  assert DecNum.context.flags[DecNum::Rounded]
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
- class TestToRF < Test::Unit::TestCase
3
+ class TestToRF < Minitest::Test
4
4
 
5
5
 
6
6
  def setup
@@ -31,6 +31,131 @@ class TestToRF < Test::Unit::TestCase
31
31
  assert d.to_f.is_a?(Float)
32
32
  assert_equal f, d.to_f
33
33
  end
34
+ assert DecNum.nan.to_f.nan?
35
+ assert DecNum.infinity.to_f.infinite?
36
+ assert DecNum.infinity.to_f > 0
37
+ assert DecNum.infinity(-1).to_f.infinite?
38
+ assert DecNum.infinity(-1).to_f < 0
39
+ assert 1.0/DecNum('-0').to_f < 0
40
+ assert 1.0/DecNum('+0').to_f > 0
41
+
42
+ data = []
43
+ [10, 100, 1000, 10000].each do |n_digits|
44
+ data << DecNum('+0.'+'1'*n_digits)
45
+ data << DecNum('-0.'+'1'*n_digits)
46
+ end
47
+
48
+ srand 1023022
49
+ data = []
50
+ DecNum.context(:precision=>15, :elimit=>90) do
51
+ data += [DecNum('1.448997445238699'), DecNum('1E23'),DecNum('-6.22320623338259E+16'),
52
+ DecNum('-3.83501075447972E-10'), DecNum('1.448997445238699')]
53
+ data += %w{
54
+ 1E23
55
+ 1.448997445238699
56
+ -6.22320623338259E+16
57
+ -3.83501075447972E-10
58
+ 1.448997445238699
59
+ 1.23E-30
60
+ 1.23456789E-20
61
+ 1.23456789E-30
62
+ 1.234567890123456789
63
+ 0.9999999999999995559107901499
64
+ 0.9999999999999996114219413812
65
+ 0.9999999999999996669330926125
66
+ 0.9999999999999997224442438437
67
+ 0.9999999999999997779553950750
68
+ 0.9999999999999998334665463062
69
+ 0.9999999999999998889776975375
70
+ 0.9999999999999999444888487687
71
+ 1
72
+ 1.000000000000000111022302463
73
+ 1.000000000000000222044604925
74
+ 1.000000000000000333066907388
75
+ 1.000000000000000444089209850
76
+ 1.000000000000000555111512313
77
+ 1.000000000000000666133814775
78
+ 1.000000000000000777156117238
79
+ 1.000000000000000888178419700
80
+ }.map{ |num| DecNum(num) }
81
+ data += Array.new(10000){random_num(DecNum)}
82
+ end
83
+
84
+ assert_equal 2, Float::RADIX
85
+
86
+ data.each do |x|
87
+ expected = Flt::Num.convert_exact(x, 2, Flt::BinNum::FloatContext).to_f
88
+ assert_equal expected, x.to_s.to_f
89
+
90
+ relative_error_limit = Float::EPSILON
91
+ # rel_err = (x.to_f - expected).abs/expected.abs
92
+ assert expected.abs*relative_error_limit > (x.to_f - expected).abs, "#{x.to_f} != #{expected} (#{x})"
93
+ end
34
94
  end
35
95
 
96
+ def test_to_f_bin
97
+ BinNum.context(BinNum::FloatContext) do
98
+ ['0.1', '-0.1', '0.0', '1234567.1234567', '-1234567.1234567', '1.234E7', '1.234E-7'].each do |n|
99
+ f = Float(n)
100
+ b = BinNum(n, :fixed)
101
+ assert b.to_f.is_a?(Float)
102
+ assert_equal f, b.to_f
103
+ end
104
+ assert BinNum.nan.to_f.nan?
105
+ assert BinNum.infinity.to_f.infinite?
106
+ assert BinNum.infinity.to_f > 0
107
+ assert BinNum.infinity(-1).to_f.infinite?
108
+ assert BinNum.infinity(-1).to_f < 0
109
+ assert 1.0/BinNum('-0', :fixed).to_f < 0
110
+ assert 1.0/BinNum('+0', :fixed).to_f > 0
111
+
112
+ data = []
113
+ [10, 100, 1000, 10000].each do |n_digits|
114
+ data << BinNum('+0.'+'1'*n_digits)
115
+ data << BinNum('-0.'+'1'*n_digits)
116
+ end
117
+
118
+ srand 1023022
119
+ data = []
120
+ data += [BinNum('1.448997445238699', :fixed), BinNum('1E23', :fixed),BinNum('-6.22320623338259E+16', :fixed),
121
+ BinNum('-3.83501075447972E-10', :fixed), BinNum('1.448997445238699', :fixed)]
122
+ data += %w{
123
+ 1E23
124
+ 1.448997445238699
125
+ -6.22320623338259E+16
126
+ -3.83501075447972E-10
127
+ 1.448997445238699
128
+ 1.23E-30
129
+ 1.23456789E-20
130
+ 1.23456789E-30
131
+ 1.234567890123456789
132
+ 0.9999999999999995559107901499
133
+ 0.9999999999999996114219413812
134
+ 0.9999999999999996669330926125
135
+ 0.9999999999999997224442438437
136
+ 0.9999999999999997779553950750
137
+ 0.9999999999999998334665463062
138
+ 0.9999999999999998889776975375
139
+ 0.9999999999999999444888487687
140
+ 1
141
+ 1.000000000000000111022302463
142
+ 1.000000000000000222044604925
143
+ 1.000000000000000333066907388
144
+ 1.000000000000000444089209850
145
+ 1.000000000000000555111512313
146
+ 1.000000000000000666133814775
147
+ 1.000000000000000777156117238
148
+ 1.000000000000000888178419700
149
+ }.map{ |num| BinNum(num, :fixed) }
150
+ data += Array.new(10000){random_num(BinNum)}
151
+
152
+ data.each do |x|
153
+ expected = x.to_decimal_exact(exact: true).to_s.to_f
154
+ assert_equal expected, x.to_f
155
+ end
156
+ end
157
+
158
+ end
159
+
160
+
36
161
  end