rdl 1.1.1 → 2.0.0.rc1

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +6 -0
  3. data/README.md +211 -32
  4. data/gemfiles/Gemfile.travis +1 -1
  5. data/lib/rdl.rb +85 -18
  6. data/lib/rdl/info.rb +74 -0
  7. data/lib/rdl/query.rb +8 -9
  8. data/lib/rdl/typecheck.rb +1057 -0
  9. data/lib/rdl/types/annotated_arg.rb +5 -5
  10. data/lib/rdl/types/{nil.rb → bot.rb} +9 -13
  11. data/lib/rdl/types/dependent_arg.rb +5 -5
  12. data/lib/rdl/types/dots_query.rb +2 -0
  13. data/lib/rdl/types/finitehash.rb +67 -24
  14. data/lib/rdl/types/generic.rb +13 -21
  15. data/lib/rdl/types/intersection.rb +9 -8
  16. data/lib/rdl/types/method.rb +30 -32
  17. data/lib/rdl/types/nominal.rb +22 -16
  18. data/lib/rdl/types/optional.rb +8 -22
  19. data/lib/rdl/types/parser.racc +8 -3
  20. data/lib/rdl/types/parser.tab.rb +131 -118
  21. data/lib/rdl/types/singleton.rb +15 -10
  22. data/lib/rdl/types/structural.rb +6 -6
  23. data/lib/rdl/types/top.rb +6 -6
  24. data/lib/rdl/types/tuple.rb +56 -24
  25. data/lib/rdl/types/type.rb +9 -0
  26. data/lib/rdl/types/type_inferencer.rb +1 -1
  27. data/lib/rdl/types/union.rb +52 -26
  28. data/lib/rdl/types/var.rb +7 -6
  29. data/lib/rdl/types/vararg.rb +5 -6
  30. data/lib/rdl/types/wild_query.rb +9 -2
  31. data/lib/rdl/util.rb +9 -7
  32. data/lib/rdl/wrap.rb +90 -72
  33. data/lib/rdl_types.rb +2 -2
  34. data/rdl.gemspec +6 -8
  35. data/test/test_alias.rb +4 -3
  36. data/test/test_contract.rb +5 -4
  37. data/test/test_dsl.rb +2 -1
  38. data/test/test_generic.rb +30 -26
  39. data/test/test_intersection.rb +3 -3
  40. data/test/test_le.rb +129 -61
  41. data/test/test_lib_types.rb +3 -2
  42. data/test/test_member.rb +33 -46
  43. data/test/test_parser.rb +113 -116
  44. data/test/test_query.rb +2 -1
  45. data/test/test_rdl.rb +64 -6
  46. data/test/test_rdl_type.rb +3 -2
  47. data/test/test_type_contract.rb +30 -12
  48. data/test/test_typecheck.rb +893 -0
  49. data/test/test_types.rb +50 -54
  50. data/test/test_wrap.rb +2 -1
  51. data/types/ruby-2.x/_aliases.rb +13 -2
  52. data/types/ruby-2.x/bigdecimal.rb +60 -85
  53. data/types/ruby-2.x/bignum.rb +80 -119
  54. data/types/ruby-2.x/complex.rb +33 -40
  55. data/types/ruby-2.x/fixnum.rb +81 -120
  56. data/types/ruby-2.x/float.rb +79 -116
  57. data/types/ruby-2.x/integer.rb +187 -22
  58. data/types/ruby-2.x/nil.rb +12 -0
  59. data/types/ruby-2.x/numeric.rb +38 -38
  60. data/types/ruby-2.x/object.rb +3 -3
  61. data/types/ruby-2.x/random.rb +2 -0
  62. data/types/ruby-2.x/range.rb +20 -19
  63. data/types/ruby-2.x/rational.rb +40 -40
  64. data/types/ruby-2.x/regexp.rb +4 -4
  65. data/types/ruby-2.x/string.rb +15 -17
  66. metadata +17 -16
  67. data/lib/rdl/types/.#lexer.rex +0 -1
@@ -1,20 +1,15 @@
1
1
  class Bignum < Integer
2
2
  rdl_nowrap
3
3
 
4
- type :%, '(Fixnum) -> Fixnum'
5
- pre(:%) { |x| x!=0}
6
- type :%, '(Bignum) -> Integer'
7
- pre(:%) { |x| x!=0}
8
- type :%, '(Float) -> Float'
9
- pre(:%) { |x| x!=0}
10
- type :%, '(Rational) -> Rational'
11
- pre(:%) { |x| x!=0}
12
- type :%, '(BigDecimal) -> BigDecimal'
13
- pre(:%) { |x| x!=0}
14
-
15
- type :&, '(Integer) -> Fixnum'
16
-
17
- type :*, '(Fixnum) -> Integer'
4
+ type :%, '(Fixnum x {{ x!=0 }}) -> Fixnum'
5
+ type :%, '(Bignum x {{ x!=0 }}) -> %integer'
6
+ type :%, '(Float x {{ x!=0 }}) -> Float'
7
+ type :%, '(Rational x {{ x!=0 }}) -> Rational'
8
+ type :%, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
9
+
10
+ type :&, '(%integer) -> Fixnum'
11
+
12
+ type :*, '(Fixnum) -> %integer'
18
13
  type :*, '(Bignum) -> Bignum'
19
14
  type :*, '(Float) -> Float'
20
15
  type :*, '(Rational) -> Rational'
@@ -22,53 +17,49 @@ class Bignum < Integer
22
17
  type :*, '(Complex) -> Complex'
23
18
  pre(:*) { |x| if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end} #can't have a complex with part BigDecimal, other part infinity/NAN
24
19
 
25
- type :**, '(Integer) -> Numeric'
26
- type :**, '(Float) -> Numeric'
27
- type :**, '(Rational) -> Numeric'
20
+ type :**, '(%integer) -> %numeric'
21
+ type :**, '(Float) -> %numeric'
22
+ type :**, '(Rational) -> %numeric'
28
23
  type :**, '(BigDecimal) -> BigDecimal'
29
24
  pre(:**) { |x| x!=BigDecimal::INFINITY && if self<0 then x<=-1||x>=0 else true end}
30
25
  post(:**) { |r,x| r.real?}
31
26
  type :**, '(Complex) -> Complex'
32
27
  pre(:**) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end}
33
28
 
34
- type :+, '(Integer) -> Integer'
29
+ type :+, '(%integer) -> %integer'
35
30
  type :+, '(Float) -> Float'
36
31
  type :+, '(Rational) -> Rational'
37
32
  type :+, '(BigDecimal) -> BigDecimal'
38
33
  type :+, '(Complex) -> Complex'
39
34
 
40
- type :-, '(Integer) -> Integer'
35
+ type :-, '(%integer) -> %integer'
41
36
  type :-, '(Float) -> Float'
42
37
  type :-, '(Rational) -> Rational'
43
38
  type :-, '(BigDecimal) -> BigDecimal'
44
39
  type :-, '(Complex) -> Complex'
45
40
 
46
- type :-, '() -> Integer'
41
+ type :-, '() -> %integer'
47
42
 
48
- type :/, '(Integer) -> Integer'
49
- pre(:/) { |x| x!=0}
50
- type :/, '(Float) -> Float'
51
- pre(:/) { |x| x!=0}
52
- type :/, '(Rational) -> Rational'
53
- pre(:/) { |x| x!=0}
54
- type :/, '(BigDecimal) -> BigDecimal'
55
- pre(:/) { |x| x!=0}
56
- type :/, '(Complex) -> Complex'
57
- pre(:/) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
43
+ type :/, '(%integer x {{ x!=0 }}) -> %integer'
44
+ type :/, '(Float x {{ x!=0 }}) -> Float'
45
+ type :/, '(Rational x {{ x!=0 }}) -> Rational'
46
+ type :/, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
47
+ type :/, '(Complex x {{ x!=0 }}) -> Complex'
48
+ pre(:/) { |x| if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
58
49
 
59
- type :<, '(Integer) -> %bool'
50
+ type :<, '(%integer) -> %bool'
60
51
  type :<, '(Float) -> %bool'
61
52
  type :<, '(Rational) -> %bool'
62
53
  type :<, '(BigDecimal) -> %bool'
63
54
 
64
- type :<<, '(Fixnum) -> Integer'
55
+ type :<<, '(Fixnum) -> %integer'
65
56
 
66
- type :<=, '(Integer) -> %bool'
57
+ type :<=, '(%integer) -> %bool'
67
58
  type :<=, '(Float) -> %bool'
68
59
  type :<=, '(Rational) -> %bool'
69
60
  type :<=, '(BigDecimal) -> %bool'
70
61
 
71
- type :<=>, '(Integer) -> Object'
62
+ type :<=>, '(%integer) -> Object'
72
63
  post(:<=>) { |r,x| r == -1 || r==0 || r==1}
73
64
  type :<=>, '(Float) -> Object'
74
65
  post(:<=>) { |r,x| r == -1 || r==0 || r==1}
@@ -81,20 +72,20 @@ class Bignum < Integer
81
72
 
82
73
  type :===, '(Object) -> %bool'
83
74
 
84
- type :>, '(Integer) -> %bool'
75
+ type :>, '(%integer) -> %bool'
85
76
  type :>, '(Float) -> %bool'
86
77
  type :>, '(Rational) -> %bool'
87
78
  type :>, '(BigDecimal) -> %bool'
88
79
 
89
- type :>=, '(Integer) -> %bool'
80
+ type :>=, '(%integer) -> %bool'
90
81
  type :>=, '(Float) -> %bool'
91
82
  type :>=, '(Rational) -> %bool'
92
83
  type :>=, '(BigDecimal) -> %bool'
93
84
 
94
- type :>>, '(Integer) -> Integer'
85
+ type :>>, '(%integer) -> %integer'
95
86
  post(:>>) { |r,x| r >= 0 }
96
87
 
97
- type :[], '(Integer) -> Fixnum'
88
+ type :[], '(%integer) -> Fixnum'
98
89
  post(:[]) { |r,x| r == 0 || r==1}
99
90
  type :[], '(Rational) -> Fixnum'
100
91
  post(:[]) { |r,x| r == 0 || r==1}
@@ -105,40 +96,32 @@ class Bignum < Integer
105
96
  pre(:[]) { |x| x!=BigDecimal::INFINITY && !x.nan? }
106
97
  post(:[]) { |r,x| r == 0 || r==1}
107
98
 
108
- type :^, '(Integer) -> Integer'
99
+ type :^, '(%integer) -> %integer'
109
100
 
110
- type :|, '(Integer) -> Integer'
101
+ type :|, '(%integer) -> %integer'
111
102
 
112
103
  type :~, '() -> Bignum'
113
104
 
114
- type :abs, '() -> Bignum'
115
- post(:abs) { |r,x| r >= 0 }
105
+ type :abs, '() -> Bignum r {{ r>=0 }}'
116
106
 
117
- type :bit_length, '() -> Integer'
118
- post(:bit_length) { |r,x| r >= 0 }
107
+ type :bit_length, '() -> %integer r {{ r>=0 }}'
119
108
 
120
- type :div, '(Fixnum) -> Integer'
121
- pre(:div) { |x| x!=0}
122
- type :div, '(Bignum) -> Integer'
123
- pre(:div) { |x| x!=0}
124
- type :div, '(Float) -> Integer'
125
- pre(:div) { |x| x!=0 && !x.nan?}
126
- type :div, '(Rational) -> Integer'
127
- pre(:div) { |x| x!=0}
128
- type :div, '(BigDecimal) -> Integer'
129
- pre(:div) { |x| x!=0 && !x.nan?}
109
+ type :div, '(%integer x {{ x!=0 }}) -> %integer'
110
+ type :div, '(Float x {{ x!=0 && !x.nan? }}) -> %integer'
111
+ type :div, '(Rational x {{ x!=0 }}) -> %integer'
112
+ type :div, '(BigDecimal x {{ x!=0 && !x.nan?}}) -> %integer'
130
113
 
131
114
  type :divmod, '(%real) -> [%real, %real]'
132
115
  pre(:divmod) { |x| x!=0 && if x.is_a?(Float) then !x.nan? else true end}
133
116
 
134
117
  type :even?, '() -> %bool'
135
118
 
136
- type :fdiv, '(Integer) -> Float'
119
+ type :fdiv, '(%integer) -> Float'
137
120
  type :fdiv, '(Float) -> Float'
138
121
  type :fdiv, '(Rational) -> Float'
139
122
  type :fdiv, '(BigDecimal) -> BigDecimal'
140
123
  type :fdiv, '(Complex) -> Complex'
141
- pre(:fdiv) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
124
+ pre(:fdiv) { |x| if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
142
125
 
143
126
  type :to_s, '() -> String'
144
127
  type :inspect, '() -> String'
@@ -146,108 +129,86 @@ class Bignum < Integer
146
129
  type :magnitude, '() -> Bignum'
147
130
  post(:magnitude) { |r,x| r >= 0 }
148
131
 
149
- type :modulo, '(Fixnum) -> Fixnum'
150
- pre(:modulo) { |x| x!=0}
151
- type :modulo, '(Bignum) -> Integer'
152
- pre(:modulo) { |x| x!=0}
153
- type :modulo, '(Float) -> Float'
154
- pre(:modulo) { |x| x!=0}
155
- type :modulo, '(Rational) -> Rational'
156
- pre(:modulo) { |x| x!=0}
157
- type :modulo, '(BigDecimal) -> BigDecimal'
158
- pre(:modulo) { |x| x!=0}
132
+ type :modulo, '(Fixnum x {{ x!=0 }}) -> Fixnum'
133
+ type :modulo, '(Bignum x {{ x!=0 }}) -> %integer'
134
+ type :modulo, '(Float x {{ x!=0 }}) -> Float'
135
+ type :modulo, '(Rational x {{ x!=0 }}) -> Rational'
136
+ type :modulo, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
159
137
 
160
- type :next, '() -> Integer'
138
+ type :next, '() -> %integer'
161
139
 
162
140
  type :odd?, '() -> %bool'
163
141
 
164
- type :size, '() -> Integer'
142
+ type :size, '() -> %integer'
165
143
 
166
- type :succ, '() -> Integer'
144
+ type :succ, '() -> %integer'
167
145
 
168
146
  type :to_f, '() -> Float'
169
147
 
170
148
  type :zero?, '() -> %bool'
171
149
 
172
- type :ceil, '() -> Integer'
150
+ type :ceil, '() -> %integer'
173
151
 
174
- type :denominator, '() -> Fixnum'
175
- post(:denominator) { |r,x| r == 1 }
152
+ type :denominator, '() -> Fixnum r {{ r==1 }}'
176
153
 
177
- type :floor, '() -> Integer'
154
+ type :floor, '() -> %integer'
178
155
 
179
156
  type :numerator, '() -> Bignum'
180
157
 
181
- type :quo, '(Integer) -> Rational'
182
- pre(:quo) { |x| x!=0}
183
- type :quo, '(Float) -> Float'
184
- pre(:quo) { |x| x!=0}
185
- type :quo, '(Rational) -> Rational'
186
- pre(:quo) { |x| x!=0}
187
- type :quo, '(BigDecimal) -> BigDecimal'
188
- pre(:quo) { |x| x!=0}
189
- type :quo, '(Complex) -> Complex'
190
- pre(:quo) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
158
+ type :quo, '(%integer x {{ x!=0 }}) -> Rational'
159
+ type :quo, '(Float x {{ x!=0 }}) -> Float'
160
+ type :quo, '(Rational x {{ x!=0 }}) -> Rational'
161
+ type :quo, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
162
+ type :quo, '(Complex x {{ x!=0 }}) -> Complex'
163
+ pre(:quo) { if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
191
164
 
192
- type :rationalize, '() -> Rational'
165
+ type :rationalize, '() -> Rational'
193
166
 
194
- type :rationalize, '(Numeric) -> Rational'
167
+ type :rationalize, '(%numeric) -> Rational'
195
168
 
196
- type :round, '() -> Integer'
169
+ type :round, '() -> %integer'
197
170
 
198
- type :round, '(Numeric) -> Numeric'
171
+ type :round, '(%numeric) -> %numeric'
199
172
  pre(:round) { |x| x!=0 && if x.is_a?(Complex) then x.imaginary==0 && (if x.real.is_a?(Float)||x.real.is_a?(BigDecimal) then !x.real.infinite? && !x.real.nan? else true end) elsif x.is_a?(Float) then x!=Float::INFINITY && !x.nan? elsif x.is_a?(BigDecimal) then x!=BigDecimal::INFINITY && !x.nan? else true end} #Also, x must be in range [-2**31, 2**31].
200
173
 
201
174
  type :to_i, '() -> Bignum'
202
175
 
203
176
  type :to_r, '() -> Rational'
204
177
 
205
- type :truncate, '() -> Integer'
178
+ type :truncate, '() -> %integer'
206
179
 
207
- type :angle, '() -> Numeric'
180
+ type :angle, '() -> %numeric'
208
181
  post(:angle) { |r,x| r == 0 || r == Math::PI}
209
182
 
210
- type :arg, '() -> Numeric'
183
+ type :arg, '() -> %numeric'
211
184
  post(:arg) { |r,x| r == 0 || r == Math::PI}
212
185
 
213
- type :equal?, '(Object) -> %bool'
186
+ type :equal?, '(Object) -> %bool'
214
187
  type :eql?, '(Object) -> %bool'
215
188
 
216
- type :hash, '() -> Integer'
189
+ type :hash, '() -> %integer'
217
190
 
218
- type :phase, '() -> Numeric'
191
+ type :phase, '() -> %numeric'
219
192
 
220
- type :abs2, '() -> Bignum'
221
- post(:abs2) { |r,x| r >= 0 }
193
+ type :abs2, '() -> Bignum r {{ r>=0 }}'
222
194
 
223
195
  type :conj, '() -> Bignum'
224
196
  type :conjugate, '() -> Bignum'
225
197
 
226
- type :imag, '() -> Fixnum'
227
- post(:imag) { |r,x| r == 0 }
228
- type :imaginary, '() -> Fixnum'
229
- post(:imaginary) { |r,x| r == 0 }
198
+ type :imag, '() -> Fixnum r {{ r==0 }}'
199
+ type :imaginary, '() -> Fixnum r {{ r==0 }}'
230
200
 
231
201
  type :real, '() -> Bignum'
232
202
 
233
- type :real?, '() -> TrueClass'
234
-
235
- type :to_c, '() -> Complex'
236
- post(:to_c) { |r,x| r.imaginary == 0 }
237
-
238
- type :remainder, '(Fixnum) -> Fixnum'
239
- pre(:remainder) { |x| x!=0}
240
- post(:remainder) { |r,x| r>0}
241
- type :remainder, '(Bignum) -> Fixnum'
242
- pre(:remainder) { |x| x!=0}
243
- post(:remainder) { |r,x| r>0}
244
- type :remainder, '(Float) -> Float'
245
- pre(:remainder) { |x| x!=0}
246
- type :remainder, '(Rational) -> Rational'
247
- pre(:remainder) { |x| x!=0}
248
- post(:remainder) { |r,x| r>0}
249
- type :remainder, '(BigDecimal) -> BigDecimal'
250
- pre(:remainder) { |x| x!=0}
251
-
252
- type :coerce, '(Integer) -> [Integer, Integer]'
203
+ type :real?, '() -> true'
204
+
205
+ type :to_c, '() -> Complex r {{ r.imaginary==0 }}'
206
+
207
+ type :remainder, '(Fixnum x {{ x!=0 }}) -> Fixnum r {{ r>=0 }}'
208
+ type :remainder, '(Bignum x {{ x!=0 }}) -> Fixnum r {{ r>=0 }}'
209
+ type :remainder, '(Float x {{ x!=0 }}) -> Float'
210
+ type :remainder, '(Rational x {{ x!=0 }}) -> Rational r {{ r>=0 }}'
211
+ type :remainder, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
212
+
213
+ type :coerce, '(%integer) -> [%integer, %integer]'
253
214
  end
@@ -1,7 +1,7 @@
1
1
  class Complex < Numeric
2
2
  rdl_nowrap
3
3
 
4
- type :*, '(Integer) -> Complex'
4
+ type :*, '(%integer) -> Complex'
5
5
  type :*, '(Float) -> Complex'
6
6
  pre(:*) { |x| if x.infinite?||x.nan? then !self.imaginary.is_a?(BigDecimal)&&!self.real.is_a?(BigDecimal) else true end}
7
7
  type :*, '(Rational) -> Complex'
@@ -10,15 +10,14 @@ class Complex < Numeric
10
10
  type :*, '(Complex) -> Complex'
11
11
  pre(:*) { |x| if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end}
12
12
 
13
- type :**, '(Integer) -> Complex'
13
+ type :**, '(%integer) -> Complex'
14
14
  type :**, '(Float) -> Complex'
15
15
  type :**, '(Rational) -> Complex'
16
- type :**, '(BigDecimal) -> Complex'
17
- pre(:**) { |x| x!=BigDecimal::INFINITY && !x.nan? && x>=0}
16
+ type :**, '(BigDecimal x {{ !x.infinite? && !x.nan? && x>=0 }}) -> Complex'
18
17
  type :**, '(Complex) -> Complex'
19
18
  pre(:**) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end}
20
19
 
21
- type :+, '(Integer) -> Complex'
20
+ type :+, '(%integer) -> Complex'
22
21
  type :+, '(Float) -> Complex'
23
22
  pre(:+) { |x| if x.infinite?||x.nan? then !self.real.is_a?(BigDecimal) else true end}
24
23
  type :+, '(Rational) -> Complex'
@@ -26,8 +25,8 @@ class Complex < Numeric
26
25
  pre(:+) {if x.real.is_a?(Float) then !x.real.infinite? && !x.real.nan? else true end}
27
26
  type :+, '(Complex) -> Complex'
28
27
  pre(:+) { |x| if (x.real.is_a?(BigDecimal) && self.real.is_a?(Float)) then !(self.real.infinite?||self.real.nan?) elsif x.real.is_a?(Float)&&self.real.is_a?(BigDecimal) then !(x.real.infinite?||x.real.nan?) elsif (x.imaginary.is_a?(BigDecimal) && self.imaginary.is_a?(Float)) then !(self.imaginary.infinite?||self.imaginary.nan?) elsif x.imaginary.is_a?(Float)&&self.imaginary.is_a?(BigDecimal) then !(x.imaginary.infinite?||x.imaginary.nan?) else true end}
29
-
30
- type :-, '(Integer) -> Complex'
28
+
29
+ type :-, '(%integer) -> Complex'
31
30
  type :-, '(Float) -> Complex'
32
31
  pre(:-) { |x| if x.infinite?||x.nan? then !self.real.is_a?(BigDecimal) else true end}
33
32
  type :-, '(Rational) -> Complex'
@@ -38,24 +37,20 @@ class Complex < Numeric
38
37
 
39
38
  type :-, '() -> Complex'
40
39
 
41
- type :/, '(Integer) -> Complex'
42
- pre(:/) { |x| x!=0}
43
- type :/, '(Float) -> Complex'
44
- pre(:/) { |x| x!=0 && if x.infinte?||x.nan? then !self.real.is_a?(BigDecimal) && !self.imaginary.is_a?(BigDecimal) else true end}
45
- type :/, '(Rational) -> Complex'
46
- pre(:/) { |x| x!=0}
47
- type :/, '(BigDecimal) -> Complex'
48
- pre(:/) { |x| x!=0 && if self.real.is_a?(Float) then !self.real.infinite? && !self.real.nan? else true end && if self.imaginary.is_a?(Float) then !self.imaginary.infinite? && !self.imaginary.nan? else true end}
49
- type :/, '(Complex) -> Complex'
50
- pre(:/) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal) || self.real.is_a?(BigDecimal) || self.imaginary .is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) && if self.real.is_a?(Float) then !self.real.infinite? && !self.real.nan? else true end && if self.imaginary.is_a?(Float) then !self.imaginary.infinite? && !self.imaginary.nan? else true end else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
40
+ type :/, '(%integer x {{ x!=0 }}) -> Complex'
41
+ type :/, '(Float x {{ x!=0 }}) -> Complex'
42
+ pre(:/) { |x| if x.infinte?||x.nan? then !self.real.is_a?(BigDecimal) && !self.imaginary.is_a?(BigDecimal) else true end}
43
+ type :/, '(Rational x {{ x!=0 }}) -> Complex'
44
+ type :/, '(BigDecimal x {{ x!=0 }}) -> Complex'
45
+ pre(:/) { |x| if self.real.is_a?(Float) then !self.real.infinite? && !self.real.nan? else true end && if self.imaginary.is_a?(Float) then !self.imaginary.infinite? && !self.imaginary.nan? else true end}
46
+ type :/, '(Complex x {{ x!=0 }}) -> Complex'
47
+ pre(:/) { |x| if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal) || self.real.is_a?(BigDecimal) || self.imaginary .is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) && if self.real.is_a?(Float) then !self.real.infinite? && !self.real.nan? else true end && if self.imaginary.is_a?(Float) then !self.imaginary.infinite? && !self.imaginary.nan? else true end else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
51
48
 
52
49
  type:==, '(Object) -> %bool'
53
50
 
54
- type :abs, '() -> Numeric'
55
- post(:abs) { |r,x| r >= 0 }
51
+ type :abs, '() -> %numeric r {{ r>=0 }}'
56
52
 
57
- type :abs2, '() -> Numeric'
58
- post(:abs2) { |r,x| r >= 0 }
53
+ type :abs2, '() -> %numeric r {{ r>=0 }}'
59
54
 
60
55
  type :angle, '() -> Float'
61
56
 
@@ -64,16 +59,16 @@ class Complex < Numeric
64
59
  type :conj, '() -> Complex'
65
60
  type :conjugate, '() -> Complex'
66
61
 
67
- type :denominator, '() -> Integer'
62
+ type :denominator, '() -> %integer'
68
63
 
69
64
  type :equal?, '(Object) -> %bool'
70
65
  type :eql?, '(Object) -> %bool'
71
66
 
72
- type :fdiv, '(Numeric) -> Complex'
67
+ type :fdiv, '(%numeric) -> Complex'
73
68
  pre(:fdiv) { |x| if (self.real.is_a?(Float) && (self.real.infinite? || self.real.nan?))||(self.imaginary.is_a?(Float) && (self.imaginary.infinite? || self.imaginary.nan?)) then !x.is_a?(BigDecimal) && (if x.is_a?(Complex) then !x.real.is_a?(BigDecimal) && !x.imaginary.is_a?(BigDecimal) else true end) else true end}
74
69
 
75
- type :hash, '() -> Integer'
76
-
70
+ type :hash, '() -> %integer'
71
+
77
72
  type :imag, '() -> %real'
78
73
  type :imaginary, '() -> %real'
79
74
 
@@ -85,29 +80,27 @@ class Complex < Numeric
85
80
 
86
81
  type :phase, '() -> Float'
87
82
 
88
- type :polar, '() -> [%real, %real]'
83
+ type :polar, '() -> [%real, %real]'
89
84
 
90
85
 
91
- type :quo, '(Integer) -> Complex'
92
- pre(:quo) { |x| x!=0}
93
- type :quo, '(Float) -> Complex'
94
- pre(:quo) { |x| x!=0 && if self.real.is_a?(BigDecimal)||self.imaginary.is_a?(BigDecimal) then !x.infinite? && !x.nan? else true end}
95
- type :quo, '(Rational) -> Complex'
96
- pre(:quo) { |x| x!=0}
97
- type :quo, '(BigDecimal) -> BigDecimal'
98
- pre(:quo) { |x| x!=0 && if self.real.is_a?(Float) then !self.real.infinite?&&!self.real.nan? else true end && if self.imaginary.is_a?(Float) then !self.imaginary.infinite? && !self.imaginary.nan? else true end}
99
- type :quo, '(Complex) -> Complex'
100
- pre(:quo) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal) || self.real.is_a?(BigDecimal) || self.imaginary .is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) && if self.real.is_a?(Float) then !self.real.infinite? && !self.real.nan? else true end && if self.imaginary.is_a?(Float) then !self.imaginary.infinite? && !self.imaginary.nan? else true end else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
86
+ type :quo, '(%integer x {{ x!=0 }}) -> Complex'
87
+ type :quo, '(Float x {{ x!=0 }}) -> Complex'
88
+ pre(:quo) { |x| if self.real.is_a?(BigDecimal)||self.imaginary.is_a?(BigDecimal) then !x.infinite? && !x.nan? else true end}
89
+ type :quo, '(Rational x {{ x!=0 }}) -> Complex'
90
+ type :quo, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
91
+ pre(:quo) { |x| if self.real.is_a?(Float) then !self.real.infinite?&&!self.real.nan? else true end && if self.imaginary.is_a?(Float) then !self.imaginary.infinite? && !self.imaginary.nan? else true end}
92
+ type :quo, '(Complex x {{ x!=0 }}) -> Complex'
93
+ pre(:quo) { |x| if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal) || self.real.is_a?(BigDecimal) || self.imaginary .is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) && if self.real.is_a?(Float) then !self.real.infinite? && !self.real.nan? else true end && if self.imaginary.is_a?(Float) then !self.imaginary.infinite? && !self.imaginary.nan? else true end else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
101
94
 
102
95
  type :rationalize, '() -> Rational'
103
96
  pre(:rationalize) { self.imaginary==0 && if self.real.is_a?(Float)||self.real.is_a?(BigDecimal) then !self.real.infinite? && !self.real.nan? else true end}
104
97
 
105
- type :rationalize, '(Numeric) -> Rational'
98
+ type :rationalize, '(%numeric) -> Rational'
106
99
  pre(:rationalize) { |x| self.imaginary==0 && if self.real.is_a?(Float)||self.real.is_a?(Rational) then (if x.is_a?(Float)||x.is_a?(BigDecimal) then !x.infinite? && !x.nan? else true end) else true end && if self.real.is_a?(Float)||self.real.is_a?(BigDecimal) then !self.real.infinite? && !self.real.nan? else true end}
107
100
 
108
101
  type :real, '() -> %real'
109
102
 
110
- type :real?, '() -> FalseClass'
103
+ type :real?, '() -> false'
111
104
 
112
105
  type :rect, '() -> [%real, %real]'
113
106
  type :rectangular, '() -> [%real, %real]'
@@ -117,7 +110,7 @@ class Complex < Numeric
117
110
  type :to_f, '() -> Float'
118
111
  pre(:to_f) { self.imaginary==0}
119
112
 
120
- type :to_i, '() -> Integer'
113
+ type :to_i, '() -> %integer'
121
114
  pre(:to_i) { self.imaginary==0 && if self.real.is_a?(Float)||self.real.is_a?(BigDecimal) then !self.real.infinite? && !self.real.nan? else true end}
122
115
 
123
116
  type :to_r, '() -> Rational'
@@ -127,5 +120,5 @@ class Complex < Numeric
127
120
 
128
121
  type :zero?, '() -> %bool'
129
122
 
130
- type :coerce, '(Numeric) -> [Complex, Complex]'
123
+ type :coerce, '(%numeric) -> [Complex, Complex]'
131
124
  end