rdl 1.1.0 → 1.1.1.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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGES.md +25 -0
  4. data/README.md +104 -64
  5. data/extras/type_tests/%.rb +171 -0
  6. data/extras/type_tests/&.rb +159 -0
  7. data/extras/type_tests/**.rb +222 -0
  8. data/extras/type_tests/*.rb +177 -0
  9. data/extras/type_tests/+.rb +170 -0
  10. data/extras/type_tests/-.rb +171 -0
  11. data/extras/type_tests/1scomp.rb +157 -0
  12. data/extras/type_tests/<.rb +170 -0
  13. data/extras/type_tests/<<.rb +159 -0
  14. data/extras/type_tests/>>.rb +159 -0
  15. data/extras/type_tests/[].rb +163 -0
  16. data/extras/type_tests/^.rb +159 -0
  17. data/extras/type_tests/abs.rb +155 -0
  18. data/extras/type_tests/abs2.rb +164 -0
  19. data/extras/type_tests/angle.rb +157 -0
  20. data/extras/type_tests/arg.rb +157 -0
  21. data/extras/type_tests/bit_length.rb +157 -0
  22. data/extras/type_tests/ceil.rb +157 -0
  23. data/extras/type_tests/ceilRational.rb +160 -0
  24. data/extras/type_tests/conj.rb +158 -0
  25. data/extras/type_tests/defwhere.rb +86 -0
  26. data/extras/type_tests/denominator.rb +157 -0
  27. data/extras/type_tests/div.rb +172 -0
  28. data/extras/type_tests/divslash.rb +179 -0
  29. data/extras/type_tests/even?.rb +157 -0
  30. data/extras/type_tests/fdiv.rb +244 -0
  31. data/extras/type_tests/finite?.rb +157 -0
  32. data/extras/type_tests/floor.rb +157 -0
  33. data/extras/type_tests/floorRational.rb +161 -0
  34. data/extras/type_tests/hash.rb +157 -0
  35. data/extras/type_tests/imag.rb +158 -0
  36. data/extras/type_tests/infinite?.rb +157 -0
  37. data/extras/type_tests/modulo.rb +171 -0
  38. data/extras/type_tests/nan?.rb +157 -0
  39. data/extras/type_tests/neg.rb +155 -0
  40. data/extras/type_tests/next.rb +157 -0
  41. data/extras/type_tests/next_float.rb +157 -0
  42. data/extras/type_tests/numerator.rb +157 -0
  43. data/extras/type_tests/phase.rb +157 -0
  44. data/extras/type_tests/prev_float.rb +157 -0
  45. data/extras/type_tests/quo.rb +179 -0
  46. data/extras/type_tests/rationalize.rb +157 -0
  47. data/extras/type_tests/rationalizeArg.rb +198 -0
  48. data/extras/type_tests/real.rb +157 -0
  49. data/extras/type_tests/real?.rb +157 -0
  50. data/extras/type_tests/round.rb +157 -0
  51. data/extras/type_tests/roundArg.rb +169 -0
  52. data/extras/type_tests/size.rb +157 -0
  53. data/extras/type_tests/to_c.rb +157 -0
  54. data/extras/type_tests/to_f.rb +155 -0
  55. data/extras/type_tests/to_i.rb +157 -0
  56. data/extras/type_tests/to_r.rb +157 -0
  57. data/extras/type_tests/to_s.rb +157 -0
  58. data/extras/type_tests/truncate.rb +157 -0
  59. data/extras/type_tests/truncateArg.rb +166 -0
  60. data/extras/type_tests/type tests +1 -0
  61. data/extras/type_tests/zero?.rb +155 -0
  62. data/extras/type_tests/|.rb +159 -0
  63. data/lib/rdl/contracts/and.rb +1 -1
  64. data/lib/rdl/contracts/flat.rb +2 -2
  65. data/lib/rdl/contracts/proc.rb +2 -1
  66. data/lib/rdl/types/.#lexer.rex +1 -0
  67. data/lib/rdl/types/dependent_arg.rb +47 -0
  68. data/lib/rdl/types/finitehash.rb +5 -5
  69. data/lib/rdl/types/generic.rb +3 -3
  70. data/lib/rdl/types/lexer.rex +5 -2
  71. data/lib/rdl/types/lexer.rex.rb +3 -0
  72. data/lib/rdl/types/method.rb +144 -15
  73. data/lib/rdl/types/nominal.rb +1 -1
  74. data/lib/rdl/types/parser.racc +6 -1
  75. data/lib/rdl/types/parser.tab.rb +272 -245
  76. data/lib/rdl/types/tuple.rb +1 -1
  77. data/lib/rdl/types/type_inferencer.rb +7 -7
  78. data/lib/rdl/wrap.rb +16 -11
  79. data/rdl.gemspec +3 -3
  80. data/test/test_dsl.rb +4 -5
  81. data/test/test_le.rb +5 -5
  82. data/test/test_lib_types.rb +34 -34
  83. data/test/test_member.rb +3 -3
  84. data/test/test_type_contract.rb +63 -1
  85. data/test/test_types.rb +2 -0
  86. data/types/ruby-2.x/_aliases.rb +2 -2
  87. data/types/ruby-2.x/bigdecimal.rb +246 -12
  88. data/types/ruby-2.x/bignum.rb +253 -0
  89. data/types/ruby-2.x/complex.rb +111 -22
  90. data/types/ruby-2.x/fixnum.rb +238 -31
  91. data/types/ruby-2.x/float.rb +217 -35
  92. data/types/ruby-2.x/integer.rb +17 -16
  93. data/types/ruby-2.x/numeric.rb +31 -21
  94. data/types/ruby-2.x/rational.rb +196 -18
  95. metadata +67 -4
@@ -1,42 +1,131 @@
1
- class Complex
1
+ class Complex < Numeric
2
2
  rdl_nowrap
3
3
 
4
- type 'self.polar', '(%real abs, ?%real arg) -> Complex'
5
- type 'self.rect', '(%real real, ?%real imag) -> Complex'
6
- pre('self.rect') { |r, i| (not i) || (i.real?) }
7
- rdl_alias 'self.rectangular', 'self.rect'
8
- type :*, '(Numeric) -> Complex'
9
- type :**, '(Numeric) -> Complex'
10
- type :+, '(Numeric) -> Complex'
11
- type :-, '(Numeric) -> Complex'
4
+ type :*, '(Integer) -> Complex'
5
+ type :*, '(Float) -> Complex'
6
+ pre(:*) { |x| if x.infinite?||x.nan? then !self.imaginary.is_a?(BigDecimal)&&!self.real.is_a?(BigDecimal) else true end}
7
+ type :*, '(Rational) -> Complex'
8
+ type :*, '(BigDecimal) -> Complex'
9
+ pre(:*) {if x.real.is_a?(Float) then !x.real.infinite? && !x.real.nan? elsif x.imaginary.is_a?(Float) then !x.imaginary.infinite? && !x.imaginary.nan? else true end}
10
+ type :*, '(Complex) -> Complex'
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
+
13
+ type :**, '(Integer) -> Complex'
14
+ type :**, '(Float) -> Complex'
15
+ type :**, '(Rational) -> Complex'
16
+ type :**, '(BigDecimal) -> Complex'
17
+ pre(:**) { |x| x!=BigDecimal::INFINITY && !x.nan? && x>=0}
18
+ type :**, '(Complex) -> Complex'
19
+ 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
+
21
+ type :+, '(Integer) -> Complex'
22
+ type :+, '(Float) -> Complex'
23
+ pre(:+) { |x| if x.infinite?||x.nan? then !self.real.is_a?(BigDecimal) else true end}
24
+ type :+, '(Rational) -> Complex'
25
+ type :+, '(BigDecimal) -> Complex'
26
+ pre(:+) {if x.real.is_a?(Float) then !x.real.infinite? && !x.real.nan? else true end}
27
+ type :+, '(Complex) -> Complex'
28
+ 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'
31
+ type :-, '(Float) -> Complex'
32
+ pre(:-) { |x| if x.infinite?||x.nan? then !self.real.is_a?(BigDecimal) else true end}
33
+ type :-, '(Rational) -> Complex'
34
+ type :-, '(BigDecimal) -> Complex'
35
+ pre(:-) {if x.real.is_a?(Float) then !x.real.infinite? && !x.real.nan? else true end}
36
+ type :-, '(Complex) -> Complex'
37
+ 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}
38
+
12
39
  type :-, '() -> Complex'
13
- type :/, '(Numeric) -> Complex'
14
- type :==, '(%any object) -> %bool'
15
- type :abs, '() -> %real'
16
- post(:abs) { |r| r >= 0 }
17
- type :abs2, '() -> %real'
18
- post(:abs2) { |r| r >= 0 }
40
+
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}
51
+
52
+ type:==, '(Object) -> %bool'
53
+
54
+ type :abs, '() -> Numeric'
55
+ post(:abs) { |r,x| r >= 0 }
56
+
57
+ type :abs2, '() -> Numeric'
58
+ post(:abs2) { |r,x| r >= 0 }
59
+
19
60
  type :angle, '() -> Float'
61
+
20
62
  type :arg, '() -> Float'
63
+
21
64
  type :conj, '() -> Complex'
22
- rdl_alias :conjugate, :conj
65
+ type :conjugate, '() -> Complex'
66
+
23
67
  type :denominator, '() -> Integer'
68
+
69
+ type :equal?, '(Object) -> %bool'
70
+ type :eql?, '(Object) -> %bool'
71
+
24
72
  type :fdiv, '(Numeric) -> Complex'
73
+ 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
+
75
+ type :hash, '() -> Integer'
76
+
25
77
  type :imag, '() -> %real'
26
- rdl_alias :imaginary, :imag
78
+ type :imaginary, '() -> %real'
79
+
27
80
  type :inspect, '() -> String'
81
+
28
82
  type :magnitude, '() -> %real'
29
- type :numerator, '() -> Numeric'
83
+
84
+ type :numerator, '() -> Complex'
85
+
30
86
  type :phase, '() -> Float'
31
- type :polar, '() -> [%real, %real]'
32
- rdl_alias :quo, :/
33
- type :rationalize, '(?Numeric eps) -> Rational'
87
+
88
+ type :polar, '() -> [%real, %real]'
89
+
90
+
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}
101
+
102
+ type :rationalize, '() -> Rational'
103
+ 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
+
105
+ type :rationalize, '(Numeric) -> Rational'
106
+ 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
+
34
108
  type :real, '() -> %real'
109
+
35
110
  type :real?, '() -> FalseClass'
111
+
36
112
  type :rect, '() -> [%real, %real]'
37
- type :to_c, '() -> self'
113
+ type :rectangular, '() -> [%real, %real]'
114
+
115
+ type :to_c, '() -> Complex'
116
+
38
117
  type :to_f, '() -> Float'
118
+ pre(:to_f) { self.imaginary==0}
119
+
39
120
  type :to_i, '() -> Integer'
121
+ 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
+
40
123
  type :to_r, '() -> Rational'
124
+ pre(:to_r) { self.imaginary==0 && if self.real.is_a?(Float)||self.real.is_a?(BigDecimal) then !self.real.infinite? && !self.real.nan? else true end}
125
+
41
126
  type :to_s, '() -> String'
127
+
128
+ type :zero?, '() -> %bool'
129
+
130
+ type :coerce, '(Numeric) -> [Complex, Complex]'
42
131
  end
@@ -1,45 +1,252 @@
1
- class Fixnum
1
+ class Fixnum < Integer
2
2
  rdl_nowrap
3
3
 
4
- type :%, '(Numeric other) -> Numeric'
5
- post(:%) { |r, _| r.real? }
6
- type :&, '(Integer) -> Integer'
7
- type :*, '(Numeric) -> Numeric'
8
- type :**, '(Numeric) -> Numeric'
9
- type :+, '(Numeric) -> Numeric'
10
- type :-, '(Numeric) -> Numeric'
11
- type :-, '() -> Numeric'
12
- type :/, '(Numeric) -> Numeric'
13
- type :<, '(Numeric) -> %bool'
14
- pre(:<) { |x| x.real? }
15
- type :<<, '(Fixnum count) -> Integer'
16
- type :<=, '(Numeric) -> %bool'
17
- pre(:<=) { |x| x.real? }
18
- type :<=>, '(Numeric) -> -1 or 0 or 1 or nil'
19
- type :==, '(%any) -> %bool'
20
- type :>, '(Numeric) -> %bool'
21
- pre(:>) { |x| x.real? }
22
- type :>=, '(Numeric) -> %bool'
23
- pre(:>=) { |x| x.real? }
24
- type :>>, '(Fixnum count) -> Integer'
25
- type :[], '(Fixnum) -> 0 or 1'
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'
18
+ type :*, '(Float) -> Float'
19
+ type :*, '(Rational) -> Rational'
20
+ type :*, '(BigDecimal) -> BigDecimal'
21
+ type :*, '(Complex) -> Complex'
22
+ 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
+
24
+ type :**, '(Integer) -> Numeric'
25
+ type :**, '(Float) -> Numeric'
26
+ type :**, '(Rational) -> Numeric'
27
+ type :**, '(BigDecimal) -> BigDecimal'
28
+ pre(:**) { |x| x!=BigDecimal::INFINITY && if self<0 then x<=-1||x>=0 else true end}
29
+ post(:**) { |r,x| r.real?}
30
+ type :**, '(Complex) -> Complex'
31
+ 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
+
33
+ type :+, '(Integer) -> Integer'
34
+ type :+, '(Float) -> Float'
35
+ type :+, '(Rational) -> Rational'
36
+ type :+, '(BigDecimal) -> BigDecimal'
37
+ type :+, '(Complex) -> Complex'
38
+
39
+ type :-, '(Integer) -> Integer'
40
+ type :-, '(Float) -> Float'
41
+ type :-, '(Rational) -> Rational'
42
+ type :-, '(BigDecimal) -> BigDecimal'
43
+ type :-, '(Complex) -> Complex'
44
+
45
+ type :-, '() -> Fixnum'
46
+
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'
59
+ type :<, '(Float) -> %bool'
60
+ type :<, '(Rational) -> %bool'
61
+ type :<, '(BigDecimal) -> %bool'
62
+
63
+ type :<<, '(Fixnum) -> Integer' #must be below a certain amount, not exactly sure what amount
64
+
65
+ type :<=, '(Integer) -> %bool'
66
+ type :<=, '(Float) -> %bool'
67
+ type :<=, '(Rational) -> %bool'
68
+ type :<=, '(BigDecimal) -> %bool'
69
+
70
+ type :<=>, '(Integer) -> Object'
71
+ post(:<=>) { |r,x| r == -1 || r==0 || r==1}
72
+ type :<=>, '(Float) -> Object'
73
+ post(:<=>) { |r,x| r == -1 || r==0 || r==1}
74
+ type :<=>, '(Rational) -> Object'
75
+ post(:<=>) { |r,x| r == -1 || r==0 || r==1}
76
+ type :<=>, '(BigDecimal) -> Object'
77
+ post(:<=>) { |r,x| r == -1 || r==0 || r==1}
78
+
79
+ type :==, '(Object) -> %bool'
80
+
81
+ type :===, '(Object) -> %bool'
82
+
83
+ type :>, '(Integer) -> %bool'
84
+ type :>, '(Float) -> %bool'
85
+ type :>, '(Rational) -> %bool'
86
+ type :>, '(BigDecimal) -> %bool'
87
+
88
+ type :>=, '(Integer) -> %bool'
89
+ type :>=, '(Float) -> %bool'
90
+ type :>=, '(Rational) -> %bool'
91
+ type :>=, '(BigDecimal) -> %bool'
92
+
93
+ type :>>, '(Integer) -> Integer'
94
+ post(:>>) { |r,x| r >= 0 }
95
+
96
+ type :[], '(Integer) -> Fixnum'
97
+ post(:[]) { |r,x| r == 0 || r==1}
98
+ type :[], '(Rational) -> Fixnum'
99
+ post(:[]) { |r,x| r == 0 || r==1}
100
+ type :[], '(Float) -> Fixnum'
101
+ pre(:[]) { |x| x!=Float::INFINITY && !x.nan? }
102
+ post(:[]) { |r,x| r == 0 || r==1}
103
+ type :[], '(BigDecimal) -> Fixnum'
104
+ pre(:[]) { |x| x!=BigDecimal::INFINITY && !x.nan? }
105
+ post(:[]) { |r,x| r == 0 || r==1}
106
+
26
107
  type :^, '(Integer) -> Integer'
108
+
27
109
  type :|, '(Integer) -> Integer'
28
- type :~, '() -> Integer'
110
+
111
+ type :~, '() -> Fixnum'
112
+
29
113
  type :abs, '() -> Integer'
114
+ post(:abs) { |r,x| r >= 0 }
115
+
30
116
  type :bit_length, '() -> Fixnum'
31
- type :div, '(Numeric) -> Integer'
32
- type :divmod, '(Numeric) -> [Numeric, Numeric]'
117
+ post(:bit_length) { |r,x| r >= 0 }
118
+
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?}
129
+
130
+ type :divmod, '(%real) -> [%real, %real]'
131
+ pre(:divmod) { |x| x!=0 && if x.is_a?(Float) then !x.nan? else true end}
132
+
33
133
  type :even?, '() -> %bool'
34
- type :fdiv, '(Numeric) -> Float'
35
- rdl_alias :inspect, :to_s
134
+
135
+ type :fdiv, '(Integer) -> Float'
136
+ type :fdiv, '(Float) -> Float'
137
+ type :fdiv, '(Rational) -> Float'
138
+ type :fdiv, '(BigDecimal) -> BigDecimal'
139
+ 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}
141
+
142
+ type :to_s, '() -> String'
143
+ type :inspect, '() -> String'
144
+
36
145
  type :magnitude, '() -> Integer'
37
- rdl_alias :modulo, :%
146
+ post(:magnitude) { |r,x| r >= 0 }
147
+
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}
158
+
38
159
  type :next, '() -> Integer'
160
+
39
161
  type :odd?, '() -> %bool'
162
+
40
163
  type :size, '() -> Fixnum'
41
- rdl_alias :succ, :next
164
+
165
+ type :succ, '() -> Integer'
166
+
42
167
  type :to_f, '() -> Float'
43
- type :to_s, '(?Fixnum base) -> String'
168
+
44
169
  type :zero?, '() -> %bool'
170
+
171
+ type :ceil, '() -> Integer'
172
+
173
+ type :denominator, '() -> Fixnum'
174
+ post(:denominator) { |r,x| r == 1 }
175
+
176
+ type :floor, '() -> Integer'
177
+ type :numerator, '() -> Fixnum'
178
+
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}
189
+
190
+ type :rationalize, '() -> Rational'
191
+
192
+ type :rationalize, '(Numeric) -> Rational'
193
+
194
+ type :round, '() -> Integer'
195
+
196
+ type :round, '(Numeric) -> Numeric'
197
+ 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
+
199
+ type :to_i, '() -> Fixnum'
200
+
201
+ type :to_r, '() -> Rational'
202
+
203
+ type :truncate, '() -> Integer'
204
+
205
+ type :angle, '() -> Numeric'
206
+ post(:angle) { |r,x| r == 0 || r == Math::PI}
207
+
208
+ type :arg, '() -> Numeric'
209
+ post(:arg) { |r,x| r == 0 || r == Math::PI}
210
+
211
+ type :equal?, '(Object) -> %bool'
212
+ type :eql?, '(Object) -> %bool'
213
+
214
+ type :hash, '() -> Integer'
215
+
216
+ type :phase, '() -> Numeric'
217
+
218
+ type :abs2, '() -> Integer'
219
+ post(:abs2) { |r,x| r >= 0 }
220
+
221
+ type :conj, '() -> Fixnum'
222
+ type :conjugate, '() -> Fixnum'
223
+
224
+ type :imag, '() -> Fixnum'
225
+ post(:imag) { |r,x| r == 0 }
226
+ type :imaginary, '() -> Fixnum'
227
+ post(:imaginary) { |r,x| r == 0 }
228
+
229
+ type :real, '() -> Fixnum'
230
+
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]'
251
+ pre(:coerce) { |x| if x.is_a?(Complex) then x.imaginary==0 else true end}
45
252
  end
@@ -1,54 +1,236 @@
1
- class Float
1
+ class Float < Numeric
2
2
  rdl_nowrap
3
3
 
4
- type :%, '(Numeric other) -> Numeric'
5
- type :*, '(Numeric other) -> Numeric'
6
- type :**, '(Numeric other) -> Numeric'
7
- type :+, '(Numeric other) -> Numeric'
8
- type :-, '(Numeric other) -> Numeric'
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'
14
+ type :*, '(Float) -> Float'
15
+ type :*, '(Rational) -> Float'
16
+ type :*, '(BigDecimal) -> BigDecimal'
17
+ pre(:*) { self!=Float::INFINITY && !(self.nan?)}
18
+ type :*, '(Complex) -> Complex'
19
+ 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
+
21
+ type :**, '(Integer) -> Float'
22
+ type :**, '(Float) -> Numeric'
23
+ type :**, '(Rational) -> Numeric'
24
+ type :**, '(BigDecimal) -> BigDecimal'
25
+ pre(:**) { |x| x!=BigDecimal::INFINITY && if self<0 then x<=-1||x>=0 else true end}
26
+ post(:**) { |x| x.real?}
27
+ type :**, '(Complex) -> Complex'
28
+ 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
+
30
+ type :+, '(Integer) -> Float'
31
+ type :+, '(Float) -> Float'
32
+ type :+, '(Rational) -> Float'
33
+ type :+, '(BigDecimal) -> BigDecimal'
34
+ pre(:+) { self!=Float::INFINITY && !(self.nan?)}
35
+ type :+, '(Complex) -> Complex'
36
+ pre(:+) { |x| if x.real.is_a?(BigDecimal) then self!=Float::INFINITY && !(self.nan?) else true end}
37
+
38
+ type :-, '(Integer) -> Float'
39
+ type :-, '(Float) -> Float'
40
+ type :-, '(Rational) -> Float'
41
+ type :-, '(BigDecimal) -> BigDecimal'
42
+ pre(:-) { self!=Float::INFINITY && !(self.nan?)}
43
+ type :-, '(Complex) -> Complex'
44
+ pre(:-) { |x| if x.real.is_a?(BigDecimal) then self!=Float::INFINITY && !(self.nan?) else true end}
45
+
9
46
  type :-, '() -> Float'
10
- type :/, '(Numeric other) -> Float'
11
- type :<, '(Numeric) -> %bool'
12
- pre(:<) { |x| x.real? }
13
- type :<=, '(Numeric) -> %bool'
14
- pre(:<=) { |x| x.real? }
15
- type :<=>, '(Numeric) -> -1 or 0 or 1 or nil'
16
- pre(:<=>) { |x| x.real? }
17
- type :==, '(%any) -> %bool'
18
- type :>, '(Numeric) -> %bool'
19
- pre(:>) { |x| x.real? }
20
- type :>=, '(Numeric) -> %bool'
21
- pre(:>=) { |x| x.real? }
47
+
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'
60
+ type :<, '(Float) -> %bool'
61
+ type :<, '(Rational) -> %bool'
62
+ type :<, '(BigDecimal) -> %bool'
63
+ pre(:<) { !self.nan? && self!=Float::INFINITY}
64
+
65
+ type :<=, '(Integer) -> %bool'
66
+ type :<=, '(Float) -> %bool'
67
+ type :<=, '(Rational) -> %bool'
68
+ type :<=, '(BigDecimal) -> %bool'
69
+ pre(:<=) { !self.nan? && self!=Float::INFINITY}
70
+
71
+ type :<=>, '(Integer) -> Object'
72
+ post(:<=>) { |x| x == -1 || x==0 || x==1}
73
+ type :<=>, '(Float) -> Object'
74
+ post(:<=>) { |x| x == -1 || x==0 || x==1}
75
+ type :<=>, '(Rational) -> Object'
76
+ post(:<=>) { |x| x == -1 || x==0 || x==1}
77
+ type :<=>, '(BigDecimal) -> Object'
78
+ pre(:<=>) { !self.nan? && self!=Float::INFINITY}
79
+ post(:<=>) { |x| x == -1 || x==0 || x==1}
80
+
81
+ type :==, '(Object) -> %bool'
82
+ pre(:==) { |x| if (x.is_a?(BigDecimal)) then (!self.nan? && self!=Float::INFINITY) else true end}
83
+
84
+ type :===, '(Object) -> %bool'
85
+ pre(:===) { |x| if (x.is_a?(BigDecimal)) then (!self.nan? && self!=Float::INFINITY) else true end}
86
+
87
+ type :>, '(Integer) -> %bool'
88
+ type :>, '(Float) -> %bool'
89
+ type :>, '(Rational) -> %bool'
90
+ type :>, '(BigDecimal) -> %bool'
91
+ pre(:>) { !self.nan? && self!=Float::INFINITY}
92
+
93
+ type :>=, '(Integer) -> %bool'
94
+ type :>=, '(Float) -> %bool'
95
+ type :>=, '(Rational) -> %bool'
96
+ type :>=, '(BigDecimal) -> %bool'
97
+ pre(:>=) { !self.nan? && self!=Float::INFINITY}
98
+
22
99
  type :abs, '() -> Float'
23
- type :angle, '() -> 0 or ${Math::PI}'
24
- type :arg, '() -> 0 or ${Math::PI}'
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?}
115
+
116
+ type :divmod, '(%real) -> [%real, %real]'
117
+ pre(:divmod) { |x| x!=0 && if x.is_a?(Float) then !x.nan? else true end && self!=Float::INFINITY && !self.nan?}
118
+
119
+ type :angle, '() -> Numeric'
120
+ post(:angle) { |r,x| r == 0 || r == Math::PI || r == Float::NAN}
121
+
122
+ type :arg, '() -> Numeric'
123
+ post(:arg) { |r,x| r == 0 || r == Math::PI || r == Float::NAN}
124
+
25
125
  type :ceil, '() -> Integer'
26
- type :coerce, '(Numeric) -> [Float, Float]'
126
+ pre(:ceil) { self!=Float::INFINITY && !self.nan?}
127
+
128
+ type :coerce, '(%real) -> [Float, Float]'
129
+
27
130
  type :denominator, '() -> Integer'
28
- post(:denominator) { |r, _| r > 0 }
29
- type :divmod, '(Numeric) -> [Numeric, Numeric]'
30
- type :equl?, '(%any) -> %bool'
31
- type :fdiv, '(Numeric) -> Float'
131
+ post(:denominator) { |r,x| r > 0 }
132
+
133
+ type :equal?, '(Object) -> %bool'
134
+
135
+ type :eql?, '(Object) -> %bool'
136
+
137
+ type :fdiv, '(Integer) -> Float'
138
+ type :fdiv, '(Float) -> Float'
139
+ type :fdiv, '(Rational) -> Float'
140
+ type :fdiv, '(BigDecimal) -> BigDecimal'
141
+ pre(:fdiv) { self!=Float::INFINITY && !self.nan?}
142
+ type :fdiv, '(Complex) -> Complex'
143
+ 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
+
32
145
  type :finite?, '() -> %bool'
146
+
33
147
  type :floor, '() -> Integer'
148
+ pre(:ceil) { self!=Float::INFINITY && !self.nan?}
149
+
34
150
  type :hash, '() -> Integer'
35
- type :infinite?, '() -> -1 or 1 or nil'
36
- rdl_alias :inspect, :to_s
151
+
152
+ type :infinite?, '() -> Object'
153
+ post(:infinite?) { |r,x| r == -1 || r == 1 || r == nil }
154
+
155
+ type :to_s, '() -> String'
156
+ type :inspect, '() -> String'
157
+
37
158
  type :magnitude, '() -> Float'
38
- rdl_alias :modulo, :%
159
+ post(:magnitude) { |r,x| r>=0 }
160
+
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?}
169
+
39
170
  type :nan?, '() -> %bool'
171
+
40
172
  type :next_float, '() -> Float'
173
+
41
174
  type :numerator, '() -> Integer'
42
- type :phase, '() -> 0 or ${Math::PI}'
175
+
176
+ type :phase, '() -> Numeric'
177
+ post(:phase) { |r,x| r == 0 || r == Math::PI || r == Float::NAN}
178
+
43
179
  type :prev_float, '() -> Float'
44
- rdl_alias :quo, :/
45
- type :rationalize, '(Float eps) -> Rational'
46
- type :round, '(?Fixnum ndigits) -> Integer or Float'
47
- type :to_f, '() -> self'
180
+
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}
191
+
192
+ type :rationalize, '() -> Rational'
193
+ pre(:rationalize) { self!=Float::INFINITY && !self.nan?}
194
+
195
+ type :rationalize, '(Numeric) -> Rational'
196
+ pre(:rationalize) { |x| if x.is_a?(Float) then x!=Float::INFINITY && !x.nan? else true end}
197
+
198
+ type :round, '() -> Integer'
199
+ pre(:round) { self!=Float::INFINITY && !self.nan?}
200
+
201
+ type :round, '(Numeric) -> Numeric'
202
+ 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
+
204
+ type :to_f, '() -> Float'
205
+
48
206
  type :to_i, '() -> Integer'
49
- rdl_alias :to_int, :to_i
207
+ pre(:to_i) { self!=Float::INFINITY && !self.nan?}
208
+
209
+ type :to_int, '() -> Integer'
210
+ pre(:to_int) { self!=Float::INFINITY && !self.nan?}
211
+
50
212
  type :to_r, '() -> Rational'
51
- type :to_s, '() -> String'
213
+ pre(:to_r) { self!=Float::INFINITY && !self.nan?}
214
+
52
215
  type :truncate, '() -> Integer'
216
+
53
217
  type :zero?, '() -> %bool'
218
+
219
+ type :conj, '() -> Float'
220
+ type :conjugate, '() -> Float'
221
+
222
+ type :imag, '() -> Fixnum'
223
+ post(:imag) { |r,x| r == 0 }
224
+ type :imaginary, '() -> Fixnum'
225
+ post(:imaginary) { |r,x| r == 0 }
226
+
227
+ type :real, '() -> Float'
228
+
229
+ type :real?, '() -> TrueClass'
230
+
231
+ type :to_c, '() -> Complex'
232
+ post(:to_c) { |r,x| r.imaginary == 0 }
233
+
234
+ type :coerce, '(Numeric) -> [Float, Float]'
235
+ pre(:coerce) { |x| if x.is_a?(Complex) then x.imaginary==0 else true end}
54
236
  end