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.
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,42 +1,37 @@
1
1
  class Fixnum < 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 :*, '(Integer) -> 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 :*, '(%integer) -> %integer'
18
13
  type :*, '(Float) -> Float'
19
14
  type :*, '(Rational) -> Rational'
20
15
  type :*, '(BigDecimal) -> BigDecimal'
21
16
  type :*, '(Complex) -> Complex'
22
17
  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
23
18
 
24
- type :**, '(Integer) -> Numeric'
25
- type :**, '(Float) -> Numeric'
26
- type :**, '(Rational) -> Numeric'
19
+ type :**, '(%integer) -> %numeric'
20
+ type :**, '(Float) -> %numeric'
21
+ type :**, '(Rational) -> %numeric'
27
22
  type :**, '(BigDecimal) -> BigDecimal'
28
23
  pre(:**) { |x| x!=BigDecimal::INFINITY && if self<0 then x<=-1||x>=0 else true end}
29
24
  post(:**) { |r,x| r.real?}
30
25
  type :**, '(Complex) -> Complex'
31
26
  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}
32
27
 
33
- type :+, '(Integer) -> Integer'
28
+ type :+, '(%integer) -> %integer'
34
29
  type :+, '(Float) -> Float'
35
30
  type :+, '(Rational) -> Rational'
36
31
  type :+, '(BigDecimal) -> BigDecimal'
37
32
  type :+, '(Complex) -> Complex'
38
33
 
39
- type :-, '(Integer) -> Integer'
34
+ type :-, '(%integer) -> %integer'
40
35
  type :-, '(Float) -> Float'
41
36
  type :-, '(Rational) -> Rational'
42
37
  type :-, '(BigDecimal) -> BigDecimal'
@@ -44,30 +39,26 @@ class Fixnum < Integer
44
39
 
45
40
  type :-, '() -> Fixnum'
46
41
 
47
- type :/, '(Integer) -> Integer'
48
- pre(:/) { |x| x!=0}
49
- type :/, '(Float) -> Float'
50
- pre(:/) { |x| x!=0}
51
- type :/, '(Rational) -> Rational'
52
- pre(:/) { |x| x!=0}
53
- type :/, '(BigDecimal) -> BigDecimal'
54
- pre(:/) { |x| x!=0}
55
- type :/, '(Complex) -> Complex'
56
- 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}
57
-
58
- type :<, '(Integer) -> %bool'
42
+ type :/, '(%integer x {{ x!=0 }}) -> %integer'
43
+ type :/, '(Float x {{ x!=0 }}) -> Float'
44
+ type :/, '(Rational x {{ x!=0 }}) -> Rational'
45
+ type :/, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
46
+ type :/, '(Complex x {{ x!=0 }}) -> Complex'
47
+ pre(:/) { 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}
48
+
49
+ type :<, '(%integer) -> %bool'
59
50
  type :<, '(Float) -> %bool'
60
51
  type :<, '(Rational) -> %bool'
61
52
  type :<, '(BigDecimal) -> %bool'
62
53
 
63
- type :<<, '(Fixnum) -> Integer' #must be below a certain amount, not exactly sure what amount
54
+ type :<<, '(Fixnum) -> %integer'
64
55
 
65
- type :<=, '(Integer) -> %bool'
56
+ type :<=, '(%integer) -> %bool'
66
57
  type :<=, '(Float) -> %bool'
67
58
  type :<=, '(Rational) -> %bool'
68
59
  type :<=, '(BigDecimal) -> %bool'
69
60
 
70
- type :<=>, '(Integer) -> Object'
61
+ type :<=>, '(%integer) -> Object'
71
62
  post(:<=>) { |r,x| r == -1 || r==0 || r==1}
72
63
  type :<=>, '(Float) -> Object'
73
64
  post(:<=>) { |r,x| r == -1 || r==0 || r==1}
@@ -80,20 +71,20 @@ class Fixnum < Integer
80
71
 
81
72
  type :===, '(Object) -> %bool'
82
73
 
83
- type :>, '(Integer) -> %bool'
74
+ type :>, '(%integer) -> %bool'
84
75
  type :>, '(Float) -> %bool'
85
76
  type :>, '(Rational) -> %bool'
86
77
  type :>, '(BigDecimal) -> %bool'
87
78
 
88
- type :>=, '(Integer) -> %bool'
79
+ type :>=, '(%integer) -> %bool'
89
80
  type :>=, '(Float) -> %bool'
90
81
  type :>=, '(Rational) -> %bool'
91
82
  type :>=, '(BigDecimal) -> %bool'
92
83
 
93
- type :>>, '(Integer) -> Integer'
84
+ type :>>, '(%integer) -> %integer'
94
85
  post(:>>) { |r,x| r >= 0 }
95
86
 
96
- type :[], '(Integer) -> Fixnum'
87
+ type :[], '(%integer) -> Fixnum'
97
88
  post(:[]) { |r,x| r == 0 || r==1}
98
89
  type :[], '(Rational) -> Fixnum'
99
90
  post(:[]) { |r,x| r == 0 || r==1}
@@ -104,149 +95,119 @@ class Fixnum < Integer
104
95
  pre(:[]) { |x| x!=BigDecimal::INFINITY && !x.nan? }
105
96
  post(:[]) { |r,x| r == 0 || r==1}
106
97
 
107
- type :^, '(Integer) -> Integer'
98
+ type :^, '(%integer) -> %integer'
108
99
 
109
- type :|, '(Integer) -> Integer'
100
+ type :|, '(%integer) -> %integer'
110
101
 
111
102
  type :~, '() -> Fixnum'
112
103
 
113
- type :abs, '() -> Integer'
114
- post(:abs) { |r,x| r >= 0 }
104
+ type :abs, '() -> %integer r {{ r>=0 }}'
115
105
 
116
- type :bit_length, '() -> Fixnum'
117
- post(:bit_length) { |r,x| r >= 0 }
106
+ type :bit_length, '() -> Fixnum r {{ r>=0 }}'
118
107
 
119
- type :div, '(Fixnum) -> Integer'
120
- pre(:div) { |x| x!=0}
121
- type :div, '(Bignum) -> Fixnum'
122
- pre(:div) { |x| x!=0}
123
- type :div, '(Float) -> Integer'
124
- pre(:div) { |x| x!=0 && !x.nan?}
125
- type :div, '(Rational) -> Integer'
126
- pre(:div) { |x| x!=0}
127
- type :div, '(BigDecimal) -> Integer'
128
- pre(:div) { |x| x!=0 && !x.nan?}
108
+ type :div, '(Fixnum x {{ x!=0 }}) -> %integer'
109
+ type :div, '(Bignum x {{ x!=0 }}) -> Fixnum'
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'
129
113
 
130
- type :divmod, '(%real) -> [%real, %real]'
131
- pre(:divmod) { |x| x!=0 && if x.is_a?(Float) then !x.nan? else true end}
114
+ type :divmod, '(%real x {{ x!=0 }}) -> [%real, %real]'
115
+ pre(:divmod) { |x| if x.is_a?(Float) then !x.nan? else true end}
132
116
 
133
117
  type :even?, '() -> %bool'
134
118
 
135
- type :fdiv, '(Integer) -> Float'
119
+ type :fdiv, '(%integer) -> Float'
136
120
  type :fdiv, '(Float) -> Float'
137
121
  type :fdiv, '(Rational) -> Float'
138
122
  type :fdiv, '(BigDecimal) -> BigDecimal'
139
123
  type :fdiv, '(Complex) -> Complex'
140
- 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}
141
125
 
142
126
  type :to_s, '() -> String'
143
127
  type :inspect, '() -> String'
144
128
 
145
- type :magnitude, '() -> Integer'
146
- post(:magnitude) { |r,x| r >= 0 }
129
+ type :magnitude, '() -> %integer r {{ r>=0 }}'
147
130
 
148
- type :modulo, '(Fixnum) -> Fixnum'
149
- pre(:modulo) { |x| x!=0}
150
- type :modulo, '(Bignum) -> Integer'
151
- pre(:modulo) { |x| x!=0}
152
- type :modulo, '(Float) -> Float'
153
- pre(:modulo) { |x| x!=0}
154
- type :modulo, '(Rational) -> Rational'
155
- pre(:modulo) { |x| x!=0}
156
- type :modulo, '(BigDecimal) -> BigDecimal'
157
- pre(:modulo) { |x| x!=0}
131
+ type :modulo, '(Fixnum x {{ x!=0 }}) -> Fixnum'
132
+ type :modulo, '(Bignum x {{ x!=0 }}) -> %integer'
133
+ type :modulo, '(Float x {{ x!=0 }}) -> Float'
134
+ type :modulo, '(Rational x {{ x!=0 }}) -> Rational'
135
+ type :modulo, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
158
136
 
159
- type :next, '() -> Integer'
137
+ type :next, '() -> %integer'
160
138
 
161
139
  type :odd?, '() -> %bool'
162
140
 
163
141
  type :size, '() -> Fixnum'
164
142
 
165
- type :succ, '() -> Integer'
143
+ type :succ, '() -> %integer'
166
144
 
167
145
  type :to_f, '() -> Float'
168
146
 
169
147
  type :zero?, '() -> %bool'
170
148
 
171
- type :ceil, '() -> Integer'
149
+ type :ceil, '() -> %integer'
172
150
 
173
- type :denominator, '() -> Fixnum'
174
- post(:denominator) { |r,x| r == 1 }
151
+ type :denominator, '() -> Fixnum r {{ r==1 }}'
175
152
 
176
- type :floor, '() -> Integer'
153
+ type :floor, '() -> %integer'
177
154
  type :numerator, '() -> Fixnum'
178
155
 
179
- type :quo, '(Integer) -> Rational'
180
- pre(:quo) { |x| x!=0}
181
- type :quo, '(Float) -> Float'
182
- pre(:quo) { |x| x!=0}
183
- type :quo, '(Rational) -> Rational'
184
- pre(:quo) { |x| x!=0}
185
- type :quo, '(BigDecimal) -> BigDecimal'
186
- pre(:quo) { |x| x!=0}
187
- type :quo, '(Complex) -> Complex'
188
- 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}
156
+ type :quo, '(%integer x {{ x!=0 }}) -> Rational'
157
+ type :quo, '(Float x {{ x!=0 }}) -> Float'
158
+ type :quo, '(Rational x {{ x!=0 }}) -> Rational'
159
+ type :quo, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
160
+ type :quo, '(Complex x {{ x!=0 }}) -> Complex'
161
+ pre(:quo) { |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}
189
162
 
190
163
  type :rationalize, '() -> Rational'
191
164
 
192
- type :rationalize, '(Numeric) -> Rational'
165
+ type :rationalize, '(%numeric) -> Rational'
193
166
 
194
- type :round, '() -> Integer'
167
+ type :round, '() -> %integer'
195
168
 
196
- type :round, '(Numeric) -> Numeric'
169
+ type :round, '(%numeric) -> %numeric'
197
170
  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].
198
171
 
199
172
  type :to_i, '() -> Fixnum'
200
173
 
201
174
  type :to_r, '() -> Rational'
202
175
 
203
- type :truncate, '() -> Integer'
176
+ type :truncate, '() -> %integer'
204
177
 
205
- type :angle, '() -> Numeric'
178
+ type :angle, '() -> %numeric'
206
179
  post(:angle) { |r,x| r == 0 || r == Math::PI}
207
180
 
208
- type :arg, '() -> Numeric'
181
+ type :arg, '() -> %numeric'
209
182
  post(:arg) { |r,x| r == 0 || r == Math::PI}
210
183
 
211
184
  type :equal?, '(Object) -> %bool'
212
185
  type :eql?, '(Object) -> %bool'
213
186
 
214
- type :hash, '() -> Integer'
187
+ type :hash, '() -> %integer'
215
188
 
216
- type :phase, '() -> Numeric'
189
+ type :phase, '() -> %numeric'
217
190
 
218
- type :abs2, '() -> Integer'
219
- post(:abs2) { |r,x| r >= 0 }
191
+ type :abs2, '() -> %integer r {{ r>=0}}'
220
192
 
221
193
  type :conj, '() -> Fixnum'
222
194
  type :conjugate, '() -> Fixnum'
223
195
 
224
- type :imag, '() -> Fixnum'
225
- post(:imag) { |r,x| r == 0 }
226
- type :imaginary, '() -> Fixnum'
227
- post(:imaginary) { |r,x| r == 0 }
196
+ type :imag, '() -> Fixnum r {{ r==0 }}'
197
+ type :imaginary, '() -> Fixnum r {{ r==0 }}'
228
198
 
229
199
  type :real, '() -> Fixnum'
230
200
 
231
- type :real?, '() -> TrueClass'
232
-
233
- type :to_c, '() -> Complex'
234
- post(:to_c) { |r,x| r.imaginary == 0 }
235
-
236
- type :remainder, '(Fixnum) -> Fixnum'
237
- pre(:remainder) { |x| x!=0}
238
- post(:remainder) { |r,x| r>0}
239
- type :remainder, '(Bignum) -> Fixnum'
240
- pre(:remainder) { |x| x!=0}
241
- post(:remainder) { |r,x| r>0}
242
- type :remainder, '(Float) -> Float'
243
- pre(:remainder) { |x| x!=0}
244
- type :remainder, '(Rational) -> Rational'
245
- pre(:remainder) { |x| x!=0}
246
- post(:remainder) { |r,x| r>0}
247
- type :remainder, '(BigDecimal) -> BigDecimal'
248
- pre(:remainder) { |x| x!=0}
249
-
250
- type :coerce, '(Numeric) -> [%real, %real]'
201
+ type :real?, '() -> true'
202
+
203
+ type :to_c, '() -> Complex r {{ r.imaginary == 0 }}'
204
+
205
+ type :remainder, '(Fixnum x {{ x!=0 }}) -> Fixnum r {{ r>0 }}'
206
+ type :remainder, '(Bignum x {{ x!=0 }}) -> Fixnum r {{ r>0 }}'
207
+ type :remainder, '(Float x {{ x!=0 }}) -> Float'
208
+ type :remainder, '(Rational x {{ x!=0 }}) -> Rational r {{ r>0 }}'
209
+ type :remainder, '(BigDecimal x {{ x=0 }}) -> BigDecimal'
210
+
211
+ type :coerce, '(%numeric) -> [%real, %real]'
251
212
  pre(:coerce) { |x| if x.is_a?(Complex) then x.imaginary==0 else true end}
252
213
  end
@@ -1,81 +1,67 @@
1
1
  class Float < Numeric
2
2
  rdl_nowrap
3
3
 
4
- type :%, '(Integer) -> Float'
5
- pre(:%) { |x| x!=0}
6
- type :%, '(Float) -> Float'
7
- pre(:%) { |x| x!=0}
8
- type :%, '(Rational) -> Float'
9
- pre(:%) { |x| x!=0}
10
- type :%, '(BigDecimal) -> BigDecimal'
11
- pre(:%) { |x| x!=0 && self !=Float::INFINITY && !self.nan?}
12
-
13
- type :*, '(Integer) -> Float'
4
+ type :%, '(%integer x {{ x!=0 }}) -> Float'
5
+ type :%, '(Float x {{ x!=0 }}) -> Float'
6
+ type :%, '(Rational x {{ x!=0 }}) -> Float'
7
+ type :%, '(BigDecimal x {{ x!=0 && !self.infinite? && !self.nan? }}) -> BigDecimal'
8
+
9
+ type :*, '(%integer) -> Float'
14
10
  type :*, '(Float) -> Float'
15
11
  type :*, '(Rational) -> Float'
16
- type :*, '(BigDecimal) -> BigDecimal'
17
- pre(:*) { self!=Float::INFINITY && !(self.nan?)}
12
+ type :*, '(BigDecimal x {{ !self.infinite? && !self.nan? }}) -> BigDecimal'
18
13
  type :*, '(Complex) -> Complex'
19
14
  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) && self!=Float::INFINITY && !(self.nan?) else true end} #can't have a complex with part BigDecimal, other part infinity/NAN
20
15
 
21
- type :**, '(Integer) -> Float'
22
- type :**, '(Float) -> Numeric'
23
- type :**, '(Rational) -> Numeric'
16
+ type :**, '(%integer) -> Float'
17
+ type :**, '(Float) -> %numeric'
18
+ type :**, '(Rational) -> %numeric'
24
19
  type :**, '(BigDecimal) -> BigDecimal'
25
20
  pre(:**) { |x| x!=BigDecimal::INFINITY && if self<0 then x<=-1||x>=0 else true end}
26
21
  post(:**) { |x| x.real?}
27
22
  type :**, '(Complex) -> Complex'
28
23
  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) && self!=Float::INFINITY && !(self.nan?) else true end}
29
24
 
30
- type :+, '(Integer) -> Float'
25
+ type :+, '(%integer) -> Float'
31
26
  type :+, '(Float) -> Float'
32
27
  type :+, '(Rational) -> Float'
33
- type :+, '(BigDecimal) -> BigDecimal'
34
- pre(:+) { self!=Float::INFINITY && !(self.nan?)}
28
+ type :+, '(BigDecimal x {{ !self.infinite? && !self.nan? }}) -> BigDecimal'
35
29
  type :+, '(Complex) -> Complex'
36
30
  pre(:+) { |x| if x.real.is_a?(BigDecimal) then self!=Float::INFINITY && !(self.nan?) else true end}
37
31
 
38
- type :-, '(Integer) -> Float'
32
+ type :-, '(%integer) -> Float'
39
33
  type :-, '(Float) -> Float'
40
34
  type :-, '(Rational) -> Float'
41
- type :-, '(BigDecimal) -> BigDecimal'
42
- pre(:-) { self!=Float::INFINITY && !(self.nan?)}
35
+ type :-, '(BigDecimal x {{ !self.infinite? && !self.nan? }}) -> BigDecimal'
43
36
  type :-, '(Complex) -> Complex'
44
37
  pre(:-) { |x| if x.real.is_a?(BigDecimal) then self!=Float::INFINITY && !(self.nan?) else true end}
45
38
 
46
39
  type :-, '() -> Float'
47
40
 
48
- type :/, '(Integer) -> Float'
49
- pre(:/) { |x| x!=0}
50
- type :/, '(Float) -> Float'
51
- pre(:/) { |x| x!=0}
52
- type :/, '(Rational) -> Float'
53
- pre(:/) { |x| x!=0}
54
- type :/, '(BigDecimal) -> BigDecimal'
55
- pre(:/) { |x| x!=0 && self!=Float::INFINITY && !self.nan?}
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) && self!=Float::INFINITY && !(self.nan?) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
58
-
59
- type :<, '(Integer) -> %bool'
41
+ type :/, '(%integer x {{ x!=0 }}) -> Float'
42
+ type :/, '(Float x {{ x!=0 }}) -> Float'
43
+ type :/, '(Rational x {{ x!=0 }}) -> Float'
44
+ type :/, '(BigDecimal x {{ x!=0 && !self.infinite? && !self.nan? }}) -> BigDecimal'
45
+ type :/, '(Complex x {{ x!=0 }}) -> Complex'
46
+ 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) && self!=Float::INFINITY && !(self.nan?) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
47
+
48
+ type :<, '(%integer) -> %bool'
60
49
  type :<, '(Float) -> %bool'
61
50
  type :<, '(Rational) -> %bool'
62
- type :<, '(BigDecimal) -> %bool'
63
- pre(:<) { !self.nan? && self!=Float::INFINITY}
51
+ type :<, '(BigDecimal x {{ !self.nan? && !self.infinite? }}) -> %bool'
64
52
 
65
- type :<=, '(Integer) -> %bool'
53
+ type :<=, '(%integer) -> %bool'
66
54
  type :<=, '(Float) -> %bool'
67
55
  type :<=, '(Rational) -> %bool'
68
- type :<=, '(BigDecimal) -> %bool'
69
- pre(:<=) { !self.nan? && self!=Float::INFINITY}
56
+ type :<=, '(BigDecimal x {{ !self.nan? && !self.infinite? }}) -> %bool'
70
57
 
71
- type :<=>, '(Integer) -> Object'
58
+ type :<=>, '(%integer) -> Object'
72
59
  post(:<=>) { |x| x == -1 || x==0 || x==1}
73
60
  type :<=>, '(Float) -> Object'
74
61
  post(:<=>) { |x| x == -1 || x==0 || x==1}
75
62
  type :<=>, '(Rational) -> Object'
76
63
  post(:<=>) { |x| x == -1 || x==0 || x==1}
77
- type :<=>, '(BigDecimal) -> Object'
78
- pre(:<=>) { !self.nan? && self!=Float::INFINITY}
64
+ type :<=>, '(BigDecimal x {{ !self.infinite? && !self.nan? }}) -> Object'
79
65
  post(:<=>) { |x| x == -1 || x==0 || x==1}
80
66
 
81
67
  type :==, '(Object) -> %bool'
@@ -84,70 +70,58 @@ class Float < Numeric
84
70
  type :===, '(Object) -> %bool'
85
71
  pre(:===) { |x| if (x.is_a?(BigDecimal)) then (!self.nan? && self!=Float::INFINITY) else true end}
86
72
 
87
- type :>, '(Integer) -> %bool'
73
+ type :>, '(%integer) -> %bool'
88
74
  type :>, '(Float) -> %bool'
89
75
  type :>, '(Rational) -> %bool'
90
- type :>, '(BigDecimal) -> %bool'
91
- pre(:>) { !self.nan? && self!=Float::INFINITY}
76
+ type :>, '(BigDecimal x {{ !self.infinite? && !self.nan? }}) -> %bool'
92
77
 
93
- type :>=, '(Integer) -> %bool'
78
+ type :>=, '(%integer) -> %bool'
94
79
  type :>=, '(Float) -> %bool'
95
80
  type :>=, '(Rational) -> %bool'
96
- type :>=, '(BigDecimal) -> %bool'
97
- pre(:>=) { !self.nan? && self!=Float::INFINITY}
98
-
99
- type :abs, '() -> Float'
100
- post(:abs) { |x| x >= 0 }
101
-
102
- type :abs2, '() -> Float'
103
- post(:abs2) { |x| x >= 0 }
104
-
105
- type :div, '(Fixnum) -> Integer'
106
- pre(:div) { |x| x!=0 && self!=Float::INFINITY && !self.nan?}
107
- type :div, '(Bignum) -> Integer'
108
- pre(:div) { |x| x!=0 && self!=Float::INFINITY && !self.nan?}
109
- type :div, '(Float) -> Integer'
110
- pre(:div) { |x| x!=0 && self!=Float::INFINITY && !self.nan?}
111
- type :div, '(Rational) -> Integer'
112
- pre(:div) { |x| x!=0 && self!=Float::INFINITY && !self.nan?}
113
- type :div, '(BigDecimal) -> Integer'
114
- pre(:div) { |x| x!=0 && !x.nan? && self!=Float::INFINITY && !self.nan?}
81
+ type :>=, '(BigDecimal x {{ !self.infinite? && !self.nan? }}) -> %bool'
82
+
83
+ type :abs, '() -> Float r {{ r>=0 }}'
84
+
85
+ type :abs2, '() -> Float r {{ r>=0 }}'
86
+
87
+ type :div, '(%integer x {{ x!=0 && !self.infinite? && !self.nan? }}) -> %integer'
88
+ type :div, '(Float x {{ x!=0 && !self.infinite? && !self.nan? }}) -> %integer'
89
+ type :div, '(Rational x {{ x!=0 && !self.infinite? && !self.nan? }}) -> %integer'
90
+ type :div, '(BigDecimal x {{ x!=0 && !x.nan? && !self.infinite? && !self.nan? }}) -> %integer'
115
91
 
116
92
  type :divmod, '(%real) -> [%real, %real]'
117
93
  pre(:divmod) { |x| x!=0 && if x.is_a?(Float) then !x.nan? else true end && self!=Float::INFINITY && !self.nan?}
118
94
 
119
- type :angle, '() -> Numeric'
95
+ type :angle, '() -> %numeric'
120
96
  post(:angle) { |r,x| r == 0 || r == Math::PI || r == Float::NAN}
121
97
 
122
- type :arg, '() -> Numeric'
98
+ type :arg, '() -> %numeric'
123
99
  post(:arg) { |r,x| r == 0 || r == Math::PI || r == Float::NAN}
124
100
 
125
- type :ceil, '() -> Integer'
126
- pre(:ceil) { self!=Float::INFINITY && !self.nan?}
101
+ type :ceil, '() -> %integer'
102
+ pre(:ceil) { !self.infinite? && !self.nan?}
127
103
 
128
104
  type :coerce, '(%real) -> [Float, Float]'
129
105
 
130
- type :denominator, '() -> Integer'
131
- post(:denominator) { |r,x| r > 0 }
106
+ type :denominator, '() -> %integer r {{ r>0 }}'
132
107
 
133
108
  type :equal?, '(Object) -> %bool'
134
109
 
135
- type :eql?, '(Object) -> %bool'
110
+ type :eql?, '(Object) -> %bool'
136
111
 
137
- type :fdiv, '(Integer) -> Float'
112
+ type :fdiv, '(%integer) -> Float'
138
113
  type :fdiv, '(Float) -> Float'
139
114
  type :fdiv, '(Rational) -> Float'
140
- type :fdiv, '(BigDecimal) -> BigDecimal'
141
- pre(:fdiv) { self!=Float::INFINITY && !self.nan?}
115
+ type :fdiv, '(BigDecimal x {{ !self.infinite? && !self.nan? }}) -> BigDecimal'
142
116
  type :fdiv, '(Complex) -> Complex'
143
117
  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) && self!=Float::INFINITY && !(self.nan?) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
144
118
 
145
119
  type :finite?, '() -> %bool'
146
120
 
147
- type :floor, '() -> Integer'
148
- pre(:ceil) { self!=Float::INFINITY && !self.nan?}
121
+ type :floor, '() -> %integer'
122
+ pre(:ceil) { !self.infinite? && !self.nan?}
149
123
 
150
- type :hash, '() -> Integer'
124
+ type :hash, '() -> %integer'
151
125
 
152
126
  type :infinite?, '() -> Object'
153
127
  post(:infinite?) { |r,x| r == -1 || r == 1 || r == nil }
@@ -158,79 +132,68 @@ class Float < Numeric
158
132
  type :magnitude, '() -> Float'
159
133
  post(:magnitude) { |r,x| r>=0 }
160
134
 
161
- type :modulo, '(Integer) -> Float'
162
- pre(:modulo) { |x| x!=0}
163
- type :modulo, '(Float) -> Float'
164
- pre(:modulo) { |x| x!=0}
165
- type :modulo, '(Rational) -> Float'
166
- pre(:modulo) { |x| x!=0}
167
- type :modulo, '(BigDecimal) -> BigDecimal'
168
- pre(:modulo) { |x| x!=0 && self!=Float::INFINITY && !self.nan?}
135
+ type :modulo, '(%integer x {{ x!=0 }}) -> Float'
136
+ type :modulo, '(Float x {{ x!=0 }}) -> Float'
137
+ type :modulo, '(Rational x {{ x!=0 }}) -> Float'
138
+ type :modulo, '(BigDecimal x {{ x!=0 && !self.infinite? && !self.nan? }}) -> BigDecimal'
169
139
 
170
140
  type :nan?, '() -> %bool'
171
141
 
172
142
  type :next_float, '() -> Float'
173
143
 
174
- type :numerator, '() -> Integer'
144
+ type :numerator, '() -> %integer'
175
145
 
176
- type :phase, '() -> Numeric'
146
+ type :phase, '() -> %numeric'
177
147
  post(:phase) { |r,x| r == 0 || r == Math::PI || r == Float::NAN}
178
148
 
179
149
  type :prev_float, '() -> Float'
180
150
 
181
- type :quo, '(Integer) -> Float'
182
- pre(:quo) { |x| x!=0}
183
- type :quo, '(Float) -> Float'
184
- pre(:quo) { |x| x!=0}
185
- type :quo, '(Rational) -> Float'
186
- pre(:quo) { |x| x!=0}
187
- type :quo, '(BigDecimal) -> BigDecimal'
188
- pre(:quo) { |x| x!=0 && self!=Float::INFINITY && !self.nan?}
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) && self!=Float::INFINITY && !(self.nan?) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
151
+ type :quo, '(%integer x {{ x!=0 }}) -> Float'
152
+ type :quo, '(Float x {{ x!=0 }}) -> Float'
153
+ type :quo, '(Rational x {{ x!=0 }}) -> Float'
154
+ type :quo, '(BigDecimal x {{ x!=0 && !self.infinite? && !self.nan? }}) -> BigDecimal'
155
+ type :quo, '(Complex x {{ x!=0 }}) -> Complex'
156
+ pre(:quo) { |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) && self!=Float::INFINITY && !(self.nan?) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
191
157
 
192
158
  type :rationalize, '() -> Rational'
193
- pre(:rationalize) { self!=Float::INFINITY && !self.nan?}
159
+ pre(:rationalize) { !self.infinite? && !self.nan?}
194
160
 
195
- type :rationalize, '(Numeric) -> Rational'
161
+ type :rationalize, '(%numeric) -> Rational'
196
162
  pre(:rationalize) { |x| if x.is_a?(Float) then x!=Float::INFINITY && !x.nan? else true end}
197
163
 
198
- type :round, '() -> Integer'
199
- pre(:round) { self!=Float::INFINITY && !self.nan?}
164
+ type :round, '() -> %integer'
165
+ pre(:round) { !self.infinite? && !self.nan?}
200
166
 
201
- type :round, '(Numeric) -> Numeric'
167
+ type :round, '(%numeric) -> %numeric'
202
168
  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].
203
169
 
204
170
  type :to_f, '() -> Float'
205
171
 
206
- type :to_i, '() -> Integer'
207
- pre(:to_i) { self!=Float::INFINITY && !self.nan?}
172
+ type :to_i, '() -> %integer'
173
+ pre(:to_i) { !self.infinite? && !self.nan?}
208
174
 
209
- type :to_int, '() -> Integer'
210
- pre(:to_int) { self!=Float::INFINITY && !self.nan?}
175
+ type :to_int, '() -> %integer'
176
+ pre(:to_int) { !self.infinite? && !self.nan?}
211
177
 
212
178
  type :to_r, '() -> Rational'
213
- pre(:to_r) { self!=Float::INFINITY && !self.nan?}
179
+ pre(:to_r) { !self.infinite? && !self.nan?}
214
180
 
215
- type :truncate, '() -> Integer'
181
+ type :truncate, '() -> %integer'
216
182
 
217
183
  type :zero?, '() -> %bool'
218
184
 
219
185
  type :conj, '() -> Float'
220
186
  type :conjugate, '() -> Float'
221
187
 
222
- type :imag, '() -> Fixnum'
223
- post(:imag) { |r,x| r == 0 }
224
- type :imaginary, '() -> Fixnum'
225
- post(:imaginary) { |r,x| r == 0 }
188
+ type :imag, '() -> Fixnum r {{ r==0 }}'
189
+ type :imaginary, '() -> Fixnum r {{ r==0 }}'
226
190
 
227
191
  type :real, '() -> Float'
228
192
 
229
- type :real?, '() -> TrueClass'
193
+ type :real?, '() -> true'
230
194
 
231
- type :to_c, '() -> Complex'
232
- post(:to_c) { |r,x| r.imaginary == 0 }
195
+ type :to_c, '() -> Complex r {{ r.imaginary == 0 }}'
233
196
 
234
- type :coerce, '(Numeric) -> [Float, Float]'
197
+ type :coerce, '(%numeric) -> [Float, Float]'
235
198
  pre(:coerce) { |x| if x.is_a?(Complex) then x.imaginary==0 else true end}
236
199
  end