rdl 1.1.1 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/README.md +211 -32
- data/gemfiles/Gemfile.travis +1 -1
- data/lib/rdl.rb +85 -18
- data/lib/rdl/info.rb +74 -0
- data/lib/rdl/query.rb +8 -9
- data/lib/rdl/typecheck.rb +1057 -0
- data/lib/rdl/types/annotated_arg.rb +5 -5
- data/lib/rdl/types/{nil.rb → bot.rb} +9 -13
- data/lib/rdl/types/dependent_arg.rb +5 -5
- data/lib/rdl/types/dots_query.rb +2 -0
- data/lib/rdl/types/finitehash.rb +67 -24
- data/lib/rdl/types/generic.rb +13 -21
- data/lib/rdl/types/intersection.rb +9 -8
- data/lib/rdl/types/method.rb +30 -32
- data/lib/rdl/types/nominal.rb +22 -16
- data/lib/rdl/types/optional.rb +8 -22
- data/lib/rdl/types/parser.racc +8 -3
- data/lib/rdl/types/parser.tab.rb +131 -118
- data/lib/rdl/types/singleton.rb +15 -10
- data/lib/rdl/types/structural.rb +6 -6
- data/lib/rdl/types/top.rb +6 -6
- data/lib/rdl/types/tuple.rb +56 -24
- data/lib/rdl/types/type.rb +9 -0
- data/lib/rdl/types/type_inferencer.rb +1 -1
- data/lib/rdl/types/union.rb +52 -26
- data/lib/rdl/types/var.rb +7 -6
- data/lib/rdl/types/vararg.rb +5 -6
- data/lib/rdl/types/wild_query.rb +9 -2
- data/lib/rdl/util.rb +9 -7
- data/lib/rdl/wrap.rb +90 -72
- data/lib/rdl_types.rb +2 -2
- data/rdl.gemspec +6 -8
- data/test/test_alias.rb +4 -3
- data/test/test_contract.rb +5 -4
- data/test/test_dsl.rb +2 -1
- data/test/test_generic.rb +30 -26
- data/test/test_intersection.rb +3 -3
- data/test/test_le.rb +129 -61
- data/test/test_lib_types.rb +3 -2
- data/test/test_member.rb +33 -46
- data/test/test_parser.rb +113 -116
- data/test/test_query.rb +2 -1
- data/test/test_rdl.rb +64 -6
- data/test/test_rdl_type.rb +3 -2
- data/test/test_type_contract.rb +30 -12
- data/test/test_typecheck.rb +893 -0
- data/test/test_types.rb +50 -54
- data/test/test_wrap.rb +2 -1
- data/types/ruby-2.x/_aliases.rb +13 -2
- data/types/ruby-2.x/bigdecimal.rb +60 -85
- data/types/ruby-2.x/bignum.rb +80 -119
- data/types/ruby-2.x/complex.rb +33 -40
- data/types/ruby-2.x/fixnum.rb +81 -120
- data/types/ruby-2.x/float.rb +79 -116
- data/types/ruby-2.x/integer.rb +187 -22
- data/types/ruby-2.x/nil.rb +12 -0
- data/types/ruby-2.x/numeric.rb +38 -38
- data/types/ruby-2.x/object.rb +3 -3
- data/types/ruby-2.x/random.rb +2 -0
- data/types/ruby-2.x/range.rb +20 -19
- data/types/ruby-2.x/rational.rb +40 -40
- data/types/ruby-2.x/regexp.rb +4 -4
- data/types/ruby-2.x/string.rb +15 -17
- metadata +17 -16
- data/lib/rdl/types/.#lexer.rex +0 -1
data/types/ruby-2.x/bignum.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
class Bignum < Integer
|
2
2
|
rdl_nowrap
|
3
3
|
|
4
|
-
type :%, '(Fixnum) -> Fixnum'
|
5
|
-
|
6
|
-
type :%, '(
|
7
|
-
|
8
|
-
type :%, '(
|
9
|
-
|
10
|
-
type
|
11
|
-
|
12
|
-
type
|
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 :**, '(
|
26
|
-
type :**, '(Float) ->
|
27
|
-
type :**, '(Rational) ->
|
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 :+, '(
|
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 :-, '(
|
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 :-, '() ->
|
41
|
+
type :-, '() -> %integer'
|
47
42
|
|
48
|
-
type :/, '(
|
49
|
-
|
50
|
-
type :/, '(
|
51
|
-
|
52
|
-
type :/, '(
|
53
|
-
pre(:/) { |x| x!=
|
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 :<, '(
|
50
|
+
type :<, '(%integer) -> %bool'
|
60
51
|
type :<, '(Float) -> %bool'
|
61
52
|
type :<, '(Rational) -> %bool'
|
62
53
|
type :<, '(BigDecimal) -> %bool'
|
63
54
|
|
64
|
-
type :<<, '(Fixnum) ->
|
55
|
+
type :<<, '(Fixnum) -> %integer'
|
65
56
|
|
66
|
-
type :<=, '(
|
57
|
+
type :<=, '(%integer) -> %bool'
|
67
58
|
type :<=, '(Float) -> %bool'
|
68
59
|
type :<=, '(Rational) -> %bool'
|
69
60
|
type :<=, '(BigDecimal) -> %bool'
|
70
61
|
|
71
|
-
type :<=>, '(
|
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 :>, '(
|
75
|
+
type :>, '(%integer) -> %bool'
|
85
76
|
type :>, '(Float) -> %bool'
|
86
77
|
type :>, '(Rational) -> %bool'
|
87
78
|
type :>, '(BigDecimal) -> %bool'
|
88
79
|
|
89
|
-
type :>=, '(
|
80
|
+
type :>=, '(%integer) -> %bool'
|
90
81
|
type :>=, '(Float) -> %bool'
|
91
82
|
type :>=, '(Rational) -> %bool'
|
92
83
|
type :>=, '(BigDecimal) -> %bool'
|
93
84
|
|
94
|
-
type :>>, '(
|
85
|
+
type :>>, '(%integer) -> %integer'
|
95
86
|
post(:>>) { |r,x| r >= 0 }
|
96
87
|
|
97
|
-
type :[], '(
|
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 :^, '(
|
99
|
+
type :^, '(%integer) -> %integer'
|
109
100
|
|
110
|
-
type :|, '(
|
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, '() ->
|
118
|
-
post(:bit_length) { |r,x| r >= 0 }
|
107
|
+
type :bit_length, '() -> %integer r {{ r>=0 }}'
|
119
108
|
|
120
|
-
type :div, '(
|
121
|
-
|
122
|
-
type :div, '(
|
123
|
-
|
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, '(
|
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|
|
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
|
-
|
151
|
-
type :modulo, '(
|
152
|
-
|
153
|
-
type :modulo, '(
|
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, '() ->
|
138
|
+
type :next, '() -> %integer'
|
161
139
|
|
162
140
|
type :odd?, '() -> %bool'
|
163
141
|
|
164
|
-
type :size, '() ->
|
142
|
+
type :size, '() -> %integer'
|
165
143
|
|
166
|
-
type :succ, '() ->
|
144
|
+
type :succ, '() -> %integer'
|
167
145
|
|
168
146
|
type :to_f, '() -> Float'
|
169
147
|
|
170
148
|
type :zero?, '() -> %bool'
|
171
149
|
|
172
|
-
type :ceil, '() ->
|
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, '() ->
|
154
|
+
type :floor, '() -> %integer'
|
178
155
|
|
179
156
|
type :numerator, '() -> Bignum'
|
180
157
|
|
181
|
-
type :quo, '(
|
182
|
-
|
183
|
-
type :quo, '(
|
184
|
-
|
185
|
-
type :quo, '(
|
186
|
-
pre(:quo) {
|
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, '(
|
167
|
+
type :rationalize, '(%numeric) -> Rational'
|
195
168
|
|
196
|
-
type :round, '() ->
|
169
|
+
type :round, '() -> %integer'
|
197
170
|
|
198
|
-
type :round, '(
|
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, '() ->
|
178
|
+
type :truncate, '() -> %integer'
|
206
179
|
|
207
|
-
type :angle, '() ->
|
180
|
+
type :angle, '() -> %numeric'
|
208
181
|
post(:angle) { |r,x| r == 0 || r == Math::PI}
|
209
182
|
|
210
|
-
type :arg, '() ->
|
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, '() ->
|
189
|
+
type :hash, '() -> %integer'
|
217
190
|
|
218
|
-
type :phase, '() ->
|
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
|
-
|
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?, '() ->
|
234
|
-
|
235
|
-
type :to_c, '() -> Complex'
|
236
|
-
|
237
|
-
|
238
|
-
type :remainder, '(
|
239
|
-
|
240
|
-
|
241
|
-
type :remainder, '(
|
242
|
-
|
243
|
-
|
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
|
data/types/ruby-2.x/complex.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Complex < Numeric
|
2
2
|
rdl_nowrap
|
3
3
|
|
4
|
-
type :*, '(
|
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 :**, '(
|
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 :+, '(
|
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 :-, '(
|
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 :/, '(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
type :/, '(
|
46
|
-
pre(:/) { |x|
|
47
|
-
type :/, '(
|
48
|
-
pre(:/) { |x| x!=
|
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, '() ->
|
55
|
-
post(:abs) { |r,x| r >= 0 }
|
51
|
+
type :abs, '() -> %numeric r {{ r>=0 }}'
|
56
52
|
|
57
|
-
type :abs2, '() ->
|
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, '() ->
|
62
|
+
type :denominator, '() -> %integer'
|
68
63
|
|
69
64
|
type :equal?, '(Object) -> %bool'
|
70
65
|
type :eql?, '(Object) -> %bool'
|
71
66
|
|
72
|
-
type :fdiv, '(
|
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, '() ->
|
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, '(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
type :quo, '(
|
96
|
-
pre(:quo) { |x|
|
97
|
-
type :quo, '(
|
98
|
-
pre(:quo) { |x| x!=
|
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, '(
|
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?, '() ->
|
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, '() ->
|
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, '(
|
123
|
+
type :coerce, '(%numeric) -> [Complex, Complex]'
|
131
124
|
end
|