flt 1.4.2 → 1.4.3

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: d25ad2ad4f96968dfa38899ca80fbc6c42f2693e
4
- data.tar.gz: 1dcceec01b59a5601054eaa5acc6ec6974bd5c75
3
+ metadata.gz: 6562084b49c2846a0b760e21a555950fa998f08a
4
+ data.tar.gz: 1d6fe60c1612876ac435bf4f25fd17b2a5dc1c60
5
5
  SHA512:
6
- metadata.gz: e997aa12648c1c49d0e56dadb521d338e55c6fcd2082a4e9d46a7c103688950190ecb95bc36b285d4d1d5cfb6d348e7092dec5183d0c13476112b01390475d22
7
- data.tar.gz: 28173c3cbd4fb78f986251ddfa7c8528dce13fb8b90e3069822c11a3c35902521c4b8b0eda68bf32d18b3c67c56abc86b2212b7b1b258d86d1e9782b31f5e649
6
+ metadata.gz: b98b9821e7aa201c23b59fffa24326741925fca5487765fe759adb6a01528a08941626304eb4a4883d7005228887ef65e752bebb7af1fd96a7d8bdd0bb0e582e
7
+ data.tar.gz: 95f117f1c48ae1b0264c0ab7aed6e299b3c3a8faaa0a21b98a54d40c905e3fa40db228deb650f846602a907fb83f369dd2cee759cd4b1a5876b50ff18f1a210c
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ == 1.4.3 2014-11-02
2
+
3
+ * New features
4
+ - operator [] for contexts (define new context based on it)
5
+ - new Context#special? method
6
+
7
+ * Bugfixed
8
+ - some bugs related to BigDecimal
9
+
1
10
  == 1.4.2 2014-10-30
2
11
 
3
12
  Change definition of numbers in :free mode with no change of base involved.
@@ -1,6 +1,7 @@
1
1
  # Support classes for homogeneous treatment of BigDecimal and Num values by defining BigDecimal.context
2
2
 
3
3
  require 'flt/num'
4
+ require 'flt/dec_num'
4
5
 
5
6
  require 'bigdecimal'
6
7
  require 'bigdecimal/math'
@@ -25,7 +26,7 @@ class Flt::BigDecimalContext
25
26
  def Num(*args)
26
27
  args = *args if args.size==1 && args.first.is_a?(Array)
27
28
  if args.size > 1
28
- BigDecimal.new(DecNum(*args).to_s)
29
+ BigDecimal.new(Flt::DecNum(*args).to_s)
29
30
  else
30
31
  x = args.first
31
32
  case x
@@ -131,7 +132,7 @@ class Flt::BigDecimalContext
131
132
  end
132
133
 
133
134
  def rationalize(x, tol = nil)
134
- tol ||= Flt::Tolerance([precs[0], Float::DIG].max,:sig_decimals)
135
+ tol ||= Flt::Tolerance([x.precs[0], Float::DIG].max,:sig_decimals)
135
136
  case tol
136
137
  when Integer
137
138
  Rational(*Support::Rationalizer.max_denominator(x, tol, BigDecimal))
@@ -166,4 +167,3 @@ end
166
167
  def BigDecimal.context
167
168
  Flt::BigDecimalContext.instance
168
169
  end
169
-
data/lib/flt/num.rb CHANGED
@@ -660,6 +660,12 @@ class Num < Numeric
660
660
  self.class.new(self)
661
661
  end
662
662
 
