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.
- checksums.yaml +4 -4
- data/History.txt +8 -0
- data/README.md +765 -0
- data/expand.rb +2 -0
- data/flt.gemspec +1 -0
- data/lib/flt.rb +1 -1
- data/lib/flt/bigdecimal.rb +2 -5
- data/lib/flt/bin_num.rb +1 -4
- data/lib/flt/complex.rb +10 -9
- data/lib/flt/dec_num.rb +9 -10
- data/lib/flt/float.rb +4 -6
- data/lib/flt/math.rb +3 -4
- data/lib/flt/num.rb +54 -21
- data/lib/flt/sugar.rb +1 -2
- data/lib/flt/support.rb +5 -2
- data/lib/flt/support/flag_values.rb +1 -1
- data/lib/flt/support/rationalizer.rb +3 -3
- data/lib/flt/support/rationalizer_extra.rb +6 -6
- data/lib/flt/support/reader.rb +1 -1
- data/lib/flt/tolerance.rb +2 -7
- data/lib/flt/trigonometry.rb +0 -2
- data/lib/flt/version.rb +1 -1
- data/setup.rb +1 -2
- data/test/generate_trig_data.rb +6 -6
- data/test/helper.rb +11 -5
- data/test/reader.rb +1 -1
- data/test/test_base_digits.rb +4 -2
- data/test/test_basic.rb +7 -7
- data/test/test_big_decimal.rb +21 -21
- data/test/test_bin.rb +1 -1
- data/test/test_bin_arithmetic.rb +1 -1
- data/test/test_binfloat_conversion.rb +1 -1
- data/test/test_coercion.rb +1 -1
- data/test/test_comparisons.rb +4 -4
- data/test/test_dectest.rb +2 -2
- data/test/test_define_conversions.rb +10 -10
- data/test/test_epsilon.rb +1 -1
- data/test/test_exact.rb +12 -11
- data/test/test_flags.rb +1 -1
- data/test/test_float.rb +23 -25
- data/test/test_format.rb +1 -1
- data/test/test_formatter.rb +6 -8
- data/test/test_hex_format.rb +2 -2
- data/test/test_multithreading.rb +1 -1
- data/test/test_normalized.rb +1 -1
- data/test/test_num_constructor.rb +6 -1
- data/test/test_odd_even.rb +1 -1
- data/test/test_rationalizer.rb +1 -1
- data/test/test_round.rb +36 -1
- data/test/test_sugar.rb +6 -6
- data/test/test_to_int.rb +4 -4
- data/test/test_to_rf.rb +126 -1
- data/test/test_tol.rb +1 -1
- data/test/test_trig.rb +1 -1
- data/test/test_ulp.rb +3 -3
- metadata +18 -4
- data/README.rdoc +0 -614
data/lib/flt/support/reader.rb
CHANGED
@@ -74,7 +74,7 @@ module Flt
|
|
74
74
|
# for free mode, (any) :nearest rounding is used by default
|
75
75
|
Num.convert(Num[eb].Num(sign, f, e), context.num_class, :rounding=>round_mode||:nearest, :all_digits=>all_digits)
|
76
76
|
when :fixed
|
77
|
-
if
|
77
|
+
if context.exact?
|
78
78
|
a,b = [eb, context.radix].sort
|
79
79
|
m = (Math.log(b)/Math.log(a)).round
|
80
80
|
if b == a**m
|
data/lib/flt/tolerance.rb
CHANGED
@@ -85,10 +85,6 @@
|
|
85
85
|
# tol = Tolerance(1, :percent)
|
86
86
|
# puts tol.equal_to?(3.14159, Math::PI) # -> true#
|
87
87
|
|
88
|
-
require 'flt/num'
|
89
|
-
require 'flt/float'
|
90
|
-
require 'flt/bigdecimal'
|
91
|
-
|
92
88
|
module Flt
|
93
89
|
|
94
90
|
# The Tolerance class is a base class for all tolerances.
|
@@ -398,17 +394,16 @@ module Flt
|
|
398
394
|
when BigDecimal
|
399
395
|
if @radix == :native || @radix == 10
|
400
396
|
exp = xs.map do |x|
|
401
|
-
|
397
|
+
_sign,digits,_base,exp = x.split
|
402
398
|
exp -= 1
|
403
399
|
exp -= 1 if digits=="1" # if :low mode
|
404
400
|
exp -= FloatingTolerance.ref_adjusted_exp
|
405
401
|
exp
|
406
402
|
end.send(mode)
|
407
|
-
|
403
|
+
_sign, digits, _base, vexp = v.split
|
408
404
|
BigDecimal.new("0.#{digits}E#{vexp+exp}")
|
409
405
|
else
|
410
406
|
# assert num_class==BigDecimal && @radix==2
|
411
|
-
prec = 10
|
412
407
|
exp = xs.map do |x|
|
413
408
|
exp = (Flt::DecNum(x.to_s).ln/Flt::DecNum(2).ln).ceil - 1 # ... if :high mode
|
414
409
|
exp -= FloatingTolerance.ref_adjusted_exp
|
data/lib/flt/trigonometry.rb
CHANGED
data/lib/flt/version.rb
CHANGED
data/setup.rb
CHANGED
@@ -104,7 +104,7 @@ class ConfigTable
|
|
104
104
|
def remove(name)
|
105
105
|
item = lookup(name)
|
106
106
|
@items.delete_if {|i| i.name == name }
|
107
|
-
@table.delete_if {|
|
107
|
+
@table.delete_if {|iname, i| i.name == name }
|
108
108
|
item
|
109
109
|
end
|
110
110
|
|
@@ -281,7 +281,6 @@ class ConfigTable
|
|
281
281
|
'site-ruby-common' => 'siteruby', # For backward compatibility
|
282
282
|
'site-ruby' => 'siterubyver', # For backward compatibility
|
283
283
|
'bin-dir' => 'bindir',
|
284
|
-
'bin-dir' => 'bindir',
|
285
284
|
'rb-dir' => 'rbdir',
|
286
285
|
'so-dir' => 'sodir',
|
287
286
|
'data-dir' => 'datadir',
|
data/test/generate_trig_data.rb
CHANGED
@@ -23,12 +23,12 @@ end
|
|
23
23
|
# random angles in radians for sin,cos,tan
|
24
24
|
def angle_data(num_class)
|
25
25
|
xs = []
|
26
|
-
pi = num_class
|
26
|
+
pi = num_class.math { half_cycle }
|
27
27
|
(-8..8).each do |k|
|
28
28
|
x = k*pi/4
|
29
29
|
xs += near(x)
|
30
30
|
end
|
31
|
-
pi2 = num_class
|
31
|
+
pi2 = num_class.math { quarter_cycle }
|
32
32
|
50.times{ xs << random_num_one(num_class)*pi2}
|
33
33
|
base = xs.dup
|
34
34
|
(2...10).each do |k|
|
@@ -55,7 +55,7 @@ def random_num_one(num_class=DecNum)
|
|
55
55
|
e = context.etiny
|
56
56
|
elsif rand(20)==0
|
57
57
|
# and some singular values too
|
58
|
-
if rand(
|
58
|
+
if rand(2) == 0
|
59
59
|
f = context.radix**context.precision - 1
|
60
60
|
f -= rand(3)
|
61
61
|
else
|
@@ -63,7 +63,7 @@ def random_num_one(num_class=DecNum)
|
|
63
63
|
f += rand(3)
|
64
64
|
end
|
65
65
|
# e = random_integer(context.etiny, context.etop)
|
66
|
-
if rand(
|
66
|
+
if rand(2) == 0
|
67
67
|
e = random_integer(-context.precision-1,-context.precision)
|
68
68
|
else
|
69
69
|
e = random_integer(-context.precision-10,-context.precision)
|
@@ -71,13 +71,13 @@ def random_num_one(num_class=DecNum)
|
|
71
71
|
else
|
72
72
|
f = rand(context.radix**context.precision)
|
73
73
|
# e = random_integer(context.etiny, context.etop)
|
74
|
-
if rand(
|
74
|
+
if rand(2) == 0
|
75
75
|
e = random_integer(-context.precision-1,-context.precision)
|
76
76
|
else
|
77
77
|
e = random_integer(-context.precision-10,-context.precision)
|
78
78
|
end
|
79
79
|
end
|
80
|
-
# f = -f if rand(
|
80
|
+
# f = -f if rand(2) == 0
|
81
81
|
context.Num(f, e)
|
82
82
|
end
|
83
83
|
|
data/test/helper.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'minitest/autorun'
|
2
2
|
$: << "." unless $:.include?(".") # for Ruby 1.9.2
|
3
3
|
require File.expand_path(File.join(File.dirname(__FILE__),'/../lib/flt'))
|
4
4
|
require 'enumerator'
|
5
5
|
require 'yaml'
|
6
6
|
include Flt
|
7
7
|
|
8
|
+
module Minitest::Assertions
|
9
|
+
def assert_nothing_raised(*)
|
10
|
+
yield
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
def initialize_context
|
9
15
|
DecNum.context = DecNum::ExtendedContext
|
10
16
|
BinNum.context = BinNum::ExtendedContext
|
@@ -46,9 +52,9 @@ def random_num(num_class)
|
|
46
52
|
# generate 5% of subnormals
|
47
53
|
f = rand(context.radix**(context.precision-1))
|
48
54
|
e = context.etiny
|
49
|
-
elsif rand(20)==0
|
55
|
+
elsif rand(20) == 0
|
50
56
|
# and some singular values too
|
51
|
-
if rand(
|
57
|
+
if rand(2) == 0
|
52
58
|
f = context.radix**context.precision - 1
|
53
59
|
f -= rand(3)
|
54
60
|
else
|
@@ -60,7 +66,7 @@ def random_num(num_class)
|
|
60
66
|
f = rand(context.radix**context.precision)
|
61
67
|
e = random_integer(context.etiny, context.etop)
|
62
68
|
end
|
63
|
-
f = -f if rand(
|
69
|
+
f = -f if rand(2) == 0
|
64
70
|
context.Num(f, e)
|
65
71
|
end
|
66
72
|
|
@@ -96,7 +102,7 @@ end
|
|
96
102
|
|
97
103
|
def float_data
|
98
104
|
data_file = File.join(File.dirname(__FILE__) ,'data/float_data.yml')
|
99
|
-
if File.
|
105
|
+
if File.exist?(data_file)
|
100
106
|
YAML.load(File.read(data_file)).map{|x| [x].pack('H*').unpack('E')[0]}
|
101
107
|
else
|
102
108
|
srand 349842
|
data/test/reader.rb
CHANGED
data/test/test_base_digits.rb
CHANGED
data/test/test_basic.rb
CHANGED
@@ -63,7 +63,7 @@ def return_from_local_context
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
class TestBasic < Test
|
66
|
+
class TestBasic < Minitest::Test
|
67
67
|
|
68
68
|
|
69
69
|
def setup
|
@@ -394,17 +394,17 @@ class TestBasic < Test::Unit::TestCase
|
|
394
394
|
context = num_class.context
|
395
395
|
assert context.nan.nan?
|
396
396
|
assert context.zero.zero?
|
397
|
-
assert_equal
|
397
|
+
assert_equal(+1, context.sign(context.zero))
|
398
398
|
assert context.zero(+1).zero?
|
399
|
-
assert_equal
|
399
|
+
assert_equal(+1, context.sign(context.zero(+1)))
|
400
400
|
assert context.zero(-1).zero?
|
401
|
-
assert_equal
|
401
|
+
assert_equal(-1, context.sign(context.zero(-1)))
|
402
402
|
assert context.infinity.infinite?
|
403
|
-
assert_equal
|
403
|
+
assert_equal(+1, context.sign(context.infinity))
|
404
404
|
assert context.infinity(+1).infinite?
|
405
|
-
assert_equal
|
405
|
+
assert_equal(+1, context.sign(context.infinity(+1)))
|
406
406
|
assert context.infinity(-1).infinite?
|
407
|
-
assert_equal
|
407
|
+
assert_equal(-1, context.sign(context.infinity(-1)))
|
408
408
|
assert_equal context.Num(1)/2, context.one_half
|
409
409
|
end
|
410
410
|
end
|
data/test/test_big_decimal.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
|
2
2
|
|
3
|
-
class TestBigDecimal < Test
|
3
|
+
class TestBigDecimal < Minitest::Test
|
4
4
|
|
5
5
|
def setup
|
6
6
|
initialize_context
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_sign
|
10
|
-
assert_equal
|
11
|
-
assert_equal
|
12
|
-
assert_equal
|
13
|
-
assert_equal
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
10
|
+
assert_equal(-1, BigDecimal.context.sign(BigDecimal('-1.0')))
|
11
|
+
assert_equal(-1, BigDecimal.context.sign(BigDecimal('-10.0')))
|
12
|
+
assert_equal(-1, BigDecimal.context.sign(BigDecimal('-10E50')))
|
13
|
+
assert_equal(-1, BigDecimal.context.sign(BigDecimal('-10E-50')))
|
14
|
+
assert_equal(-1, BigDecimal.context.sign(BigDecimal('-723')))
|
15
|
+
assert_equal(-1, BigDecimal.context.sign(BigDecimal('-0.0')))
|
16
16
|
|
17
|
-
assert_equal
|
18
|
-
assert_equal
|
19
|
-
assert_equal
|
20
|
-
assert_equal
|
21
|
-
assert_equal
|
22
|
-
assert_equal
|
17
|
+
assert_equal(+1, BigDecimal.context.sign(BigDecimal('+1.0')))
|
18
|
+
assert_equal(+1, BigDecimal.context.sign(BigDecimal('+10.0')))
|
19
|
+
assert_equal(+1, BigDecimal.context.sign(BigDecimal('+10E50')))
|
20
|
+
assert_equal(+1, BigDecimal.context.sign(BigDecimal('+10E-50')))
|
21
|
+
assert_equal(+1, BigDecimal.context.sign(BigDecimal('+723')))
|
22
|
+
assert_equal(+1, BigDecimal.context.sign(BigDecimal('0.0')))
|
23
23
|
|
24
24
|
assert_nil BigDecimal.context.sign(BigDecimal.context.nan)
|
25
25
|
end
|
26
26
|
|
27
27
|
def copy_sign
|
28
|
-
assert_equal
|
29
|
-
assert_equal
|
30
|
-
assert_equal
|
31
|
-
assert_equal
|
32
|
-
assert_equal
|
33
|
-
assert_equal
|
34
|
-
assert_equal
|
35
|
-
assert_equal
|
28
|
+
assert_equal(-BigDecimal('1.23'), BigDecimal.context.copy_sign(BigDecimal('1.23'), -1))
|
29
|
+
assert_equal(-BigDecimal('1.23'), BigDecimal.context.copy_sign(BigDecimal('1.23'), BigDecimal('-10')))
|
30
|
+
assert_equal(-BigDecimal('1.23'), BigDecimal.context.copy_sign(BigDecimal('-1.23'), -1))
|
31
|
+
assert_equal(-BigDecimal('1.23'), BigDecimal.context.copy_sign(BigDecimal('-1.23'), BigDecimal('-10')))
|
32
|
+
assert_equal(BigDecimal('1.23'), BigDecimal.context.copy_sign(BigDecimal('-1.23'), +1))
|
33
|
+
assert_equal(BigDecimal('1.23'), BigDecimal.context.copy_sign(BigDecimal('-1.23'), BigDecimal('+10')))
|
34
|
+
assert_equal(BigDecimal('1.23'), BigDecimal.context.copy_sign(BigDecimal('1.23'), +1))
|
35
|
+
assert_equal(BigDecimal('1.23'), BigDecimal.context.copy_sign(BigDecimal('1.23'), BigDecimal('+10')))
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
data/test/test_bin.rb
CHANGED
data/test/test_bin_arithmetic.rb
CHANGED
@@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
|
|
2
2
|
|
3
3
|
# These tests assume that Float arithmetic is correctly rounded
|
4
4
|
# Random tests using Float as a reference
|
5
|
-
class TestBinArithmetic < Test
|
5
|
+
class TestBinArithmetic < Minitest::Test
|
6
6
|
|
7
7
|
def setup
|
8
8
|
initialize_context
|
data/test/test_coercion.rb
CHANGED
data/test/test_comparisons.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
|
2
2
|
|
3
|
-
class TestComparisons < Test
|
3
|
+
class TestComparisons < Minitest::Test
|
4
4
|
|
5
5
|
|
6
6
|
def setup
|
@@ -11,9 +11,9 @@ class TestComparisons < Test::Unit::TestCase
|
|
11
11
|
assert_equal DecNum('1.1').hash, DecNum('1.1').hash
|
12
12
|
assert_equal DecNum('1.1').hash, (DecNum('1.0')+DecNum('0.1')).hash
|
13
13
|
assert_equal DecNum('1.1',:precision=>10).hash, DecNum('1.1',:precision=>3).hash
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
refute_equal DecNum('1.0').hash, DecNum('1.1').hash
|
15
|
+
refute_equal DecNum('1.0').hash, 1.0.hash
|
16
|
+
refute_equal DecNum('1.0').hash, 1.hash
|
17
17
|
|
18
18
|
assert DecNum('1.1').eql?(DecNum('1.1'))
|
19
19
|
assert DecNum('1.1').eql?(DecNum('1.0')+DecNum('0.1'))
|
data/test/test_dectest.rb
CHANGED
@@ -108,12 +108,12 @@ def unquote(txt)
|
|
108
108
|
txt
|
109
109
|
end
|
110
110
|
|
111
|
-
class TestBasic < Test
|
111
|
+
class TestBasic < Minitest::Test
|
112
112
|
|
113
113
|
def test_dec
|
114
114
|
missing = []
|
115
115
|
dir = File.join(File.dirname(__FILE__), 'data/dectest')
|
116
|
-
if !File.
|
116
|
+
if !File.exist?(dir)
|
117
117
|
skip "No dectest data present. Get it from http://speleotrove.com/decimal/dectest.zip and put it in test/data/dectest"
|
118
118
|
return
|
119
119
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
|
2
2
|
|
3
|
-
class TestDefineConversions < Test
|
3
|
+
class TestDefineConversions < Minitest::Test
|
4
4
|
|
5
5
|
|
6
6
|
def setup
|
@@ -55,20 +55,20 @@ class TestDefineConversions < Test::Unit::TestCase
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
assert_raises(TypeError, RuntimeError) { DecNum('0') == BigDecimal.new('0') }
|
59
59
|
unless Num < Numeric
|
60
60
|
# BigDecimal#eql? is weird
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
refute_equal BigDecimal.new('0'), DecNum('0')
|
62
|
+
refute_equal BigDecimal.new('1.2345'), DecNum('1.2345')
|
63
|
+
refute_equal BigDecimal.new('-1.2345'), DecNum('-1.2345')
|
64
|
+
refute_equal BigDecimal.new('1.2345'), DecNum('0.0012345000E3')
|
65
|
+
assert_raises(TypeError) { BigDecimal.new('7')+DecNum('0.1') }
|
66
66
|
end
|
67
|
-
|
68
|
-
|
67
|
+
assert_raises(TypeError, RuntimeError) { DecNum('7')+BigDecimal.new('0.1') }
|
68
|
+
assert_raises(TypeError, RuntimeError) { DecNum(BigDecimal.new('1.1')) }
|
69
69
|
|
70
70
|
['0.1', '-0.1', '0.0', '1234567.1234567', '-1234567.1234567', '1.234E7', '1.234E-7'].each do |n|
|
71
|
-
|
71
|
+
assert_raises(TypeError, RuntimeError) { DecNum(n).convert_to(BigDecimal) }
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
data/test/test_epsilon.rb
CHANGED
data/test/test_exact.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
|
2
2
|
|
3
3
|
|
4
|
-
class TestExact < Test
|
5
|
-
|
6
|
-
|
4
|
+
class TestExact < Minitest::Test
|
7
5
|
def setup
|
8
6
|
initialize_context
|
9
7
|
end
|
10
8
|
|
9
|
+
def teardown
|
10
|
+
initialize_context
|
11
|
+
end
|
11
12
|
|
12
13
|
def test_exact_no_traps
|
13
14
|
|
@@ -133,14 +134,14 @@ class TestExact < Test::Unit::TestCase
|
|
133
134
|
assert_equal DecNum(0), DecNum(1).ln
|
134
135
|
assert !DecNum.context.flags[DecNum::Inexact]
|
135
136
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
137
|
+
assert_raises(DecNum::Inexact){ DecNum(2).sqrt }
|
138
|
+
assert_raises(DecNum::Inexact){ DecNum(1)/DecNum(3) }
|
139
|
+
assert_raises(DecNum::Inexact){ DecNum(18).power(DecNum('0.5')) }
|
140
|
+
assert_raises(DecNum::Inexact){ DecNum(18).power(DecNum('1.5')) }
|
141
|
+
assert_raises(DecNum::Inexact){ DecNum(18).log10 }
|
142
|
+
assert_raises(DecNum::Inexact){ DecNum(1).exp }
|
143
|
+
assert_raises(DecNum::Inexact){ DecNum('1.2').exp }
|
144
|
+
assert_raises(DecNum::Inexact){ DecNum('1.2').ln }
|
144
145
|
|
145
146
|
end
|
146
147
|
|