rdl 1.1.0 → 1.1.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGES.md +25 -0
- data/README.md +104 -64
- data/extras/type_tests/%.rb +171 -0
- data/extras/type_tests/&.rb +159 -0
- data/extras/type_tests/**.rb +222 -0
- data/extras/type_tests/*.rb +177 -0
- data/extras/type_tests/+.rb +170 -0
- data/extras/type_tests/-.rb +171 -0
- data/extras/type_tests/1scomp.rb +157 -0
- data/extras/type_tests/<.rb +170 -0
- data/extras/type_tests/<<.rb +159 -0
- data/extras/type_tests/>>.rb +159 -0
- data/extras/type_tests/[].rb +163 -0
- data/extras/type_tests/^.rb +159 -0
- data/extras/type_tests/abs.rb +155 -0
- data/extras/type_tests/abs2.rb +164 -0
- data/extras/type_tests/angle.rb +157 -0
- data/extras/type_tests/arg.rb +157 -0
- data/extras/type_tests/bit_length.rb +157 -0
- data/extras/type_tests/ceil.rb +157 -0
- data/extras/type_tests/ceilRational.rb +160 -0
- data/extras/type_tests/conj.rb +158 -0
- data/extras/type_tests/defwhere.rb +86 -0
- data/extras/type_tests/denominator.rb +157 -0
- data/extras/type_tests/div.rb +172 -0
- data/extras/type_tests/divslash.rb +179 -0
- data/extras/type_tests/even?.rb +157 -0
- data/extras/type_tests/fdiv.rb +244 -0
- data/extras/type_tests/finite?.rb +157 -0
- data/extras/type_tests/floor.rb +157 -0
- data/extras/type_tests/floorRational.rb +161 -0
- data/extras/type_tests/hash.rb +157 -0
- data/extras/type_tests/imag.rb +158 -0
- data/extras/type_tests/infinite?.rb +157 -0
- data/extras/type_tests/modulo.rb +171 -0
- data/extras/type_tests/nan?.rb +157 -0
- data/extras/type_tests/neg.rb +155 -0
- data/extras/type_tests/next.rb +157 -0
- data/extras/type_tests/next_float.rb +157 -0
- data/extras/type_tests/numerator.rb +157 -0
- data/extras/type_tests/phase.rb +157 -0
- data/extras/type_tests/prev_float.rb +157 -0
- data/extras/type_tests/quo.rb +179 -0
- data/extras/type_tests/rationalize.rb +157 -0
- data/extras/type_tests/rationalizeArg.rb +198 -0
- data/extras/type_tests/real.rb +157 -0
- data/extras/type_tests/real?.rb +157 -0
- data/extras/type_tests/round.rb +157 -0
- data/extras/type_tests/roundArg.rb +169 -0
- data/extras/type_tests/size.rb +157 -0
- data/extras/type_tests/to_c.rb +157 -0
- data/extras/type_tests/to_f.rb +155 -0
- data/extras/type_tests/to_i.rb +157 -0
- data/extras/type_tests/to_r.rb +157 -0
- data/extras/type_tests/to_s.rb +157 -0
- data/extras/type_tests/truncate.rb +157 -0
- data/extras/type_tests/truncateArg.rb +166 -0
- data/extras/type_tests/type tests +1 -0
- data/extras/type_tests/zero?.rb +155 -0
- data/extras/type_tests/|.rb +159 -0
- data/lib/rdl/contracts/and.rb +1 -1
- data/lib/rdl/contracts/flat.rb +2 -2
- data/lib/rdl/contracts/proc.rb +2 -1
- data/lib/rdl/types/.#lexer.rex +1 -0
- data/lib/rdl/types/dependent_arg.rb +47 -0
- data/lib/rdl/types/finitehash.rb +5 -5
- data/lib/rdl/types/generic.rb +3 -3
- data/lib/rdl/types/lexer.rex +5 -2
- data/lib/rdl/types/lexer.rex.rb +3 -0
- data/lib/rdl/types/method.rb +144 -15
- data/lib/rdl/types/nominal.rb +1 -1
- data/lib/rdl/types/parser.racc +6 -1
- data/lib/rdl/types/parser.tab.rb +272 -245
- data/lib/rdl/types/tuple.rb +1 -1
- data/lib/rdl/types/type_inferencer.rb +7 -7
- data/lib/rdl/wrap.rb +16 -11
- data/rdl.gemspec +3 -3
- data/test/test_dsl.rb +4 -5
- data/test/test_le.rb +5 -5
- data/test/test_lib_types.rb +34 -34
- data/test/test_member.rb +3 -3
- data/test/test_type_contract.rb +63 -1
- data/test/test_types.rb +2 -0
- data/types/ruby-2.x/_aliases.rb +2 -2
- data/types/ruby-2.x/bigdecimal.rb +246 -12
- data/types/ruby-2.x/bignum.rb +253 -0
- data/types/ruby-2.x/complex.rb +111 -22
- data/types/ruby-2.x/fixnum.rb +238 -31
- data/types/ruby-2.x/float.rb +217 -35
- data/types/ruby-2.x/integer.rb +17 -16
- data/types/ruby-2.x/numeric.rb +31 -21
- data/types/ruby-2.x/rational.rb +196 -18
- metadata +67 -4
data/test/test_types.rb
CHANGED
@@ -165,6 +165,7 @@ class TestTypes < Minitest::Test
|
|
165
165
|
toptionalA = OptionalType.new tA
|
166
166
|
tvarargA = VarargType.new tA
|
167
167
|
tannotatedA = AnnotatedArgType.new("arg", tA)
|
168
|
+
tdependentA = DependentArgType.new("arg", tA, "{{ arg > 10 }}")
|
168
169
|
tunionAB = UnionType.new(tA, tB)
|
169
170
|
tinterAB = IntersectionType.new(tA, tB)
|
170
171
|
tsyma = SingletonType.new(:a)
|
@@ -200,6 +201,7 @@ class TestTypes < Minitest::Test
|
|
200
201
|
assert_equal toptionalA, toptionalA.instantiate(inst)
|
201
202
|
assert_equal tvarargA, tvarargA.instantiate(inst)
|
202
203
|
assert_equal tannotatedA, tannotatedA.instantiate(inst)
|
204
|
+
assert_equal tdependentA, tdependentA.instantiate(inst)
|
203
205
|
assert_equal tunionAB, tunionAB.instantiate(inst)
|
204
206
|
assert_equal tinterAB, tinterAB.instantiate(inst)
|
205
207
|
assert_equal tsyma, tsyma.instantiate(inst)
|
data/types/ruby-2.x/_aliases.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
type_alias '%real', 'Integer or Float or Rational'
|
1
|
+
type_alias '%real', 'Integer or Float or Rational or BigDecimal'
|
2
2
|
type_alias '%string', '[to_str: () -> String]'
|
3
3
|
type_alias '%path', '%string or Pathname'
|
4
|
-
type_alias '%open_args', '{external_encoding: ?String, internal_encoding: ?String, encoding: ?String, textmode: ?%any, binmode: ?%any, autoclose: ?%any, mode: ?String}'
|
4
|
+
type_alias '%open_args', '{external_encoding: ?String, internal_encoding: ?String, encoding: ?String, textmode: ?%any, binmode: ?%any, autoclose: ?%any, mode: ?String}'
|
@@ -1,15 +1,249 @@
|
|
1
|
-
class BigDecimal
|
1
|
+
class BigDecimal < Numeric
|
2
2
|
rdl_nowrap
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
type
|
8
|
-
|
9
|
-
|
10
|
-
type
|
11
|
-
type
|
12
|
-
type
|
13
|
-
|
14
|
-
|
4
|
+
type :%, '(Numeric) -> BigDecimal'
|
5
|
+
pre(:%) { |x| x!=0&&(if x.is_a?(Float) then x!=Float::INFINITY && !x.nan? else true end)}
|
6
|
+
|
7
|
+
type :+, '(Integer) -> BigDecimal'
|
8
|
+
type :+, '(Float) -> BigDecimal'
|
9
|
+
pre(:+) { |x| x!=Float::INFINITY && !(x.nan?)}
|
10
|
+
type :+, '(Rational) -> BigDecimal'
|
11
|
+
type :+, '(BigDecimal) -> BigDecimal'
|
12
|
+
type :+, '(Complex) -> Complex'
|
13
|
+
pre(:+) { |x| if x.real.is_a?(Float) then x.real!=Float::INFINITY && !(x.real.nan?) else true end}
|
14
|
+
|
15
|
+
type :-, '(Integer) -> BigDecimal'
|
16
|
+
type :-, '(Float) -> BigDecimal'
|
17
|
+
pre(:-) { |x| x!=Float::INFINITY && !(x.nan?)}
|
18
|
+
type :-, '(Rational) -> BigDecimal'
|
19
|
+
type :-, '(BigDecimal) -> BigDecimal'
|
20
|
+
type :-, '(Complex) -> Complex'
|
21
|
+
pre(:-) { |x| if x.real.is_a?(Float) then x.real!=Float::INFINITY && !(x.real.nan?) else true end}
|
22
|
+
|
23
|
+
type :-, '() -> BigDecimal'
|
24
|
+
|
25
|
+
type :*, '(Integer) -> BigDecimal'
|
26
|
+
type :*, '(Float) -> BigDecimal'
|
27
|
+
pre(:*) { |x| x!=Float::INFINITY && !(x.nan?)}
|
28
|
+
type :*, '(Rational) -> BigDecimal'
|
29
|
+
type :*, '(BigDecimal) -> BigDecimal'
|
30
|
+
type :*, '(Complex) -> Complex'
|
31
|
+
pre(:*) { |x| 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}
|
32
|
+
|
33
|
+
type :**, '(Integer) -> BigDecimal'
|
34
|
+
type :**, '(Float) -> BigDecimal'
|
35
|
+
pre(:**) { |x| x!=Float::INFINITY && !x.nan? && if(self<0) then x<=-1||x>=0 else true end}
|
36
|
+
type :**, '(Rational) -> BigDecimal'
|
37
|
+
pre(:**) { |x| if(self<0) then x<=-1||x>=0 else true end}
|
38
|
+
type :**, '(BigDecimal) -> BigDecimal'
|
39
|
+
pre(:**) { |x| x!=BigDecimal::INFINITY && if(self<0) then x<=-1||x>=0 else true end}
|
40
|
+
|
41
|
+
type :/, '(Integer) -> BigDecimal'
|
42
|
+
pre(:/) { |x| x!=0}
|
43
|
+
type :/, '(Float) -> BigDecimal'
|
44
|
+
pre(:/) { |x| x!=0 && x!=Float::INFINITY && !(x.nan?)}
|
45
|
+
type :/, '(Rational) -> BigDecimal'
|
46
|
+
pre(:/) { |x| x!=0}
|
47
|
+
type :/, '(BigDecimal) -> BigDecimal'
|
48
|
+
pre(:/) { |x| x!=0}
|
49
|
+
type :/, '(Complex) -> Complex'
|
50
|
+
pre(:/) { |x| x!=0 && if x.real.is_a?(Float) then x.real!=Float::INFINITY && !(x.real.nan?) else true end && if x.imaginary.is_a?(Float) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end && if (x.real.is_a?(Rational)) then !x.imaginary.nan? else true end}
|
51
|
+
|
52
|
+
type :<, '(Integer) -> %bool'
|
53
|
+
type :<, '(Float) -> %bool'
|
54
|
+
pre(:<) { |x| !x.nan? && x!=Float::INFINITY}
|
55
|
+
type :<, '(Rational) -> %bool'
|
56
|
+
type :<, '(BigDecimal) -> %bool'
|
57
|
+
|
58
|
+
type :<=, '(Integer) -> %bool'
|
59
|
+
type :<=, '(Float) -> %bool'
|
60
|
+
pre(:<=) { |x| !x.nan? && x!=Float::INFINITY}
|
61
|
+
type :<=, '(Rational) -> %bool'
|
62
|
+
type :<=, '(BigDecimal) -> %bool'
|
63
|
+
|
64
|
+
type :>, '(Integer) -> %bool'
|
65
|
+
type :>, '(Float) -> %bool'
|
66
|
+
pre(:>) { |x| !x.nan? && x!=Float::INFINITY}
|
67
|
+
type :>, '(Rational) -> %bool'
|
68
|
+
type :>, '(BigDecimal) -> %bool'
|
69
|
+
|
70
|
+
type :>=, '(Integer) -> %bool'
|
71
|
+
type :>=, '(Float) -> %bool'
|
72
|
+
pre(:>=) { |x| !x.nan? && x!=Float::INFINITY}
|
73
|
+
type :>=, '(Rational) -> %bool'
|
74
|
+
type :>=, '(BigDecimal) -> %bool'
|
75
|
+
|
76
|
+
type :==, '(Object) -> %bool'
|
77
|
+
pre(:==) { |x| if (x.is_a?(Float)) then (!x.nan? && x!=Float::INFINITY) else true end}
|
78
|
+
|
79
|
+
type :===, '(Object) -> %bool'
|
80
|
+
pre(:===) { |x| if (x.is_a?(Float)) then (!x.nan? && x!=Float::INFINITY) else true end}
|
81
|
+
|
82
|
+
type :<=>, '(Integer) -> Object'
|
83
|
+
post(:<=>) { |r,x| r == -1 || r==0 || r==1}
|
84
|
+
type :<=>, '(Float) -> Object'
|
85
|
+
pre(:<=>) { |x| !x.nan? && x!=Float::INFINITY}
|
86
|
+
post(:<=>) { |r,x| r == -1 || r==0 || r==1}
|
87
|
+
type :<=>, '(Rational) -> Object'
|
88
|
+
post(:<=>) { |r,x| r == -1 || r==0 || r==1}
|
89
|
+
type :<=>, '(BigDecimal) -> Object'
|
90
|
+
post(:<=>) { |r,x| r == -1 || r==0 || r==1}
|
91
|
+
|
92
|
+
type :abs, '() -> BigDecimal'
|
93
|
+
post(:abs) { |r,x| r >= 0 }
|
94
|
+
|
95
|
+
type :abs2, '() -> BigDecimal'
|
96
|
+
post(:abs2) { |r,x| r >= 0 }
|
97
|
+
|
98
|
+
type :angle, '() -> Numeric'
|
99
|
+
post(:angle) { |r,x| r == 0 || r == Math::PI}
|
100
|
+
|
101
|
+
type :arg, '() -> Numeric'
|
102
|
+
post(:arg) { |r,x| r == 0 || r == Math::PI}
|
103
|
+
|
104
|
+
type :ceil, '() -> Integer'
|
105
|
+
pre(:ceil) { !self.ininite? && !self.nan?}
|
106
|
+
|
107
|
+
type :conj, '() -> BigDecimal'
|
108
|
+
type :conjugate, '() -> BigDecimal'
|
109
|
+
|
110
|
+
type :denominator, '() -> Integer'
|
111
|
+
pre(:denominator) { !self.ininite? && !self.nan?}
|
112
|
+
post(:denominator) { |r,x| r>0}
|
113
|
+
|
114
|
+
type :div, '(Fixnum) -> Integer'
|
115
|
+
pre(:div) { |x| x!=0 && !self.infinite? && !self.nan?}
|
116
|
+
type :div, '(Bignum) -> Integer'
|
117
|
+
pre(:div) { |x| x!=0 && !self.infinite? && !self.nan?}
|
118
|
+
type :div, '(Float) -> Integer'
|
119
|
+
pre(:div) { |x| x!=0 && !x.nan? && x!=Float::INFINITY && !self.infinite? && !self.nan?}
|
120
|
+
type :div, '(Rational) -> Integer'
|
121
|
+
pre(:div) { |x| x!=0 && !self.infinite? && !self.nan?}
|
122
|
+
type :div, '(BigDecimal) -> Integer'
|
123
|
+
pre(:div) { |x| x!=0 && !x.nan? && !self.infinite? && !self.nan?}
|
124
|
+
|
125
|
+
type :divmod, '(%real) -> [%real, %real]'
|
126
|
+
pre(:divmod) { |x| x!=0 && if x.is_a?(Float) then !x.nan? && x!=Float::INFINITY else true end}
|
127
|
+
|
128
|
+
type :equal?, '(Object) -> %bool'
|
129
|
+
type :eql?, '(Object) -> %bool'
|
130
|
+
|
131
|
+
type :fdiv, '(Integer) -> Float'
|
132
|
+
type :fdiv, '(Float) -> Float'
|
133
|
+
type :fdiv, '(Rational) -> Float'
|
134
|
+
type :fdiv, '(BigDecimal) -> BigDecimal'
|
135
|
+
type :fdiv, '(Complex) -> Complex'
|
136
|
+
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}
|
137
|
+
|
138
|
+
type :finite?, '() -> %bool'
|
139
|
+
|
140
|
+
type :floor, '() -> Integer'
|
141
|
+
pre(:floor) { !self.infinite? && !self.nan?}
|
142
|
+
|
143
|
+
type :hash, '() -> Integer'
|
144
|
+
|
145
|
+
type :imag, '() -> Fixnum'
|
146
|
+
post(:imag) { |r,x| r == 0 }
|
147
|
+
type :imaginary, '() -> Fixnum'
|
148
|
+
post(:imaginary) { |r,x| r == 0 }
|
149
|
+
|
150
|
+
type :infinite?, '() -> %bool'
|
151
|
+
|
152
|
+
type :to_s, '() -> String'
|
153
|
+
type :inspect, '() -> String'
|
154
|
+
|
155
|
+
type :magnitude, '() -> BigDecimal'
|
156
|
+
post(:magnitude) { |r,x| r>0}
|
157
|
+
|
158
|
+
type :modulo, '(Numeric) -> BigDecimal'
|
159
|
+
pre(:modulo) { |x| x!=0&&(if x.is_a?(Float) then x!=Float::INFINITY && !x.nan? else true end)}
|
160
|
+
|
161
|
+
type :nan?, '() -> %bool'
|
162
|
+
|
163
|
+
type :numerator, '() -> Integer'
|
164
|
+
pre(:numerator) { !self.infinite? && !self.nan?}
|
165
|
+
|
166
|
+
type :phase, '() -> Numeric'
|
167
|
+
|
168
|
+
type :quo, '(Integer) -> BigDecimal'
|
169
|
+
pre(:quo) { |x| x!=0}
|
170
|
+
type :quo, '(Float) -> BigDecimal'
|
171
|
+
pre(:quo) { |x| x!=0 && x!=Float::INFINITY && !x.nan?}
|
172
|
+
type :quo, '(Rational) -> BigDecimal'
|
173
|
+
pre(:quo) { |x| x!=0}
|
174
|
+
type :quo, '(BigDecimal) -> BigDecimal'
|
175
|
+
pre(:quo) { |x| x!=0}
|
176
|
+
type :quo, '(Complex) -> Complex'
|
177
|
+
pre(:quo) { |x| x!=0 && if x.real.is_a?(Float) then x.real!=Float::INFINITY && !(x.real.nan?) else true end && if x.imaginary.is_a?(Float) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end && if (x.real.is_a?(Rational)) then !x.imaginary.nan? else true end}
|
178
|
+
|
179
|
+
type :real, '() -> BigDecimal'
|
180
|
+
|
181
|
+
type :real?, '() -> TrueClass'
|
182
|
+
|
183
|
+
type :round, '() -> Integer'
|
184
|
+
pre(:round) { !self.infinite? && !self.nan?}
|
185
|
+
|
186
|
+
type :round, '(Fixnum) -> BigDecimal' #Also, x must be in range [-2**31, 2**31].
|
187
|
+
|
188
|
+
type :to_f, '() -> Float'
|
189
|
+
pre(:to_f) { self<=Float::MAX}
|
190
|
+
|
191
|
+
type :to_i, '() -> Integer'
|
192
|
+
pre(:to_i) { !self.infinite? && !self.nan?}
|
193
|
+
type :to_int, '() -> Integer'
|
194
|
+
pre(:to_int) { !self.infinite? && !self.nan?}
|
195
|
+
|
196
|
+
type :to_r, '() -> Rational'
|
197
|
+
pre(:to_r) { !self.infinite? && !self.nan?}
|
198
|
+
|
199
|
+
type :to_c, '() -> Complex'
|
200
|
+
post(:to_c) { |r,x| r.imaginary == 0 }
|
201
|
+
|
202
|
+
type :truncate, '() -> Integer'
|
203
|
+
|
204
|
+
type :truncate, '(Fixnum) -> Rational' #Also, x must be in range [-2**31, 2**31].
|
205
|
+
|
206
|
+
type :zero?, '() -> %bool'
|
207
|
+
|
208
|
+
type :precs, '() -> [Integer, Integer]'
|
209
|
+
|
210
|
+
type :split, '() -> [Fixnum, String, Integer, Integer]'
|
211
|
+
|
212
|
+
type :remainder, '(%real) -> BigDecimal'
|
213
|
+
pre(:remainder) { |x| if x.is_a?(Float) then !x.infinite? && !x.nan? else true end}
|
214
|
+
|
215
|
+
type :fix, '() -> BigDecimal'
|
216
|
+
|
217
|
+
type :frac, '() -> BigDecimal'
|
218
|
+
|
219
|
+
type :power, '(Integer) -> BigDecimal'
|
220
|
+
type :power, '(Float) -> BigDecimal'
|
221
|
+
pre(:power) { |x| x!=Float::INFINITY && !x.nan? && if(self<0) then x<=-1||x>=0 else true end}
|
222
|
+
type :power, '(Rational) -> BigDecimal'
|
223
|
+
pre(:power) { |x| if(self<0) then x<=-1||x>=0 else true end}
|
224
|
+
type :power, '(BigDecimal) -> BigDecimal'
|
225
|
+
pre(:power) { |x| x!=BigDecimal::INFINITY && if(self<0) then x<=-1||x>=0 else true end}
|
226
|
+
|
227
|
+
type :nonzero?, '() -> Object'
|
228
|
+
|
229
|
+
type :exponent, '() -> Integer'
|
230
|
+
|
231
|
+
type :sign, '() -> Fixnum'
|
232
|
+
|
233
|
+
type :_dump, '() -> String'
|
234
|
+
|
235
|
+
type :sqrt, '(Fixnum) -> BigDecimal'
|
236
|
+
pre(:sqrt) { self>=0}
|
237
|
+
|
238
|
+
type :add, '(%real, Fixnum) -> BigDecimal'
|
239
|
+
pre(:add) { |x,y| if x.is_a?(Float) then !x.infinite? && !x.nan? else true end}
|
240
|
+
|
241
|
+
type :sub, '(%real, Fixnum) -> BigDecimal'
|
242
|
+
pre(:sub) { |x,y| if x.is_a?(Float) then !x.infinite? && !x.nan? else true end}
|
243
|
+
|
244
|
+
type :mult, '(%real, Fixnum) -> BigDecimal'
|
245
|
+
pre(:mult) { |x,y| if x.is_a?(Float) then !x.infinite? && !x.nan? else true end}
|
246
|
+
|
247
|
+
type :coerce, '(%real) -> [BigDecimal, BigDecimal]'
|
248
|
+
pre(:coerce) { |x| if x.is_a?(Float) then !x.nan? && !x.finite? else true end}
|
15
249
|
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
class Bignum < Integer
|
2
|
+
rdl_nowrap
|
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'
|
18
|
+
type :*, '(Bignum) -> Bignum'
|
19
|
+
type :*, '(Float) -> Float'
|
20
|
+
type :*, '(Rational) -> Rational'
|
21
|
+
type :*, '(BigDecimal) -> BigDecimal'
|
22
|
+
type :*, '(Complex) -> Complex'
|
23
|
+
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
|
+
|
25
|
+
type :**, '(Integer) -> Numeric'
|
26
|
+
type :**, '(Float) -> Numeric'
|
27
|
+
type :**, '(Rational) -> Numeric'
|
28
|
+
type :**, '(BigDecimal) -> BigDecimal'
|
29
|
+
pre(:**) { |x| x!=BigDecimal::INFINITY && if self<0 then x<=-1||x>=0 else true end}
|
30
|
+
post(:**) { |r,x| r.real?}
|
31
|
+
type :**, '(Complex) -> Complex'
|
32
|
+
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
|
+
|
34
|
+
type :+, '(Integer) -> Integer'
|
35
|
+
type :+, '(Float) -> Float'
|
36
|
+
type :+, '(Rational) -> Rational'
|
37
|
+
type :+, '(BigDecimal) -> BigDecimal'
|
38
|
+
type :+, '(Complex) -> Complex'
|
39
|
+
|
40
|
+
type :-, '(Integer) -> Integer'
|
41
|
+
type :-, '(Float) -> Float'
|
42
|
+
type :-, '(Rational) -> Rational'
|
43
|
+
type :-, '(BigDecimal) -> BigDecimal'
|
44
|
+
type :-, '(Complex) -> Complex'
|
45
|
+
|
46
|
+
type :-, '() -> Integer'
|
47
|
+
|
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}
|
58
|
+
|
59
|
+
type :<, '(Integer) -> %bool'
|
60
|
+
type :<, '(Float) -> %bool'
|
61
|
+
type :<, '(Rational) -> %bool'
|
62
|
+
type :<, '(BigDecimal) -> %bool'
|
63
|
+
|
64
|
+
type :<<, '(Fixnum) -> Integer'
|
65
|
+
|
66
|
+
type :<=, '(Integer) -> %bool'
|
67
|
+
type :<=, '(Float) -> %bool'
|
68
|
+
type :<=, '(Rational) -> %bool'
|
69
|
+
type :<=, '(BigDecimal) -> %bool'
|
70
|
+
|
71
|
+
type :<=>, '(Integer) -> Object'
|
72
|
+
post(:<=>) { |r,x| r == -1 || r==0 || r==1}
|
73
|
+
type :<=>, '(Float) -> Object'
|
74
|
+
post(:<=>) { |r,x| r == -1 || r==0 || r==1}
|
75
|
+
type :<=>, '(Rational) -> Object'
|
76
|
+
post(:<=>) { |r,x| r == -1 || r==0 || r==1}
|
77
|
+
type :<=>, '(BigDecimal) -> Object'
|
78
|
+
post(:<=>) { |r,x| r == -1 || r==0 || r==1}
|
79
|
+
|
80
|
+
type :==, '(Object) -> %bool'
|
81
|
+
|
82
|
+
type :===, '(Object) -> %bool'
|
83
|
+
|
84
|
+
type :>, '(Integer) -> %bool'
|
85
|
+
type :>, '(Float) -> %bool'
|
86
|
+
type :>, '(Rational) -> %bool'
|
87
|
+
type :>, '(BigDecimal) -> %bool'
|
88
|
+
|
89
|
+
type :>=, '(Integer) -> %bool'
|
90
|
+
type :>=, '(Float) -> %bool'
|
91
|
+
type :>=, '(Rational) -> %bool'
|
92
|
+
type :>=, '(BigDecimal) -> %bool'
|
93
|
+
|
94
|
+
type :>>, '(Integer) -> Integer'
|
95
|
+
post(:>>) { |r,x| r >= 0 }
|
96
|
+
|
97
|
+
type :[], '(Integer) -> Fixnum'
|
98
|
+
post(:[]) { |r,x| r == 0 || r==1}
|
99
|
+
type :[], '(Rational) -> Fixnum'
|
100
|
+
post(:[]) { |r,x| r == 0 || r==1}
|
101
|
+
type :[], '(Float) -> Fixnum'
|
102
|
+
pre(:[]) { |x| x!=Float::INFINITY && !x.nan? }
|
103
|
+
post(:[]) { |r,x| r == 0 || r==1}
|
104
|
+
type :[], '(BigDecimal) -> Fixnum'
|
105
|
+
pre(:[]) { |x| x!=BigDecimal::INFINITY && !x.nan? }
|
106
|
+
post(:[]) { |r,x| r == 0 || r==1}
|
107
|
+
|
108
|
+
type :^, '(Integer) -> Integer'
|
109
|
+
|
110
|
+
type :|, '(Integer) -> Integer'
|
111
|
+
|
112
|
+
type :~, '() -> Bignum'
|
113
|
+
|
114
|
+
type :abs, '() -> Bignum'
|
115
|
+
post(:abs) { |r,x| r >= 0 }
|
116
|
+
|
117
|
+
type :bit_length, '() -> Integer'
|
118
|
+
post(:bit_length) { |r,x| r >= 0 }
|
119
|
+
|
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?}
|
130
|
+
|
131
|
+
type :divmod, '(%real) -> [%real, %real]'
|
132
|
+
pre(:divmod) { |x| x!=0 && if x.is_a?(Float) then !x.nan? else true end}
|
133
|
+
|
134
|
+
type :even?, '() -> %bool'
|
135
|
+
|
136
|
+
type :fdiv, '(Integer) -> Float'
|
137
|
+
type :fdiv, '(Float) -> Float'
|
138
|
+
type :fdiv, '(Rational) -> Float'
|
139
|
+
type :fdiv, '(BigDecimal) -> BigDecimal'
|
140
|
+
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}
|
142
|
+
|
143
|
+
type :to_s, '() -> String'
|
144
|
+
type :inspect, '() -> String'
|
145
|
+
|
146
|
+
type :magnitude, '() -> Bignum'
|
147
|
+
post(:magnitude) { |r,x| r >= 0 }
|
148
|
+
|
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}
|
159
|
+
|
160
|
+
type :next, '() -> Integer'
|
161
|
+
|
162
|
+
type :odd?, '() -> %bool'
|
163
|
+
|
164
|
+
type :size, '() -> Integer'
|
165
|
+
|
166
|
+
type :succ, '() -> Integer'
|
167
|
+
|
168
|
+
type :to_f, '() -> Float'
|
169
|
+
|
170
|
+
type :zero?, '() -> %bool'
|
171
|
+
|
172
|
+
type :ceil, '() -> Integer'
|
173
|
+
|
174
|
+
type :denominator, '() -> Fixnum'
|
175
|
+
post(:denominator) { |r,x| r == 1 }
|
176
|
+
|
177
|
+
type :floor, '() -> Integer'
|
178
|
+
|
179
|
+
type :numerator, '() -> Bignum'
|
180
|
+
|
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}
|
191
|
+
|
192
|
+
type :rationalize, '() -> Rational'
|
193
|
+
|
194
|
+
type :rationalize, '(Numeric) -> Rational'
|
195
|
+
|
196
|
+
type :round, '() -> Integer'
|
197
|
+
|
198
|
+
type :round, '(Numeric) -> Numeric'
|
199
|
+
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
|
+
|
201
|
+
type :to_i, '() -> Bignum'
|
202
|
+
|
203
|
+
type :to_r, '() -> Rational'
|
204
|
+
|
205
|
+
type :truncate, '() -> Integer'
|
206
|
+
|
207
|
+
type :angle, '() -> Numeric'
|
208
|
+
post(:angle) { |r,x| r == 0 || r == Math::PI}
|
209
|
+
|
210
|
+
type :arg, '() -> Numeric'
|
211
|
+
post(:arg) { |r,x| r == 0 || r == Math::PI}
|
212
|
+
|
213
|
+
type :equal?, '(Object) -> %bool'
|
214
|
+
type :eql?, '(Object) -> %bool'
|
215
|
+
|
216
|
+
type :hash, '() -> Integer'
|
217
|
+
|
218
|
+
type :phase, '() -> Numeric'
|
219
|
+
|
220
|
+
type :abs2, '() -> Bignum'
|
221
|
+
post(:abs2) { |r,x| r >= 0 }
|
222
|
+
|
223
|
+
type :conj, '() -> Bignum'
|
224
|
+
type :conjugate, '() -> Bignum'
|
225
|
+
|
226
|
+
type :imag, '() -> Fixnum'
|
227
|
+
post(:imag) { |r,x| r == 0 }
|
228
|
+
type :imaginary, '() -> Fixnum'
|
229
|
+
post(:imaginary) { |r,x| r == 0 }
|
230
|
+
|
231
|
+
type :real, '() -> Bignum'
|
232
|
+
|
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]'
|
253
|
+
end
|