numerals 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +149 -5
- data/lib/numerals/conversions/bigdecimal.rb +209 -9
- data/lib/numerals/conversions/context_conversion.rb +40 -0
- data/lib/numerals/conversions/float.rb +106 -71
- data/lib/numerals/conversions/flt.rb +115 -44
- data/lib/numerals/conversions/integer.rb +32 -3
- data/lib/numerals/conversions/rational.rb +27 -3
- data/lib/numerals/conversions.rb +74 -33
- data/lib/numerals/digits.rb +8 -5
- data/lib/numerals/format/base_scaler.rb +160 -0
- data/lib/numerals/format/exp_setter.rb +218 -0
- data/lib/numerals/format/format.rb +257 -0
- data/lib/numerals/format/input.rb +140 -0
- data/lib/numerals/format/mode.rb +157 -0
- data/lib/numerals/format/notation.rb +51 -0
- data/lib/numerals/format/notations/html.rb +53 -0
- data/lib/numerals/format/notations/latex.rb +48 -0
- data/lib/numerals/format/notations/text.rb +141 -0
- data/lib/numerals/format/output.rb +167 -0
- data/lib/numerals/format/symbols.rb +565 -0
- data/lib/numerals/format/text_parts.rb +35 -0
- data/lib/numerals/format.rb +25 -0
- data/lib/numerals/formatting_aspect.rb +36 -0
- data/lib/numerals/numeral.rb +34 -21
- data/lib/numerals/repeat_detector.rb +99 -0
- data/lib/numerals/rounding.rb +340 -181
- data/lib/numerals/version.rb +1 -1
- data/lib/numerals.rb +4 -2
- data/numerals.gemspec +1 -1
- data/test/test_base_scaler.rb +189 -0
- data/test/test_big_conversions.rb +105 -0
- data/test/test_digits_definition.rb +23 -28
- data/test/test_exp_setter.rb +732 -0
- data/test/test_float_conversions.rb +48 -30
- data/test/test_flt_conversions.rb +476 -80
- data/test/test_format.rb +124 -0
- data/test/test_format_input.rb +226 -0
- data/test/test_format_mode.rb +124 -0
- data/test/test_format_output.rb +789 -0
- data/test/test_integer_conversions.rb +22 -22
- data/test/test_numeral.rb +35 -0
- data/test/test_rational_conversions.rb +28 -28
- data/test/test_repeat_detector.rb +72 -0
- data/test/test_rounding.rb +158 -0
- data/test/test_symbols.rb +32 -0
- metadata +38 -5
- data/lib/numerals/formatting/digits_definition.rb +0 -75
@@ -5,43 +5,46 @@ include Numerals
|
|
5
5
|
|
6
6
|
class TestFloatConversions < Test::Unit::TestCase # < Minitest::Test
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
assert_equal Numeral.nan, Conversions.
|
11
|
-
assert_equal Numeral.nan, Conversions.
|
12
|
-
assert_equal Numeral.nan, Conversions.
|
13
|
-
assert_equal Numeral.nan, Conversions.
|
14
|
-
|
15
|
-
|
16
|
-
assert_equal Numeral.infinity, Conversions.
|
17
|
-
assert_equal Numeral.infinity, Conversions.
|
18
|
-
assert_equal Numeral.infinity, Conversions.
|
19
|
-
assert_equal Numeral.infinity, Conversions.
|
20
|
-
|
21
|
-
|
22
|
-
assert_equal Numeral.infinity(-1), Conversions.
|
23
|
-
assert_equal Numeral.infinity(-1), Conversions.
|
24
|
-
assert_equal Numeral.infinity(-1), Conversions.
|
25
|
-
assert_equal Numeral.infinity(-1), Conversions.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
8
|
+
|
9
|
+
def test_write_special
|
10
|
+
assert_equal Numeral.nan, Conversions.write(Float.context.nan)
|
11
|
+
assert_equal Numeral.nan, Conversions.write(Float.context.nan, rounding: Rounding[:short, base: 2])
|
12
|
+
assert_equal Numeral.nan, Conversions.write(Float.context.nan, rounding: Rounding[:short, base: 10])
|
13
|
+
assert_equal Numeral.nan, Conversions.write(Float.context.nan, rounding: Rounding[precision: 10, base: 10])
|
14
|
+
assert_equal Numeral.nan, Conversions.write(Float.context.nan)
|
15
|
+
|
16
|
+
assert_equal Numeral.infinity, Conversions.write(Float.context.infinity)
|
17
|
+
assert_equal Numeral.infinity, Conversions.write(Float.context.infinity, rounding: Rounding[:short, base: 2])
|
18
|
+
assert_equal Numeral.infinity, Conversions.write(Float.context.infinity, rounding: Rounding[:short, base: 10])
|
19
|
+
assert_equal Numeral.infinity, Conversions.write(Float.context.infinity, rounding: Rounding[precision: 10, base: 10])
|
20
|
+
assert_equal Numeral.infinity, Conversions.write(Float.context.infinity)
|
21
|
+
|
22
|
+
assert_equal Numeral.infinity(-1), Conversions.write(Float.context.infinity(-1))
|
23
|
+
assert_equal Numeral.infinity(-1), Conversions.write(Float.context.infinity(-1), rounding: Rounding[:short, base: 2])
|
24
|
+
assert_equal Numeral.infinity(-1), Conversions.write(Float.context.infinity(-1), rounding: Rounding[:short, base: 10])
|
25
|
+
assert_equal Numeral.infinity(-1), Conversions.write(Float.context.infinity(-1), rounding: Rounding[precision: 10, base: 10])
|
26
|
+
assert_equal Numeral.infinity(-1), Conversions.write(Float.context.infinity(-1))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_read_special
|
30
|
+
assert Conversions.read(Numeral.nan, type: Float).nan?
|
31
|
+
assert_equal Float.context.infinity, Conversions.read(Numeral.infinity, type: Float)
|
32
|
+
assert_equal Float.context.infinity(-1), Conversions.read(Numeral.infinity(-1), type: Float)
|
30
33
|
end
|
31
34
|
|
32
|
-
def
|
33
|
-
assert_equal Numeral[1,point:1], Conversions.
|
34
|
-
assert_equal Numeral[1,point:1, sign: -1], Conversions.
|
35
|
+
def test_write_read_exact
|
36
|
+
assert_equal Numeral[1,point:1], Conversions.write(1.0, rounding: Rounding[:short, base: 10])
|
37
|
+
assert_equal Numeral[1,point:1, sign: -1], Conversions.write(-1.0, rounding: Rounding[:short, base: 10])
|
35
38
|
|
36
|
-
assert_equal Numeral[1,point:1, base: 2], Conversions.
|
37
|
-
assert_equal Numeral[1,point:1, sign: -1, base: 2], Conversions.
|
39
|
+
assert_equal Numeral[1,point:1, base: 2], Conversions.write(1.0, rounding: Rounding[:short, base: 2])
|
40
|
+
assert_equal Numeral[1,point:1, sign: -1, base: 2], Conversions.write(-1.0, rounding: Rounding[:short, base: 2])
|
38
41
|
|
39
42
|
[0.1, 0.01, 0.001, 1/3.0, 10/3.0, 100/3.0, Math::PI, 0.5, 123.0, 123.45, 1.23E32, 1.23E-32].each do |x|
|
40
43
|
[x, -x].each do |y|
|
41
44
|
numeral = exact_decimal(y)
|
42
|
-
tmp = Conversions.
|
43
|
-
assert_equal numeral, Conversions.
|
44
|
-
assert_equal y, Conversions.
|
45
|
+
tmp = Conversions.write(y, rounding: Rounding[:short, base: 10])
|
46
|
+
assert_equal numeral, Conversions.write(y, exact: true, rounding: Rounding[:short, base: 10]), "#{y} to base 10 exact numeral"
|
47
|
+
assert_equal y, Conversions.read(numeral, type: Float), "#{x} base 10 numeral to float"
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
@@ -55,4 +58,19 @@ class TestFloatConversions < Test::Unit::TestCase # < Minitest::Test
|
|
55
58
|
}
|
56
59
|
end
|
57
60
|
|
61
|
+
def test_type_parameters
|
62
|
+
c = Conversions[Float, input_rounding: :down]
|
63
|
+
assert_equal Rounding[:down, base: Float::RADIX], c.input_rounding
|
64
|
+
c = Conversions[Float, input_rounding: :half_even]
|
65
|
+
assert_equal Rounding[:half_even, base: Float::RADIX], c.input_rounding
|
66
|
+
|
67
|
+
c = Conversions[Float, input_rounding: Rounding[:half_up, precision: 7, base: 3]]
|
68
|
+
assert_equal Rounding[:half_up, base: Float::RADIX], c.input_rounding
|
69
|
+
|
70
|
+
c = Conversions[Float.context, input_rounding: :context]
|
71
|
+
assert_equal Float.context.radix, c.input_rounding.base
|
72
|
+
assert_equal Float.context.rounding, c.input_rounding.mode
|
73
|
+
assert_equal Float.context.precision, c.input_rounding.precision
|
74
|
+
end
|
75
|
+
|
58
76
|
end
|