radix 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,84 +0,0 @@
1
- = Radix Rational
2
-
3
- require 'radix'
4
-
5
- == Initialization
6
-
7
- Radix::Rational's initializer takes a numerator and a denominator,
8
- either of which can be an Integer, Float, String or Array along witha
9
- an integer base.
10
-
11
- Give a integer value, it will automatically be converted to the base
12
- specified.
13
-
14
- check do |num, dem, base, eqf|
15
- r = Radix::Rational.new(num, dem, base)
16
- r.assert == eqf
17
- end
18
-
19
- ok 1, 2, 2, 0.5
20
- ok 1, 1, 2, 1.0
21
-
22
- ok 8, 1, 10, 8.0
23
- ok 8, 5, 10, 1.6
24
- ok 8, 8, 10, 1.0
25
-
26
- ok 10, 1, 10, 10.0
27
- ok 10, 2, 10, 5.0
28
- ok 10, 5, 10, 2.0
29
-
30
- ok 8, 1, 16, 8.0
31
- ok 16, 1, 16, 16.0
32
-
33
- == Reduction
34
-
35
- check do |a, x|
36
- r = a.reduce
37
- r.assert == x
38
- end
39
-
40
- ok [10,5].br(10), [2,1].br(10)
41
- ok [30,3].br(10), [10,1].br(10)
42
-
43
- == Operations
44
-
45
- === Addition
46
-
47
- check do |a, b, x|
48
- r = a + b
49
- r.assert == x
50
- end
51
-
52
- ok [8,5].br(10), [1,2].br(10), [21,10].br(10)
53
-
54
- ok [8,5].br(10), 1, [13,5].br(10)
55
-
56
- ok [8,5].br(10), 0.5, [21,10].br(10)
57
-
58
- === Subtraction
59
-
60
- check do |a, b, x|
61
- r = a - b
62
- r.assert == x
63
- end
64
-
65
- ok [8,5].br(10), [1,2].br(10), [11,10].br(10)
66
-
67
- === Multiplication
68
-
69
- check do |a, b, x|
70
- r = a * b
71
- r.assert == x
72
- end
73
-
74
- ok [8,5].br(10), [1,2].br(10), [8,10].br(10)
75
-
76
- === Division
77
-
78
- check do |a, b, x|
79
- r = a / b
80
- r.assert == x
81
- end
82
-
83
- ok [8,5].br(10), [1,2].br(10), [16,5].br(10)
84
-
@@ -1,78 +0,0 @@
1
- = Radix::Base
2
-
3
- The Radix::Base class is an encapsulatin of a numeric base. By creating
4
- an instance of Base one can convert numbers to and from other bases.
5
-
6
- require 'radix/base'
7
-
8
- == Base Instance
9
-
10
- First let's try something we all know, converting decimal to hexideciaml.
11
- To do this we setup the radix base objects for each base.
12
-
13
- b10 = Radix::Base.new(Radix::BASE::B10)
14
- b16 = Radix::Base.new(Radix::BASE::B16)
15
-
16
- Now we can covert from one base to the other.
17
-
18
- b16.convert("16" , b10).should == "10"
19
- b16.convert("160", b10).should == "A0"
20
- b16.convert("255", b10).should == "FF"
21
-
22
- To confirm, lets convert from hexidecimal back to decimal.
23
-
24
- b10.convert("10", b16).should == "16"
25
- b10.convert("A0", b16).should == "160"
26
- b10.convert("FF", b16).should == "255"
27
-
28
- If we are happy with standard encodings then we can simply provide an
29
- integer base, rather than a Radix::Base object.
30
-
31
- b10.convert("10", 16).should == "16"
32
- b10.convert("A0", 16).should == "160"
33
- b10.convert("FF", 16).should == "255"
34
-
35
- Now let's try a more down to earth base, my favorite,
36
- senary, or base six.
37
-
38
- b6 = Radix::Base.new(0..5)
39
- b6.convert("39", 10).should == "103"
40
-
41
- And the notations need not be in ASCII order. Odd alternate notations
42
- can be used as well.
43
-
44
- b10 = Radix::Base.new([:Q, :W, :E, :R, :T, :Y, :U, :I, :O, :U])
45
- b10.convert("FF", 16) #=> "EYY"
46
-
47
- == Encoding and Decoding
48
-
49
- Radix::Base instances can also be used to encode and decode strings.
50
-
51
- b16.encode("CHARLIE").should == "434841524C4945"
52
- b16.decode("434841524C4945").should == "CHARLIE"
53
-
54
- == Module Methods
55
-
56
- For further convenience, Radix::base provides functions to convert to and from
57
- standard notations upto 62 without creating an instance of Radix::Base.
58
-
59
- Radix.convert("10", 16, 10).should == "16"
60
- Radix.convert("A0", 16, 10).should == "160"
61
- Radix.convert("FF", 16, 10).should == "255"
62
-
63
- Let's try that again with the maximum base supported.
64
-
65
- Radix.convert( "62", 10, 62).should == "10"
66
- Radix.convert("8814542", 10, 62).should == "az42"
67
-
68
- Radix.convert( "10", 62, 10).should == "62"
69
- Radix.convert( "az42", 62, 10).should == "8814542"
70
-
71
- Finally, we will demonstrate how to convert bases larger than 62.
72
- These can only be represented as arrays since there are not enough
73
- latin characters to represent them.
74
-
75
- Radix.convert_base([100, 10], 256, 10).should == [2, 5, 6, 1, 0]
76
- Radix.convert_base([2, 5, 6, 1, 0], 10, 256).should == [100, 10]
77
- Radix.convert_base([1, 0, 1, 0, 1], 2, 10).should == [2, 1]
78
-
@@ -1 +0,0 @@
1
- require 'ae/should'
@@ -1 +0,0 @@
1
- require 'qed/extensions/check'