663
+ # Create a context as a copy of the current one with some options
664
+ # changed.
665
+ def [](options={})
666
+ self.class.new self, options
667
+ end
668
+
663
669
  CONDITION_MAP = {
664
670
  #ConversionSyntax=>InvalidOperation,
665
671
  #DivisionImpossible=>InvalidOperation,
@@ -1150,6 +1156,10 @@ class Num < Numeric
1150
1156
  _convert(x).infinite?
1151
1157
  end
1152
1158
 
1159
+ def special?(x)
1160
+ _convert(x).special?
1161
+ end
1162
+
1153
1163
  def zero?(x)
1154
1164
  _convert(x).zero?
1155
1165
  end
@@ -15,7 +15,7 @@ module Flt
15
15
  #
16
16
  # The variables used by the algorithm are stored in instance variables:
17
17
  # @v - The number to be formatted = @f*@b**@e
18
- # @b - The numberic base of the input floating-point representation of @v
18
+ # @b - The numeric base of the input floating-point representation of @v
19
19
  # @f - The significand or characteristic (fraction)
20
20
  # @e - The exponent
21
21
  #
@@ -43,7 +43,7 @@ module Flt
43
43
  # @k = 1+floor(logB((@r+@m_p)/2))
44
44
  #
45
45
  # @output_b is the output base
46
- # @output_min_e is the output minimum exponent
46
+ # @min_e is the input minimum exponent
47
47
  # p is the input floating point precision
48
48
  class Formatter
49
49
 
@@ -154,7 +154,7 @@ module Flt
154
154
  case @round_mode
155
155
  when :half_even
156
156
  # rounding rage is (v-m-,v+m+) if v is odd and [v+m-,v+m+] if even
157
- @round_l = @round_h = ((@f%2)==0)
157
+ @round_l = @round_h = ((@f % 2) == 0)
158
158
  when :up
159
159
  # rounding rage is (v-,v]
160
160
  # ceiling is treated here assuming f>0
@@ -192,7 +192,7 @@ module Flt
192
192
  @r, @s, @m_p, @m_m = @f*be1*2, @b*2, be1, be
193
193
  end
194
194
  else
195
- if @e==@min_e or @f != b_power(p-1)
195
+ if @e == @min_e || @f != b_power(p-1)
196
196
  @r, @s, @m_p, @m_m = @f*2, b_power(-@e)*2, 1, 1
197
197
  else
198
198
  @r, @s, @m_p, @m_m = @f*@b*2, b_power(1-@e)*2, @b, 1
@@ -234,11 +234,12 @@ module Flt
234
234
  # Access rounded result of format operation: scaling (position of radix point) and digits
235
235
  def adjusted_digits(round_mode)
236
236
  if @adjusted_digits.nil? && !@digits.nil?
237
- @adjusted_k, @adjusted_digits = Support.adjust_digits(@k, @digits,
238
- :round_mode => round_mode,
239
- :negative => @minus,
240
- :round_up => @round_up,
241
- :base => @output_b)
237
+ @adjusted_k, @adjusted_digits = Support.adjust_digits(
238
+ @k, @digits,
239
+ :round_mode => round_mode,
240
+ :negative => @minus,
241
+ :round_up => @round_up,
242
+ :base => @output_b)
242
243
  end
243
244
  return @adjusted_k, @adjusted_digits
244
245
  end
data/lib/flt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Flt
2
- VERSION = "1.4.2"
2
+ VERSION = "1.4.3"
3
3
  end
data/test/test_basic.rb CHANGED
@@ -134,6 +134,14 @@ class TestBasic < Test::Unit::TestCase
134
134
  assert_equal :half_even, DecNum.context.rounding
135
135
  assert_equal 10, DecNum.context.precision
136
136
 
137
+ context_a = DecNum::BasicContext
138
+ assert_equal :half_up, context_a.rounding
139
+ assert_equal 9, context_a.precision
140
+ context_b = context_a[precision: 11]
141
+ assert_equal 9, context_a.precision
142
+ assert_equal 11, context_b.precision
143
+ assert_equal :half_up, context_a.rounding
144
+ assert_equal :half_up, context_b.rounding
137
145
 
138
146
  assert_equal DecNum("0."+"3"*100), DecNum(1)./(DecNum(3),DecNum.Context(:precision=>100))
139
147
  assert_equal 10, DecNum.context.precision
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.2
4
+ version: 1.4.3
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-30 00:00:00.000000000 Z
11
+ date: 2014-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler