rdx 0.9.0.pre
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.
- checksums.yaml +7 -0
- data/.rdx +20 -0
- data/README +19 -0
- data/bin/rdx +7 -0
- data/examples/minimal/.rdx +8 -0
- data/examples/minimal/README +10 -0
- data/examples/minimal/lib/other_conventions.rb +64 -0
- data/examples/minimal/lib/the_basics.rb +94 -0
- data/examples/minimal/lib/using_directives.rb +66 -0
- data/examples/minimal/rakefile +27 -0
- data/examples/ruby-2.0.0-p0/README +7 -0
- data/examples/ruby-2.0.0-p0/install/core/.rdx +6 -0
- data/examples/ruby-2.0.0-p0/install/core/README +19 -0
- data/examples/ruby-2.0.0-p0/install/core/Rakefile +61 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/array.c.diff +166 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/bignum.c.diff +11 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/class.c.diff +36 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/compar.c.diff +11 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/complex.c.diff +301 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/cont.c.diff +65 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/dir.c.diff +147 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/re.rdoc.diff +328 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/security.rdoc.diff +8 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/standard_library.rdoc.diff +0 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax.rdoc.diff +0 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/assignment.rdoc.diff +160 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/calling_methods.rdoc.diff +130 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/control_expressions.rdoc.diff +254 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/exceptions.rdoc.diff +0 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/literals.rdoc.diff +54 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/methods.rdoc.diff +157 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/miscellaneous.rdoc.diff +91 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/modules_and_classes.rdoc.diff +161 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/precedence.rdoc.diff +8 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/refinements.rdoc.diff +146 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/encoding.c.diff +276 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/enum.c.diff +281 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/enumerator.c.diff +479 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/error.c.diff +143 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/eval.c.diff +47 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/eval_jump.c.diff +23 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/file.c.diff +752 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/gc.c.diff +195 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/hash.c.diff +84 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/iseq.c.diff +354 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/load.c.diff +53 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/marshal.c.diff +98 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/math.c.diff +110 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/numeric.c.diff +103 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/object.c.diff +295 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/pack.c.diff +18 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/parse.y.diff +23 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/proc.c.diff +155 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/random.c.diff +126 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/range.c.diff +49 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/rational.c.diff +312 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/re.c.diff +207 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/ruby.c.diff +21 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/signal.c.diff +67 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/sprintf.c.diff +29 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/string.c.diff +73 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/struct.c.diff +20 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/time.c.diff +691 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/transcode.c.diff +435 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/variable.c.diff +62 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/vm_backtrace.c.diff +164 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/vm_eval.c.diff +99 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/vm_method.c.diff +17 -0
- data/examples/ruby-2.0.0-p0/install/core/diffs/vm_trace.c.diff +393 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/.rdx +6 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/README +19 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/Rakefile +53 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/abbrev.rb.diff +77 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/base64.rb.diff +42 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/benchmark.rb.diff +144 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/cmath.rb.diff +52 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/forwardable.rb.diff +150 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/mathn.rb.diff +58 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/matrix.rb.diff +657 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/observer.rb.diff +31 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/optparse.rb.diff +147 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/ostruct.rb.diff +78 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/prime.rb.diff +52 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/pstore.rb.diff +110 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/scanf.rb.diff +100 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/securerandom.rb.diff +144 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/set.rb.diff +637 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/shellwords.rb.diff +66 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/singleton.rb.diff +37 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/tempfile.rb.diff +104 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/thread.rb.diff +38 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/time.rb.diff +140 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/tmpdir.rb.diff +52 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/uri.rb.diff +39 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/uri/common.rb.diff +237 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/weakref.rb.diff +36 -0
- data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/yaml/store.rb.diff +27 -0
- data/examples/ruby-2.0.0-p0/rakefile +165 -0
- data/lib/rdx.rb +331 -0
- data/lib/rdx/assertions.rb +484 -0
- data/lib/rdx/binding.rb +151 -0
- data/lib/rdx/code_object.rb +598 -0
- data/lib/rdx/comment.rb +338 -0
- data/lib/rdx/convention.rb +1174 -0
- data/lib/rdx/directive.rb +1432 -0
- data/lib/rdx/example.rb +679 -0
- data/lib/rdx/generator.rb +112 -0
- data/lib/rdx/generator/rdoc.rb +1006 -0
- data/lib/rdx/options.rb +359 -0
- data/lib/rdx/plain_text.rb +65 -0
- data/lib/rdx/reporter.rb +421 -0
- data/lib/rdx/ruby_lex.rb +324 -0
- data/lib/rdx/runner.rb +309 -0
- data/lib/rdx/source_file.rb +94 -0
- data/lib/rdx/specification.rb +194 -0
- data/lib/rdx/statement.rb +248 -0
- data/lib/rdx/store.rb +119 -0
- data/lib/rdx/task.rb +361 -0
- data/lib/rdx/text.rb +688 -0
- data/lib/rdx/version.rb +15 -0
- data/rakefile +64 -0
- metadata +203 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
--- core/orig/pack.c 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/pack.c 2015-06-25 17:35:23 +0000
|
3
|
+
@@ -286,6 +286,7 @@
|
4
|
+
* n.pack("ccc") #=> "ABC"
|
5
|
+
*
|
6
|
+
* Directives for +pack+.
|
7
|
+
+ * :rdx: off -
|
8
|
+
*
|
9
|
+
* Integer | Array |
|
10
|
+
* Directive | Element | Meaning
|
11
|
+
@@ -1232,6 +1233,7 @@
|
12
|
+
*
|
13
|
+
* This table summarizes the various formats and the Ruby classes
|
14
|
+
* returned by each.
|
15
|
+
+ * :rdx: off -
|
16
|
+
*
|
17
|
+
* Integer | |
|
18
|
+
* Directive | Returns | Meaning
|
@@ -0,0 +1,23 @@
|
|
1
|
+
--- core/orig/parse.y 2013-01-31 07:33:30 +0000
|
2
|
+
+++ core/patched/parse.y 2015-06-20 07:31:38 +0000
|
3
|
+
@@ -10390,13 +10390,13 @@
|
4
|
+
* Returns an array of all the symbols currently in Ruby's symbol
|
5
|
+
* table.
|
6
|
+
*
|
7
|
+
- * Symbol.all_symbols.size #=> 903
|
8
|
+
- * Symbol.all_symbols[1,20] #=> [:floor, :ARGV, :Binding, :symlink,
|
9
|
+
- * :chown, :EOFError, :$;, :String,
|
10
|
+
- * :LOCK_SH, :"setuid?", :$<,
|
11
|
+
- * :default_proc, :compact, :extend,
|
12
|
+
- * :Tms, :getwd, :$=, :ThreadGroup,
|
13
|
+
- * :wait2, :$>]
|
14
|
+
+ * Symbol.all_symbols.size #-> 903
|
15
|
+
+ * Symbol.all_symbols[1,20] #-> [:floor, :ARGV, :Binding, :symlink,
|
16
|
+
+ * # :chown, :EOFError, :$;, :String,
|
17
|
+
+ * # :LOCK_SH, :"setuid?", :$<,
|
18
|
+
+ * # :default_proc, :compact, :extend,
|
19
|
+
+ * # :Tms, :getwd, :$=, :ThreadGroup,
|
20
|
+
+ * # :wait2, :$>]
|
21
|
+
*/
|
22
|
+
|
23
|
+
VALUE
|
@@ -0,0 +1,155 @@
|
|
1
|
+
--- core/orig/proc.c 2015-06-11 07:51:43 +0000
|
2
|
+
+++ core/patched/proc.c 2015-06-12 23:46:09 +0000
|
3
|
+
@@ -147,9 +147,9 @@
|
4
|
+
*
|
5
|
+
* A Proc object generated by +lambda+ doesn't have such tricks.
|
6
|
+
*
|
7
|
+
- * lambda {|a,b| [a,b] }.call(1,2,3) #=> ArgumentError
|
8
|
+
- * lambda {|a,b| [a,b] }.call(1) #=> ArgumentError
|
9
|
+
- * lambda {|a,b| [a,b] }.call([1,2]) #=> ArgumentError
|
10
|
+
+ * lambda {|a,b| [a,b] }.call(1,2,3) # raises ArgumentError
|
11
|
+
+ * lambda {|a,b| [a,b] }.call(1) # raises ArgumentError
|
12
|
+
+ * lambda {|a,b| [a,b] }.call([1,2]) # raises ArgumentError
|
13
|
+
*
|
14
|
+
* Proc#lambda? is a predicate for the tricks.
|
15
|
+
* It returns +true+ if no tricks apply.
|
16
|
+
@@ -198,7 +198,7 @@
|
17
|
+
* class C
|
18
|
+
* define_method(:d) {}
|
19
|
+
* end
|
20
|
+
- * C.new.d(1,2) #=> ArgumentError
|
21
|
+
+ * C.new.d(1,2) # raises ArgumentError
|
22
|
+
* C.new.method(:d).to_proc.lambda? #=> true
|
23
|
+
*
|
24
|
+
* +define_method+ always defines a method without the tricks,
|
25
|
+
@@ -208,7 +208,7 @@
|
26
|
+
* class C
|
27
|
+
* define_method(:e, &proc {})
|
28
|
+
* end
|
29
|
+
- * C.new.e(1,2) #=> ArgumentError
|
30
|
+
+ * C.new.e(1,2) # raises ArgumentError
|
31
|
+
* C.new.method(:e).to_proc.lambda? #=> true
|
32
|
+
*
|
33
|
+
* This exception insures that methods never have tricks
|
34
|
+
@@ -221,7 +221,7 @@
|
35
|
+
*
|
36
|
+
* def2(:f) {}
|
37
|
+
* end
|
38
|
+
- * C.new.f(1,2) #=> ArgumentError
|
39
|
+
+ * C.new.f(1,2) # raises ArgumentError
|
40
|
+
*
|
41
|
+
* The wrapper <i>def2</i> defines a method which has no tricks.
|
42
|
+
*
|
43
|
+
@@ -547,11 +547,9 @@
|
44
|
+
* a_proc = lambda {|a,b| a}
|
45
|
+
* a_proc.call(1,2,3)
|
46
|
+
*
|
47
|
+
- * <em>produces:</em>
|
48
|
+
+ * <em>raises the exception:</em>
|
49
|
+
*
|
50
|
+
- * prog.rb:4:in `block in <main>': wrong number of arguments (3 for 2) (ArgumentError)
|
51
|
+
- * from prog.rb:5:in `call'
|
52
|
+
- * from prog.rb:5:in `<main>'
|
53
|
+
+ * wrong number of arguments (3 for 2) (ArgumentError)
|
54
|
+
*
|
55
|
+
*/
|
56
|
+
|
57
|
+
@@ -649,7 +647,7 @@
|
58
|
+
*
|
59
|
+
* proc { |x = 0| }.arity #=> 0
|
60
|
+
* lambda { |a = 0| }.arity #=> -1
|
61
|
+
- * proc { |x=0, y| }.arity #=> 0
|
62
|
+
+ * proc { |x=0, y| }.arity #=> 1
|
63
|
+
* lambda { |x=0, y| }.arity #=> -2
|
64
|
+
* proc { |x=0, y=0| }.arity #=> 0
|
65
|
+
* lambda { |x=0, y=0| }.arity #=> -1
|
66
|
+
@@ -1434,7 +1432,7 @@
|
67
|
+
* A.define_singleton_method(:who_am_i) do
|
68
|
+
* "I am: #{class_name}"
|
69
|
+
* end
|
70
|
+
- * A.who_am_i # ==> "I am: A"
|
71
|
+
+ * A.who_am_i # => "I am: A"
|
72
|
+
*
|
73
|
+
* guy = "Bob"
|
74
|
+
* guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
|
75
|
+
@@ -1635,15 +1633,12 @@
|
76
|
+
* bm.call
|
77
|
+
* bm = um.bind(B.new)
|
78
|
+
* bm.call
|
79
|
+
- * bm = um.bind(A.new)
|
80
|
+
- * bm.call
|
81
|
+
+ * bm = um.bind(A.new) # raises TypeError: bind argument must be an instance of B
|
82
|
+
*
|
83
|
+
* <em>produces:</em>
|
84
|
+
*
|
85
|
+
* In test, class = C
|
86
|
+
* In test, class = B
|
87
|
+
- * prog.rb:16:in `bind': bind argument must be an instance of B (TypeError)
|
88
|
+
- * from prog.rb:16
|
89
|
+
*/
|
90
|
+
|
91
|
+
static VALUE
|
92
|
+
@@ -2043,7 +2038,7 @@
|
93
|
+
}
|
94
|
+
|
95
|
+
/*
|
96
|
+
- * call_seq:
|
97
|
+
+ * call-seq:
|
98
|
+
* local_jump_error.exit_value -> obj
|
99
|
+
*
|
100
|
+
* Returns the exit value associated with this +LocalJumpError+.
|
101
|
+
@@ -2167,34 +2162,34 @@
|
102
|
+
* takes the rest of arguments.
|
103
|
+
*
|
104
|
+
* b = proc {|x, y, z| (x||0) + (y||0) + (z||0) }
|
105
|
+
- * p b.curry[1][2][3] #=> 6
|
106
|
+
- * p b.curry[1, 2][3, 4] #=> 6
|
107
|
+
- * p b.curry(5)[1][2][3][4][5] #=> 6
|
108
|
+
- * p b.curry(5)[1, 2][3, 4][5] #=> 6
|
109
|
+
- * p b.curry(1)[1] #=> 1
|
110
|
+
+ * b.curry[1][2][3] #=> 6
|
111
|
+
+ * b.curry[1, 2][3, 4] #=> 6
|
112
|
+
+ * b.curry(5)[1][2][3][4][5] #=> 6
|
113
|
+
+ * b.curry(5)[1, 2][3, 4][5] #=> 6
|
114
|
+
+ * b.curry(1)[1] #=> 1
|
115
|
+
*
|
116
|
+
* b = proc {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.inject(0, &:+) }
|
117
|
+
- * p b.curry[1][2][3] #=> 6
|
118
|
+
- * p b.curry[1, 2][3, 4] #=> 10
|
119
|
+
- * p b.curry(5)[1][2][3][4][5] #=> 15
|
120
|
+
- * p b.curry(5)[1, 2][3, 4][5] #=> 15
|
121
|
+
- * p b.curry(1)[1] #=> 1
|
122
|
+
+ * b.curry[1][2][3] #=> 6
|
123
|
+
+ * b.curry[1, 2][3, 4] #=> 10
|
124
|
+
+ * b.curry(5)[1][2][3][4][5] #=> 15
|
125
|
+
+ * b.curry(5)[1, 2][3, 4][5] #=> 15
|
126
|
+
+ * b.curry(1)[1] #=> 1
|
127
|
+
*
|
128
|
+
* b = lambda {|x, y, z| (x||0) + (y||0) + (z||0) }
|
129
|
+
- * p b.curry[1][2][3] #=> 6
|
130
|
+
- * p b.curry[1, 2][3, 4] #=> wrong number of arguments (4 for 3)
|
131
|
+
- * p b.curry(5) #=> wrong number of arguments (5 for 3)
|
132
|
+
- * p b.curry(1) #=> wrong number of arguments (1 for 3)
|
133
|
+
+ * b.curry[1][2][3] #=> 6
|
134
|
+
+ * b.curry[1, 2][3, 4] # raises ArgumentError: wrong number of arguments (4 for 3)
|
135
|
+
+ * b.curry(5) # raises ArgumentError: wrong number of arguments (5 for 3)
|
136
|
+
+ * b.curry(1) # raises ArgumentError: wrong number of arguments (1 for 3)
|
137
|
+
*
|
138
|
+
* b = lambda {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.inject(0, &:+) }
|
139
|
+
- * p b.curry[1][2][3] #=> 6
|
140
|
+
- * p b.curry[1, 2][3, 4] #=> 10
|
141
|
+
- * p b.curry(5)[1][2][3][4][5] #=> 15
|
142
|
+
- * p b.curry(5)[1, 2][3, 4][5] #=> 15
|
143
|
+
- * p b.curry(1) #=> wrong number of arguments (1 for 3)
|
144
|
+
+ * b.curry[1][2][3] #=> 6
|
145
|
+
+ * b.curry[1, 2][3, 4] #=> 10
|
146
|
+
+ * b.curry(5)[1][2][3][4][5] #=> 15
|
147
|
+
+ * b.curry(5)[1, 2][3, 4][5] #=> 15
|
148
|
+
+ * b.curry(1) # raises ArgumentError: wrong number of arguments (1 for 3+)
|
149
|
+
*
|
150
|
+
* b = proc { :foo }
|
151
|
+
- * p b.curry[] #=> :foo
|
152
|
+
+ * b.curry[] #=> :foo
|
153
|
+
*/
|
154
|
+
static VALUE
|
155
|
+
proc_curry(int argc, VALUE *argv, VALUE self)
|
@@ -0,0 +1,126 @@
|
|
1
|
+
--- core/orig/random.c 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/random.c 2015-06-20 07:58:39 +0000
|
3
|
+
@@ -563,7 +563,7 @@
|
4
|
+
* Returns an arbitrary seed value. This is used by Random.new
|
5
|
+
* when no seed value is specified as an argument.
|
6
|
+
*
|
7
|
+
- * Random.new_seed #=> 115032730400174366788466674494640623225
|
8
|
+
+ * Random.new_seed #-> 115032730400174366788466674494640623225
|
9
|
+
*/
|
10
|
+
static VALUE
|
11
|
+
random_seed(void)
|
12
|
+
@@ -582,10 +582,10 @@
|
13
|
+
*
|
14
|
+
* prng1 = Random.new(1234)
|
15
|
+
* prng1.seed #=> 1234
|
16
|
+
- * prng1.rand(100) #=> 47
|
17
|
+
+ * rand = prng1.rand(100) #-> 47
|
18
|
+
*
|
19
|
+
* prng2 = Random.new(prng1.seed)
|
20
|
+
- * prng2.rand(100) #=> 47
|
21
|
+
+ * prng2.rand(100) #=> rand # 47
|
22
|
+
*/
|
23
|
+
static VALUE
|
24
|
+
random_get_seed(VALUE obj)
|
25
|
+
@@ -782,11 +782,19 @@
|
26
|
+
* between different runs of the program. By setting the seed to a known value,
|
27
|
+
* programs can be made deterministic during testing.
|
28
|
+
*
|
29
|
+
- * srand 1234 # => 268519324636777531569100071560086917274
|
30
|
+
- * [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
|
31
|
+
- * [ rand(10), rand(1000) ] # => [4, 664]
|
32
|
+
+ *-- rdx
|
33
|
+
+ * orig_srand = srand
|
34
|
+
+ *++
|
35
|
+
+ * srand 1234 # -> 268519324636777531569100071560086917274
|
36
|
+
+ * rand1,rand2 = rand,rand # -> [0.1915194503788923,0.6221087710398319]
|
37
|
+
+ * [ rand(10), rand(1000) ] # -> [4, 664]
|
38
|
+
* srand 1234 # => 1234
|
39
|
+
- * [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
|
40
|
+
+ * [ rand, rand ] # => [rand1, rand2]
|
41
|
+
+ * # [0.1915194503788923,0.6221087710398319]
|
42
|
+
+ *-- rdx
|
43
|
+
+ * srand orig_srand
|
44
|
+
+ *++
|
45
|
+
+ *
|
46
|
+
*/
|
47
|
+
|
48
|
+
static VALUE
|
49
|
+
@@ -963,7 +971,7 @@
|
50
|
+
*
|
51
|
+
* Returns a random binary string containing +size+ bytes.
|
52
|
+
*
|
53
|
+
- * random_string = Random.new.bytes(10) # => "\xD7:R\xAB?\x83\xCE\xFAkO"
|
54
|
+
+ * random_string = Random.new.bytes(10) # -> "\xD7:R\xAB?\x83\xCE\xFAkO"
|
55
|
+
* random_string.size # => 10
|
56
|
+
*/
|
57
|
+
static VALUE
|
58
|
+
@@ -1159,20 +1167,20 @@
|
59
|
+
* is a negative integer or zero, +rand+ raises an ArgumentError.
|
60
|
+
*
|
61
|
+
* prng = Random.new
|
62
|
+
- * prng.rand(100) # => 42
|
63
|
+
+ * prng.rand(100) # -> 42
|
64
|
+
*
|
65
|
+
* When +max+ is a Float, +rand+ returns a random floating point number
|
66
|
+
* between 0.0 and +max+, including 0.0 and excluding +max+.
|
67
|
+
*
|
68
|
+
- * prng.rand(1.5) # => 1.4600282860034115
|
69
|
+
+ * prng.rand(1.5) # -> 1.4600282860034115
|
70
|
+
*
|
71
|
+
* When +max+ is a Range, +rand+ returns a random number where
|
72
|
+
* range.member?(number) == true.
|
73
|
+
*
|
74
|
+
- * prng.rand(5..9) # => one of [5, 6, 7, 8, 9]
|
75
|
+
- * prng.rand(5...9) # => one of [5, 6, 7, 8]
|
76
|
+
- * prng.rand(5.0..9.0) # => between 5.0 and 9.0, including 9.0
|
77
|
+
- * prng.rand(5.0...9.0) # => between 5.0 and 9.0, excluding 9.0
|
78
|
+
+ * prng.rand(5..9) # -> 6 # one of [5, 6, 7, 8, 9]
|
79
|
+
+ * prng.rand(5...9) # -> 8 # one of [5, 6, 7, 8]
|
80
|
+
+ * prng.rand(5.0..9.0) # -> 5.484030000720008 # between 5.0 and 9.0, including 9.0
|
81
|
+
+ * prng.rand(5.0...9.0) # -> 7.121666988157002 # between 5.0 and 9.0, excluding 9.0
|
82
|
+
*
|
83
|
+
* Both the beginning and ending values of the range must respond to subtract
|
84
|
+
* (<tt>-</tt>) and add (<tt>+</tt>)methods, or rand will raise an
|
85
|
+
@@ -1243,10 +1251,11 @@
|
86
|
+
* prng2 = Random.new(1234)
|
87
|
+
* prng1 == prng2 # => true
|
88
|
+
*
|
89
|
+
- * prng1.rand # => 0.1915194503788923
|
90
|
+
+ * rand1 = prng1.rand # -> 0.1915194503788923
|
91
|
+
* prng1 == prng2 # => false
|
92
|
+
*
|
93
|
+
- * prng2.rand # => 0.1915194503788923
|
94
|
+
+ * rand2 = prng2.rand # -> 0.1915194503788923
|
95
|
+
+ * rand1 == rand2 # => true
|
96
|
+
* prng1 == prng2 # => true
|
97
|
+
*/
|
98
|
+
static VALUE
|
99
|
+
@@ -1271,12 +1280,12 @@
|
100
|
+
* returns a pseudo-random floating point number between 0.0 and 1.0,
|
101
|
+
* including 0.0 and excluding 1.0.
|
102
|
+
*
|
103
|
+
- * rand #=> 0.2725926052826416
|
104
|
+
+ * rand #-> 0.2725926052826416
|
105
|
+
*
|
106
|
+
* When +max.abs+ is greater than or equal to 1, +rand+ returns a pseudo-random
|
107
|
+
* integer greater than or equal to 0 and less than +max.to_i.abs+.
|
108
|
+
*
|
109
|
+
- * rand(100) #=> 12
|
110
|
+
+ * rand(100) #-> 12
|
111
|
+
*
|
112
|
+
* When +max+ is a Range, +rand+ returns a random number where
|
113
|
+
* range.member?(number) == true.
|
114
|
+
@@ -1284,9 +1293,9 @@
|
115
|
+
* Negative or floating point values for +max+ are allowed, but may give
|
116
|
+
* surprising results.
|
117
|
+
*
|
118
|
+
- * rand(-100) # => 87
|
119
|
+
- * rand(-0.5) # => 0.8130921818028143
|
120
|
+
- * rand(1.9) # equivalent to rand(1), which is always 0
|
121
|
+
+ * rand(-100) # -> 87
|
122
|
+
+ * rand(-0.5) # -> 0.8130921818028143
|
123
|
+
+ * rand(1.9) # => 0 # equivalent to rand(1), which is always 0
|
124
|
+
*
|
125
|
+
* Kernel.srand may be used to ensure that sequences of random numbers are
|
126
|
+
* reproducible between different runs of a program.
|
@@ -0,0 +1,49 @@
|
|
1
|
+
--- core/orig/range.c 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/range.c 2015-06-20 08:08:42 +0000
|
3
|
+
@@ -356,7 +356,7 @@
|
4
|
+
* range elements.
|
5
|
+
*
|
6
|
+
* If no block is given, an enumerator is returned instead.
|
7
|
+
- *
|
8
|
+
+ *
|
9
|
+
* range = Xs.new(1)..Xs.new(10)
|
10
|
+
* range.step(2) {|x| puts x}
|
11
|
+
* puts
|
12
|
+
@@ -550,7 +550,7 @@
|
13
|
+
* satisfies the condition, it returns nil.
|
14
|
+
*
|
15
|
+
* ary = [0, 100, 100, 100, 200]
|
16
|
+
- * (0..4).bsearch {|i| 100 - ary[i] } #=> 1, 2 or 3
|
17
|
+
+ * (0..4).bsearch {|i| 100 - ary[i] } # -> 2 # may be even 1 or 3
|
18
|
+
* (0..4).bsearch {|i| 300 - ary[i] } #=> nil
|
19
|
+
* (0..4).bsearch {|i| 50 - ary[i] } #=> nil
|
20
|
+
*
|
21
|
+
@@ -729,7 +729,7 @@
|
22
|
+
* # prints: 10 11 12 13 14 15
|
23
|
+
*
|
24
|
+
* (2.5..5).each {|n| print n, ' ' }
|
25
|
+
- * # raises: TypeError: can't iterate from Float
|
26
|
+
+ * # raises TypeError: can't iterate from Float
|
27
|
+
*/
|
28
|
+
|
29
|
+
static VALUE
|
30
|
+
@@ -1271,6 +1271,8 @@
|
31
|
+
* to construct ranges. Note that the Comparable module is included
|
32
|
+
* so the <code>==</code> method is defined in terms of <code><=></code>.
|
33
|
+
*
|
34
|
+
+ * :rdx: setup
|
35
|
+
+ *
|
36
|
+
* class Xs # represent a string of 'x's
|
37
|
+
* include Comparable
|
38
|
+
* attr :length
|
39
|
+
@@ -1293,8 +1295,8 @@
|
40
|
+
*
|
41
|
+
* An example of using <code>Xs</code> to construct a range:
|
42
|
+
*
|
43
|
+
- * r = Xs.new(3)..Xs.new(6) #=> xxx..xxxxxx
|
44
|
+
- * r.to_a #=> [xxx, xxxx, xxxxx, xxxxxx]
|
45
|
+
+ * r = Xs.new(3)..Xs.new(6) # > xxx..xxxxxx
|
46
|
+
+ * r.to_a # > [xxx, xxxx, xxxxx, xxxxxx]
|
47
|
+
* r.member?(Xs.new(5)) #=> true
|
48
|
+
*
|
49
|
+
*/
|
@@ -0,0 +1,312 @@
|
|
1
|
+
--- core/orig/rational.c 2015-06-11 07:51:44 +0000
|
2
|
+
+++ core/patched/rational.c 2015-06-28 11:41:38 +0000
|
3
|
+
@@ -569,8 +569,8 @@
|
4
|
+
*
|
5
|
+
* Returns x/y;
|
6
|
+
*
|
7
|
+
- * Rational(1, 2) #=> (1/2)
|
8
|
+
- * Rational('1/2') #=> (1/2)
|
9
|
+
+ * Rational(1, 2) #=> 1/2
|
10
|
+
+ * Rational('1/2') #=> 1/2
|
11
|
+
*/
|
12
|
+
static VALUE
|
13
|
+
nurat_f_rational(int argc, VALUE *argv, VALUE klass)
|
14
|
+
@@ -606,6 +606,15 @@
|
15
|
+
* Rational(7, 1).denominator #=> 1
|
16
|
+
* Rational(9, -4).denominator #=> 4
|
17
|
+
* Rational(-2, -10).denominator #=> 5
|
18
|
+
+ * Rationals are automatically reduced when created:
|
19
|
+
+ * Rational(6,4) #=> 3/2
|
20
|
+
+ * therefore for every Rational <i>rat</i>
|
21
|
+
+ *-- rdx
|
22
|
+
+ * num = (-1)**rand(2) * rand(1000)
|
23
|
+
+ * den = 1 + rand(1000)
|
24
|
+
+ * rat = Rational(num, den)
|
25
|
+
+ *++
|
26
|
+
+ * we always end up with:
|
27
|
+
* rat.numerator.gcd(rat.denominator) #=> 1
|
28
|
+
*/
|
29
|
+
static VALUE
|
30
|
+
@@ -706,10 +715,10 @@
|
31
|
+
*
|
32
|
+
* Performs addition.
|
33
|
+
*
|
34
|
+
- * Rational(2, 3) + Rational(2, 3) #=> (4/3)
|
35
|
+
- * Rational(900) + Rational(1) #=> (900/1)
|
36
|
+
- * Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
|
37
|
+
- * Rational(9, 8) + 4 #=> (41/8)
|
38
|
+
+ * Rational(2, 3) + Rational(2, 3) #=> 4/3
|
39
|
+
+ * Rational(900) + Rational(1) #=> 901/1
|
40
|
+
+ * Rational(-2, 9) + Rational(-9, 2) #=> -85/18
|
41
|
+
+ * Rational(9, 8) + 4 #=> 41/8
|
42
|
+
* Rational(20, 9) + 9.8 #=> 12.022222222222222
|
43
|
+
*/
|
44
|
+
static VALUE
|
45
|
+
@@ -746,10 +755,10 @@
|
46
|
+
*
|
47
|
+
* Performs subtraction.
|
48
|
+
*
|
49
|
+
- * Rational(2, 3) - Rational(2, 3) #=> (0/1)
|
50
|
+
- * Rational(900) - Rational(1) #=> (899/1)
|
51
|
+
- * Rational(-2, 9) - Rational(-9, 2) #=> (77/18)
|
52
|
+
- * Rational(9, 8) - 4 #=> (23/8)
|
53
|
+
+ * Rational(2, 3) - Rational(2, 3) #=> 0/1
|
54
|
+
+ * Rational(900) - Rational(1) #=> 899/1
|
55
|
+
+ * Rational(-2, 9) - Rational(-9, 2) #=> 77/18
|
56
|
+
+ * Rational(9, 8) - 4 #=> -23/8
|
57
|
+
* Rational(20, 9) - 9.8 #=> -7.577777777777778
|
58
|
+
*/
|
59
|
+
static VALUE
|
60
|
+
@@ -825,10 +834,10 @@
|
61
|
+
*
|
62
|
+
* Performs multiplication.
|
63
|
+
*
|
64
|
+
- * Rational(2, 3) * Rational(2, 3) #=> (4/9)
|
65
|
+
- * Rational(900) * Rational(1) #=> (900/1)
|
66
|
+
- * Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
|
67
|
+
- * Rational(9, 8) * 4 #=> (9/2)
|
68
|
+
+ * Rational(2, 3) * Rational(2, 3) #=> 4/9
|
69
|
+
+ * Rational(900) * Rational(1) #=> 900/1
|
70
|
+
+ * Rational(-2, 9) * Rational(-9, 2) #=> 1/1
|
71
|
+
+ * Rational(9, 8) * 4 #=> 9/2
|
72
|
+
* Rational(20, 9) * 9.8 #=> 21.77777777777778
|
73
|
+
*/
|
74
|
+
static VALUE
|
75
|
+
@@ -866,10 +875,10 @@
|
76
|
+
*
|
77
|
+
* Performs division.
|
78
|
+
*
|
79
|
+
- * Rational(2, 3) / Rational(2, 3) #=> (1/1)
|
80
|
+
- * Rational(900) / Rational(1) #=> (900/1)
|
81
|
+
- * Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
|
82
|
+
- * Rational(9, 8) / 4 #=> (9/32)
|
83
|
+
+ * Rational(2, 3) / Rational(2, 3) #=> 1/1
|
84
|
+
+ * Rational(900) / Rational(1) #=> 900/1
|
85
|
+
+ * Rational(-2, 9) / Rational(-9, 2) #=> 4/81
|
86
|
+
+ * Rational(9, 8) / 4 #=> 9/32
|
87
|
+
* Rational(20, 9) / 9.8 #=> 0.22675736961451246
|
88
|
+
*/
|
89
|
+
static VALUE
|
90
|
+
@@ -952,11 +961,11 @@
|
91
|
+
*
|
92
|
+
* Performs exponentiation.
|
93
|
+
*
|
94
|
+
- * Rational(2) ** Rational(3) #=> (8/1)
|
95
|
+
- * Rational(10) ** -2 #=> (1/100)
|
96
|
+
+ * Rational(2) ** Rational(3) #=> 8/1
|
97
|
+
+ * Rational(10) ** -2 #=> 1/100
|
98
|
+
* Rational(10) ** -2.0 #=> 0.01
|
99
|
+
- * Rational(-4) ** Rational(1,2) #=> (1.2246063538223773e-16+2.0i)
|
100
|
+
- * Rational(1, 2) ** 0 #=> (1/1)
|
101
|
+
+ * Rational(-4) ** Rational(1,2) #=> 1.2246063538223773e-16+2.0i
|
102
|
+
+ * Rational(1, 2) ** 0 #=> 1/1
|
103
|
+
* Rational(1, 2) ** 0.0 #=> 1.0
|
104
|
+
*/
|
105
|
+
static VALUE
|
106
|
+
@@ -1198,8 +1207,7 @@
|
107
|
+
*
|
108
|
+
* Returns the truncated value as an integer.
|
109
|
+
*
|
110
|
+
- * Equivalent to
|
111
|
+
- * rat.truncate.
|
112
|
+
+ * Equivalent to <code>rat.truncate</code>.
|
113
|
+
*
|
114
|
+
* Rational(2, 3).to_i #=> 0
|
115
|
+
* Rational(3).to_i #=> 3
|
116
|
+
@@ -1281,12 +1289,13 @@
|
117
|
+
*
|
118
|
+
* Rational(3).floor #=> 3
|
119
|
+
* Rational(2, 3).floor #=> 0
|
120
|
+
- * Rational(-3, 2).floor #=> -1
|
121
|
+
- *
|
122
|
+
+ * Rational(-3, 2).floor #=> -2
|
123
|
+
+ *
|
124
|
+
+ * :rdx: off -
|
125
|
+
* decimal - 1 2 3 . 4 5 6
|
126
|
+
* ^ ^ ^ ^ ^ ^
|
127
|
+
* precision -3 -2 -1 0 +1 +2
|
128
|
+
- *
|
129
|
+
+ * :rdx:
|
130
|
+
* '%f' % Rational('-123.456').floor(+1) #=> "-123.500000"
|
131
|
+
* '%f' % Rational('-123.456').floor(-1) #=> "-130.000000"
|
132
|
+
*/
|
133
|
+
@@ -1307,10 +1316,11 @@
|
134
|
+
* Rational(2, 3).ceil #=> 1
|
135
|
+
* Rational(-3, 2).ceil #=> -1
|
136
|
+
*
|
137
|
+
+ * :rdx: off -
|
138
|
+
* decimal - 1 2 3 . 4 5 6
|
139
|
+
* ^ ^ ^ ^ ^ ^
|
140
|
+
* precision -3 -2 -1 0 +1 +2
|
141
|
+
- *
|
142
|
+
+ * :rdx:
|
143
|
+
* '%f' % Rational('-123.456').ceil(+1) #=> "-123.400000"
|
144
|
+
* '%f' % Rational('-123.456').ceil(-1) #=> "-120.000000"
|
145
|
+
*/
|
146
|
+
@@ -1331,10 +1341,11 @@
|
147
|
+
* Rational(2, 3).truncate #=> 0
|
148
|
+
* Rational(-3, 2).truncate #=> -1
|
149
|
+
*
|
150
|
+
+ * :rdx: off -
|
151
|
+
* decimal - 1 2 3 . 4 5 6
|
152
|
+
* ^ ^ ^ ^ ^ ^
|
153
|
+
* precision -3 -2 -1 0 +1 +2
|
154
|
+
- *
|
155
|
+
+ * :rdx:
|
156
|
+
* '%f' % Rational('-123.456').truncate(+1) #=> "-123.400000"
|
157
|
+
* '%f' % Rational('-123.456').truncate(-1) #=> "-120.000000"
|
158
|
+
*/
|
159
|
+
@@ -1356,10 +1367,11 @@
|
160
|
+
* Rational(2, 3).round #=> 1
|
161
|
+
* Rational(-3, 2).round #=> -2
|
162
|
+
*
|
163
|
+
+ * :rdx: off -
|
164
|
+
* decimal - 1 2 3 . 4 5 6
|
165
|
+
* ^ ^ ^ ^ ^ ^
|
166
|
+
* precision -3 -2 -1 0 +1 +2
|
167
|
+
- *
|
168
|
+
+ * :rdx:
|
169
|
+
* '%f' % Rational('-123.456').round(+1) #=> "-123.500000"
|
170
|
+
* '%f' % Rational('-123.456').round(-1) #=> "-120.000000"
|
171
|
+
*/
|
172
|
+
@@ -1393,8 +1405,8 @@
|
173
|
+
*
|
174
|
+
* Returns self.
|
175
|
+
*
|
176
|
+
- * Rational(2).to_r #=> (2/1)
|
177
|
+
- * Rational(-8, 6).to_r #=> (-4/3)
|
178
|
+
+ * Rational(2).to_r #=> 2/1
|
179
|
+
+ * Rational(-8, 6).to_r #=> -4/3
|
180
|
+
*/
|
181
|
+
static VALUE
|
182
|
+
nurat_to_r(VALUE self)
|
183
|
+
@@ -1508,9 +1520,9 @@
|
184
|
+
* otherwise.
|
185
|
+
*
|
186
|
+
* r = Rational(5033165, 16777216)
|
187
|
+
- * r.rationalize #=> (5033165/16777216)
|
188
|
+
- * r.rationalize(Rational('0.01')) #=> (3/10)
|
189
|
+
- * r.rationalize(Rational('0.1')) #=> (1/3)
|
190
|
+
+ * r.rationalize #=> 5033165/16777216
|
191
|
+
+ * r.rationalize(Rational('0.01')) #=> 3/10
|
192
|
+
+ * r.rationalize(Rational('0.1')) #=> 1/3
|
193
|
+
*/
|
194
|
+
static VALUE
|
195
|
+
nurat_rationalize(int argc, VALUE *argv, VALUE self)
|
196
|
+
@@ -1863,8 +1875,8 @@
|
197
|
+
*
|
198
|
+
* Returns the value as a rational.
|
199
|
+
*
|
200
|
+
- * 1.to_r #=> (1/1)
|
201
|
+
- * (1<<64).to_r #=> (18446744073709551616/1)
|
202
|
+
+ * 1.to_r #=> 1/1
|
203
|
+
+ * (1<<64).to_r #=> 18446744073709551616/1
|
204
|
+
*/
|
205
|
+
static VALUE
|
206
|
+
integer_to_r(VALUE self)
|
207
|
+
@@ -1922,10 +1934,10 @@
|
208
|
+
* NOTE: 0.3.to_r isn't the same as '0.3'.to_r. The latter is
|
209
|
+
* equivalent to '3/10'.to_r, but the former isn't so.
|
210
|
+
*
|
211
|
+
- * 2.0.to_r #=> (2/1)
|
212
|
+
- * 2.5.to_r #=> (5/2)
|
213
|
+
- * -0.75.to_r #=> (-3/4)
|
214
|
+
- * 0.0.to_r #=> (0/1)
|
215
|
+
+ * 2.0.to_r #=> 2/1
|
216
|
+
+ * 2.5.to_r #=> 5/2
|
217
|
+
+ * -0.75.to_r #=> -3/4
|
218
|
+
+ * 0.0.to_r #=> 0/1
|
219
|
+
*
|
220
|
+
* See rationalize.
|
221
|
+
*/
|
222
|
+
@@ -1959,9 +1971,9 @@
|
223
|
+
* <= flt+|eps|). if the optional eps is not given, it will be chosen
|
224
|
+
* automatically.
|
225
|
+
*
|
226
|
+
- * 0.3.rationalize #=> (3/10)
|
227
|
+
- * 1.333.rationalize #=> (1333/1000)
|
228
|
+
- * 1.333.rationalize(0.01) #=> (4/3)
|
229
|
+
+ * 0.3.rationalize #=> 3/10
|
230
|
+
+ * 1.333.rationalize #=> 1333/1000
|
231
|
+
+ * 1.333.rationalize(0.01) #=> 4/3
|
232
|
+
*
|
233
|
+
* See to_r.
|
234
|
+
*/
|
235
|
+
@@ -2246,14 +2258,14 @@
|
236
|
+
* NOTE: '0.3'.to_r isn't the same as 0.3.to_r. The former is
|
237
|
+
* equivalent to '3/10'.to_r, but the latter isn't so.
|
238
|
+
*
|
239
|
+
- * ' 2 '.to_r #=> (2/1)
|
240
|
+
- * '300/2'.to_r #=> (150/1)
|
241
|
+
- * '-9.2'.to_r #=> (-46/5)
|
242
|
+
- * '-9.2e2'.to_r #=> (-920/1)
|
243
|
+
- * '1_234_567'.to_r #=> (1234567/1)
|
244
|
+
- * '21 june 09'.to_r #=> (21/1)
|
245
|
+
- * '21/06/09'.to_r #=> (7/2)
|
246
|
+
- * 'bwv 1079'.to_r #=> (0/1)
|
247
|
+
+ * ' 2 '.to_r #=> 2/1
|
248
|
+
+ * '300/2'.to_r #=> 150/1
|
249
|
+
+ * '-9.2'.to_r #=> -46/5
|
250
|
+
+ * '-9.2e2'.to_r #=> -920/1
|
251
|
+
+ * '1_234_567'.to_r #=> 1234567/1
|
252
|
+
+ * '21 june 09'.to_r #=> 21/1
|
253
|
+
+ * '21/06/09'.to_r #=> 7/2
|
254
|
+
+ * 'bwv 1079'.to_r #=> 0/1
|
255
|
+
*/
|
256
|
+
static VALUE
|
257
|
+
string_to_r(VALUE self)
|
258
|
+
@@ -2376,37 +2388,39 @@
|
259
|
+
* In ruby, you can create rational object with Rational, to_r or
|
260
|
+
* rationalize method. The return values will be irreducible.
|
261
|
+
*
|
262
|
+
- * Rational(1) #=> (1/1)
|
263
|
+
- * Rational(2, 3) #=> (2/3)
|
264
|
+
- * Rational(4, -6) #=> (-2/3)
|
265
|
+
- * 3.to_r #=> (3/1)
|
266
|
+
+ * Rational(1) #=> 1/1
|
267
|
+
+ * Rational(2, 3) #=> 2/3
|
268
|
+
+ * Rational(4, -6) #=> -2/3
|
269
|
+
+ * 3.to_r #=> 3/1
|
270
|
+
*
|
271
|
+
* You can also create rational object from floating-point numbers or
|
272
|
+
* strings.
|
273
|
+
*
|
274
|
+
- * Rational(0.3) #=> (5404319552844595/18014398509481984)
|
275
|
+
- * Rational('0.3') #=> (3/10)
|
276
|
+
- * Rational('2/3') #=> (2/3)
|
277
|
+
- *
|
278
|
+
- * 0.3.to_r #=> (5404319552844595/18014398509481984)
|
279
|
+
- * '0.3'.to_r #=> (3/10)
|
280
|
+
- * '2/3'.to_r #=> (2/3)
|
281
|
+
- * 0.3.rationalize #=> (3/10)
|
282
|
+
+ * Rational(0.3) #=> 5404319552844595/18014398509481984
|
283
|
+
+ * Rational('0.3') #=> 3/10
|
284
|
+
+ * Rational('2/3') #=> 2/3
|
285
|
+
+ *
|
286
|
+
+ * 0.3.to_r #=> 5404319552844595/18014398509481984
|
287
|
+
+ * '0.3'.to_r #=> 3/10
|
288
|
+
+ * '2/3'.to_r #=> 2/3
|
289
|
+
+ * 0.3.rationalize #=> 3/10
|
290
|
+
*
|
291
|
+
* A rational object is an exact number, which helps you to write
|
292
|
+
* program without any rounding errors.
|
293
|
+
*
|
294
|
+
* 10.times.inject(0){|t,| t + 0.1} #=> 0.9999999999999999
|
295
|
+
- * 10.times.inject(0){|t,| t + Rational('0.1')} #=> (1/1)
|
296
|
+
+ * 10.times.inject(0){|t,| t + Rational('0.1')} #=> 1/1
|
297
|
+
*
|
298
|
+
* However, when an expression has inexact factor (numerical value or
|
299
|
+
* operation), will produce an inexact result.
|
300
|
+
*
|
301
|
+
- * Rational(10) / 3 #=> (10/3)
|
302
|
+
+ * Rational(10) / 3 #=> 10/3
|
303
|
+
+ * :rdx: bug the result is again 10/3
|
304
|
+
* Rational(10) / 3.0 #=> 3.3333333333333335
|
305
|
+
+ * :rdx:
|
306
|
+
*
|
307
|
+
* Rational(-8) ** Rational(1, 3)
|
308
|
+
- * #=> (1.0000000000000002+1.7320508075688772i)
|
309
|
+
+ * #=> 1.0000000000000002+1.7320508075688772i
|
310
|
+
*/
|
311
|
+
void
|
312
|
+
Init_Rational(void)
|