flt 1.4.3 → 1.4.4
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 +5 -0
- data/lib/flt/num.rb +6 -0
- data/lib/flt/support/formatter.rb +2 -2
- data/lib/flt/support/reader.rb +1 -1
- data/lib/flt/version.rb +1 -1
- data/test/test_basic.rb +9 -0
- data/test/test_bin.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b31b19298dc561379a1bb087187ba69da8d959ab
|
4
|
+
data.tar.gz: b26b4ff187ec92bd51198b274666babf5123c856
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 561ae33a6932265a5f6e708405c485c1d684f42db179c8575f5949bf78a7d25316a1ca5da03de911cfe7f82f8ee3c6e359a9f68d74c4862c5319a7cb06fa18bc
|
7
|
+
data.tar.gz: c29f03d82d8c9513d11318ce2f66fbcac5507757acc12fa7b4c01b0e65734583a1f244566d18626662ff35d57a06ffee1e0ac4bae4363d95978ed1b70ce7fb5f
|
data/History.txt
CHANGED
data/lib/flt/num.rb
CHANGED
@@ -485,6 +485,12 @@ class Num < Numeric
|
|
485
485
|
|
486
486
|
# Constructor for the associated numeric class
|
487
487
|
def Num(*args)
|
488
|
+
context = { context: self }
|
489
|
+
if args.last.kind_of?(Hash)
|
490
|
+
args = args[0...-1] + [ context.merge(args.last) ]
|
491
|
+
else
|
492
|
+
args << context
|
493
|
+
end
|
488
494
|
num_class.Num(*args)
|
489
495
|
end
|
490
496
|
|
@@ -6,7 +6,7 @@ module Flt
|
|
6
6
|
# (Robert G. Burger, R. Kent Dybvig)
|
7
7
|
#
|
8
8
|
# This algorithm formats arbitrary base floating point numbers as decimal
|
9
|
-
# text literals. The floating-point (with fixed precision) is interpreted as an
|
9
|
+
# text literals. The floating-point (with fixed precision) is interpreted as an approximate
|
10
10
|
# value, representing any value in its 'rounding-range' (the interval where all values round
|
11
11
|
# to the floating-point value, with the given precision and rounding mode).
|
12
12
|
# An alternative approach which is not taken here would be to represent the exact floating-point
|
@@ -56,7 +56,7 @@ module Flt
|
|
56
56
|
|
57
57
|
# A Formatted object is created to format floating point numbers given:
|
58
58
|
# * The input base in which numbers to be formatted are defined
|
59
|
-
# * The input minimum
|
59
|
+
# * The input minimum exponent
|
60
60
|
# * The output base to which the input is converted.
|
61
61
|
# * The :raise_on_repeat option, true by default specifies that when
|
62
62
|
# an infinite sequence of repeating significant digits is found on the output
|
data/lib/flt/support/reader.rb
CHANGED
@@ -26,7 +26,7 @@ module Flt
|
|
26
26
|
# (William D. Clinger)
|
27
27
|
class Reader
|
28
28
|
|
29
|
-
# There are
|
29
|
+
# There are three different reading approaches, selected by the :mode parameter:
|
30
30
|
# * :fixed (the destination context defines the resulting precision) input is rounded as specified
|
31
31
|
# by the context; if the context precision is 'exact', the exact input value will be represented
|
32
32
|
# in the destination base, which can lead to a Inexact exception (or a NaN result and an Inexact flag)
|
data/lib/flt/version.rb
CHANGED
data/test/test_basic.rb
CHANGED
@@ -441,4 +441,13 @@ class TestBasic < Test::Unit::TestCase
|
|
441
441
|
|
442
442
|
end
|
443
443
|
|
444
|
+
def test_context_constructor
|
445
|
+
DecNum.context.precision = 8
|
446
|
+
DecNum.context.rounding = :half_even
|
447
|
+
context = DecNum.context[precision: 4]
|
448
|
+
assert_equal "1000", context.Num('0.1', :fixed).split[1].to_s
|
449
|
+
assert_equal "1000", context.Num('0.1', :fixed, :base => 10).split[1].to_s
|
450
|
+
assert_equal "10000000", DecNum('0.1', :fixed).split[1].to_s
|
451
|
+
end
|
452
|
+
|
444
453
|
end
|
data/test/test_bin.rb
CHANGED
@@ -175,6 +175,15 @@ class TestBin < Test::Unit::TestCase
|
|
175
175
|
|
176
176
|
end
|
177
177
|
|
178
|
+
def test_context_constructor
|
179
|
+
BinNum.context.precision = 16
|
180
|
+
BinNum.context.rounding = :half_even
|
181
|
+
context = BinNum.context[precision: 8]
|
182
|
+
assert_equal "11001101", context.Num('0.1', :fixed).split[1].to_s(2)
|
183
|
+
assert_equal "11001101", context.Num('0.1', :fixed, :base => 10).split[1].to_s(2)
|
184
|
+
assert_equal "1100110011001101", BinNum('0.1', :fixed).split[1].to_s(2)
|
185
|
+
end
|
186
|
+
|
178
187
|
def test_text_to_float_exact
|
179
188
|
BinNum.context.exact = :quiet
|
180
189
|
%w{
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Goizueta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|