flt 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d83917f212ce371cb0539547a00b167a49ad62ba
4
- data.tar.gz: e8d5884693b1d3bdcfd44ef3e2e2bf4dd864fc8a
3
+ metadata.gz: d25ad2ad4f96968dfa38899ca80fbc6c42f2693e
4
+ data.tar.gz: 1dcceec01b59a5601054eaa5acc6ec6974bd5c75
5
5
  SHA512:
6
- metadata.gz: 726acb0972354c41401c11a05882a77b4897f26c69e9e8ae52ae5b970008a0a10d6dcdb193c289fc1fa6f618db232b5052ba1204ed8c61b314b87892d128646a
7
- data.tar.gz: f4757df03b50b6b64692b0cf93009954c13091f780dbc87a7b8886751369f5a83b1a69673098c95529e5b1bdfef049c659d92589316fd23ff58054e0ba54c24c
6
+ metadata.gz: e997aa12648c1c49d0e56dadb521d338e55c6fcd2082a4e9d46a7c103688950190ecb95bc36b285d4d1d5cfb6d348e7092dec5183d0c13476112b01390475d22
7
+ data.tar.gz: 28173c3cbd4fb78f986251ddfa7c8528dce13fb8b90e3069822c11a3c35902521c4b8b0eda68bf32d18b3c67c56abc86b2212b7b1b258d86d1e9782b31f5e649
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.4.2 2014-10-30
2
+
3
+ Change definition of numbers in :free mode with no change of base involved.
4
+
1
5
  == 1.4.1 2014-10-29
2
6
 
3
7
  Minor correction to allow partially requiring some files
data/lib/flt/dec_num.rb CHANGED
@@ -104,7 +104,7 @@ class DecNum < Num
104
104
  # DecNum('0.1000') # -> 0.1000
105
105
  # DecNum('0.12345') # -> 0.12345
106
106
  # DecNum('1.2345E-1') # -> 0.12345
107
- # DecNum('0.1000', :short) # -> 0.1000
107
+ # DecNum('0.1000', :short) # -> 0.1
108
108
  # DecNum('0.1000',:fixed, :precision=>20) # -> 0.10000000000000000000
109
109
  # DecNum('0.12345',:fixed, :precision=>20) # -> 0.12345000000000000000
110
110
  # DecNum('0.100110E3', :base=>2) # -> 4.8
data/lib/flt/num.rb CHANGED
@@ -1,6 +1,37 @@
1
1
  # Base classes for floating-point numbers and contexts.
2
2
 
3
3
  #--
4
+ # TODO: selecting the kind of ulp is awkward; consider one of these options:
5
+ # * don't support variant ulps; always use Muller's ulp
6
+ # * use an options hash for the kind of ulp parameter
7
+ # * keep the kind of ulp in the context
8
+ # also, note that Tolerance uses only the Muller king of ulp.
9
+ # TODO: move the exception classes from Flt::Num to Flt ? move also Flt::Num::ContextBas to Flt ?
10
+ # TODO: find better name for :all_digits (:preserve_precision, :mantain_precision, ...) ?
11
+ # TODO: should the context determine the mode for cross-base literal-to-Num conversion (:free, :fixed)?
12
+ # BinNum.context.input = :fixed; x = BinNum('0.1')
13
+ #++
14
+
15
+ require 'flt/support'
16
+ require 'flt/support/flag_values'
17
+ require 'flt/support/reader'
18
+ require 'flt/support/formatter'
19
+ require 'flt/support/rationalizer'
20
+
21
+ require 'bigdecimal'
22
+ require 'forwardable'
23
+ require 'rational'
24
+ require 'monitor'
25
+ require 'ostruct'
26
+
27
+ module Flt
28
+
29
+ # Generic radix arbitrary-precision, floating-point numbers. This is a base class for
30
+ # floating point types of specific radix.
31
+ #
32
+ # The implementation of floating-point arithmetic is largely based on the Decimal module of Python,
33
+ # written by Eric Price, Facundo Batista, Raymond Hettinger, Aahz and Tim Peters.
34
+ #
4
35
  # =Notes on the representation of Flt::Num numbers.
5
36
  #
6
37
  # * @sign is +1 for plus and -1 for minus
@@ -8,7 +39,7 @@
8
39
  # * @exp is the exponent to be applied to @coeff as an integer or one of :inf, :nan, :snan for special values
9
40
  #
10
41
  # The value represented is @sign*@coeff*b**@exp with b = num_class.radix the radix for the the Num-derived class.
11
-
42
+ #
12
43
  # The original Python Decimal representation has these slots:
13
44
  # * _sign is 1 for minus, 0 for plus
14
45
  # * _int is the integral significand as a string of digits (leading zeroes are not kept)
@@ -111,39 +142,7 @@
111
142
  #
112
143
  # The known or 'coercible' types for DecNum are initially Integer and Rational, but this can be extended to
113
144
  # other types using define_conversion_from() in a Context object.
