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 +4 -4
- data/History.txt +5 -0
- data/lib/flt/bigdecimal.rb +10 -5
- data/lib/flt/version.rb +1 -1
- data/test/test_big_decimal.rb +38 -0
- data/test/test_float.rb +40 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f6269709d2755e8f6cc52aed9a2d2bbee4cbcf0
|
4
|
+
data.tar.gz: 1e17d3367948b38a3d37bf011b76e0589000a8a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e58ff28351ba6dbf89c2bd2c2b5acb8837e4a45237231a471bbc085bbbfe048557db87a94c49b63a5716a76f833419356c4519b1adb5f3b92cd6368b8948fa9a
|
7
|
+
data.tar.gz: 0cb92e963d19b7937fe841fb7b83506d8ba4bec7a395636ae2d2bae20ee585144744692a9088f9cad5e7e0ac00722e64ffc33c2e246cde62c902a6186b3dea0e
|
data/History.txt
CHANGED
data/lib/flt/bigdecimal.rb
CHANGED
@@ -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
|
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
|
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
|
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
|
102
|
+
x
|
98
103
|
else
|
99
|
-
-x
|
104
|
+
-x
|
100
105
|
end
|
101
106
|
else
|
102
107
|
nan
|
data/lib/flt/version.rb
CHANGED
@@ -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
|
data/test/test_float.rb
ADDED
@@ -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.
|
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-
|
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
|