flt 1.4.5 → 1.4.6

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: 7de71640b6e679c521d717895549d5858393bf9a
4
- data.tar.gz: 20405872b9008205ffd8f4af67b2197be583539f
3
+ metadata.gz: 8f6269709d2755e8f6cc52aed9a2d2bbee4cbcf0
4
+ data.tar.gz: 1e17d3367948b38a3d37bf011b76e0589000a8a0
5
5
  SHA512:
6
- metadata.gz: d5b4929799d05f048bf51827ad8dd3704467d71e4d93b996e3841c2a85d098770b20f70a7dd75b1dd86d4975d05c1232a9669e826eea70370f03e93dd61ccca6
7
- data.tar.gz: a4f6ee9f59a5e6c70c128f902465927bd68a07858871a6dff468fa78a5615d5048e6c2e4302210b60ca749b1d54dabc8175220ec617fb888e7cbba1517b68791
6
+ metadata.gz: e58ff28351ba6dbf89c2bd2c2b5acb8837e4a45237231a471bbc085bbbfe048557db87a94c49b63a5716a76f833419356c4519b1adb5f3b92cd6368b8948fa9a
7
+ data.tar.gz: 0cb92e963d19b7937fe841fb7b83506d8ba4bec7a395636ae2d2bae20ee585144744692a9088f9cad5e7e0ac00722e64ffc33c2e246cde62c902a6186b3dea0e
@@ -1,3 +1,8 @@
1
+ == 1.4.6 2015-04-07
2
+
3
+ * Bugfix
4
+ - BigDecimal.context.copy_sign returned a Float
5
+
1
6
  == 1.4.5 2015-03-04
2
7
 
3
8
  * New feature
@@ -83,20 +83,25 @@ class Flt::BigDecimalContext
83
83
  ROUNDING_MODES[BigDecimal.mode(BigDecimal::ROUND_MODE, nil)]
84
84
  end
85
85
 
86
- # Sign: -1 for minus, +1 for plus, nil for nan (note that Float zero is signed)
86
+ # Sign: -1 for minus, +1 for plus, nil for nan (note that BigDecimal zero is signed)
87
87
  def sign(x)
88
- x.sign < 0 ? -1 : +1
88
+ big_dec_sign = x.sign
89
+ if big_dec_sign < 0
90
+ -1
91
+ elsif big_dec_sign > 0
92
+ +1
93
+ end
89
94
  end
90
95
 
91
96
  # Return copy of x with the sign of y
92
97
  def copy_sign(x, y)
93
- self_sign = x.sign
98
+ self_sign = sign(x)
94
99
  other_sign = y.is_a?(Integer) ? (y < 0 ? -1 : +1) : y.sign
95
100
  if self_sign && other_sign
96
101
  if self_sign == other_sign
97
- x.to_f
102
+ x
98
103
  else
99
- -x.to_f
104
+ -x
100
105
  end
101
106
  else
102
107
  nan
@@ -1,3 +1,3 @@
1
1
  module Flt
2
- VERSION = "1.4.5"
2
+ VERSION = "1.4.6"
3
3
  end
@@ -0,0 +1,38 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
+
3
+ class TestBigDecimal < Test::Unit::TestCase
4
+
5
+ def setup
6
+ initialize_context
7
+ end
8
+
9
+ def test_sign
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
+
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
+
24
+ assert_nil BigDecimal.context.sign(BigDecimal.context.nan)
25
+ end
26
+
27
+ def copy_sign
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
+ end
37
+
38
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
+
3
+ class TestFloat < Test::Unit::TestCase
4
+
5
+ def setup
6
+ initialize_context
7
+ end
8
+
9
+ 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)
17
+
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)
25
+
26
+ assert_nil Float.context.sign(Float.context.nan)
27
+ end
28
+
29
+ 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)
38
+ end
39
+
40
+ end
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.5
4
+ version: 1.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Goizueta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,6 +83,7 @@ files:
83
83
  - test/reader.rb
84
84
  - test/test_base_digits.rb
85
85
  - test/test_basic.rb
86
+ - test/test_big_decimal.rb
86
87
  - test/test_bin.rb
87
88
  - test/test_bin_arithmetic.rb
88
89
  - test/test_binfloat_conversion.rb
@@ -93,6 +94,7 @@ files:
93
94
  - test/test_epsilon.rb
94
95
  - test/test_exact.rb
95
96
  - test/test_flags.rb
97
+ - test/test_float.rb
96
98
  - test/test_format.rb
97
99
  - test/test_formatter.rb
98
100
  - test/test_hex_format.rb
@@ -139,6 +141,7 @@ test_files:
139
141
  - test/reader.rb
140
142
  - test/test_base_digits.rb
141
143
  - test/test_basic.rb
144
+ - test/test_big_decimal.rb
142
145
  - test/test_bin.rb
143
146
  - test/test_bin_arithmetic.rb
144
147
  - test/test_binfloat_conversion.rb
@@ -149,6 +152,7 @@ test_files:
149
152
  - test/test_epsilon.rb
150
153
  - test/test_exact.rb
151
154
  - test/test_flags.rb
155
+ - test/test_float.rb
152
156
  - test/test_format.rb
153
157
  - test/test_formatter.rb
154
158
  - test/test_hex_format.rb