114
- #++
115
-
116
- #--
117
- # TODO: selecting the kind of ulp is awkward; consider one of these options:
118
- # * don't support variant ulps; always use Muller's ulp
119
- # * use an options hash for the kind of ulp parameter
120
- # * keep the kind of ulp in the context
121
- # also, note that Tolerance uses only the Muller king of ulp.
122
- # TODO: move the exception classes from Flt::Num to Flt ? move also Flt::Num::ContextBas to Flt ?
123
- # TODO: find better name for :all_digits (:preserve_precision, :mantain_precision, ...) ?
124
- # TODO: should the context determine the mode for cross-base literal-to-Num conversion (:free, :fixed)?
125
- # BinNum.context.input = :fixed; x = BinNum('0.1')
126
- #++
127
-
128
- require 'flt/support'
129
- require 'flt/support/flag_values'
130
- require 'flt/support/reader'
131
- require 'flt/support/formatter'
132
- require 'flt/support/rationalizer'
133
-
134
- require 'bigdecimal'
135
- require 'forwardable'
136
- require 'rational'
137
- require 'monitor'
138
- require 'ostruct'
139
-
140
- module Flt
141
-
142
- # Generic radix arbitrary-precision, floating-point numbers. This is a base class for
143
- # floating point types of specific radix.
144
145
  #
145
- # The implementation of floating-point arithmetic is largely based on the Decimal module of Python,
146
- # written by Eric Price, Facundo Batista, Raymond Hettinger, Aahz and Tim Peters.
147
146
  class Num < Numeric
148
147
 
149
148
  extend Support # allows use of unqualified FlagValues(), Flags(), etc.
@@ -1446,7 +1445,13 @@ class Num < Numeric
1446
1445
  # meaning here that if the digit is changed and the value converted back to a literal of the same base and
1447
1446
  # precision, the original literal will not be obtained.
1448
1447
  # * :short is a variation of :free in which only the minimun number of digits that are necessary to
1449
- # produce the original literal when the value is converted back with the same original precision.
1448
+ # produce the original literal when the value is converted back with the same original precision;
1449
+ # namely, given an input in base b1, its :short representation in base 2 is the shortest number in base b2
1450
+ # such that when converted back to base b2 with the same precision that the input had, the result is identical
1451
+ # to the input:
1452
+ # short = Num[b2].new(input, :short, base: b1)
1453
+ # Num[b1].context.precision = precision_of_inpu
1454
+ # Num[b1].new(short.to_s(base: b2), :fixed, base: b2)) == Num[b1].new(input, :free, base: b1)
1450
1455
  # * :fixed will round and normalize the value to the precision specified by the context (normalize meaning
1451
1456
  # that exaclty the number of digits specified by the precision will be generated, even if the original
1452
1457
  # literal has fewer digits.) This may fail returning NaN (and raising Inexact) if the context precision is
@@ -1544,8 +1549,23 @@ class Num < Numeric
1544
1549
  mode ||= :free
1545
1550
  end
1546
1551
 
1547
- if [:free, :short].include?(mode) && base == num_class.radix
1552
+ if mode == :free && base == num_class.radix
1548
1553
  # simple case, the job is already done
1554
+ #
1555
+ # :free mode with same base must not be handled by the Reader;
1556
+ # note that if we used the Reader for the same base case in :free mode,
1557
+ # an extra 'significative' digit would be added, because that digit
1558
+ # is significative in the sense that (under non-directed rounding,
1559
+ # and with the significance interpretation of Reader wit the all-digits option)
1560
+ # it's not free to take any value without affecting the value of
1561
+ # the other digits: e.g. input: '0.1', the result of :free
1562
+ # conversion with the Reader is '0.10' because de last digit is not free;
1563
+ # if it was 9 for example the actual value would round to '0.2' with the input
1564
+ # precision given here.
1565
+ #
1566
+ # On the other hand, :short, should be handled by the Reader even when
1567
+ # the input and output bases are the same because we want to find the shortest
1568
+ # number that can be converted back to the input with the same input precision.
1549
1569
  else
1550
1570
  rounding = context.rounding
1551
1571
  reader = Support::Reader.new(:mode=>mode)
@@ -1,9 +1,9 @@
1
- # Some rationalization algorithms currently not being used
2
-
3
1
  module Flt
4
2
  module Support
5
3
 
6
4
  class Rationalizer
5
+ # Some rationalization algorithms currently not being used
6
+
7
7
 
8
8
  # Simple Rationalization by Joe Horn
9
9
  def rationalize_Horn_simple(x, smallest_denominator = false)
data/lib/flt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Flt
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
@@ -41,13 +41,13 @@ class TestNumConstructor < Test::Unit::TestCase
41
41
  assert_equal [1, 1, -1], DecNum('0.1', :free).split
42
42
  assert_equal [1, 1000, -4], DecNum('0.1000', :free).split
43
43
  assert_equal [1, 1, -1], DecNum('0.1',:short).split
44
- assert_equal [1, 1000, -4], DecNum('0.1000',:short).split
44
+ assert_equal [1, 1, -1], DecNum('0.1000',:short).split
45
45
 
46
46
  assert_equal [1, 1, -3], BinNum('0.1E-2', :free, :base=>2).split
47
47
  assert_equal [1, 1, -1], BinNum('0.1', :free, :base=>2).split
48
48
  assert_equal [1, 8, -4], BinNum('0.1000', :free, :base=>2).split
49
49
  assert_equal [1, 1, -1], BinNum('0.1',:short, :base=>2).split
50
- assert_equal [1, 8, -4], BinNum('0.1000',:short, :base=>2).split
50
+ assert_equal [1, 1, -1], BinNum('0.1000',:short, :base=>2).split
51
51
  end
52
52
 
53
53
  def test_literal_free_base
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.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Goizueta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-29 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler