Revision 12
Added by over 7 years ago
Operations.java | ||
---|---|---|
57 | 57 |
@Override |
58 | 58 |
public AbstractRange GenericArithmeticCover(AbstractRange type1, AbstractRange type2, ExpressionKind op) |
59 | 59 |
{ |
60 |
Range<T> a = (Range<T>) type1; |
|
61 |
Range<T> b = (Range<T>) type2; |
|
60 |
final Range<T> a = (Range<T>) type1;
|
|
61 |
final Range<T> b = (Range<T>) type2;
|
|
62 | 62 |
|
63 | 63 |
// Range<T> a = type1 as Range<T>; |
64 | 64 |
// Range<T> b = type2 as Range<T>; |
... | ... | |
71 | 71 |
|
72 | 72 |
public Range<T> GenericArithmeticCover(Range<T> type1, Range<T> type2, ExpressionKind op) |
73 | 73 |
{ |
74 |
T defaultValue = m_basicOperations.getDefaultValue(); |
|
75 |
Range<T> result = type1.Create(defaultValue, defaultValue); |
|
74 |
final T defaultValue = m_basicOperations.getDefaultValue();
|
|
75 |
final Range<T> result = type1.Create(defaultValue, defaultValue);
|
|
76 | 76 |
|
77 | 77 |
switch (op) |
78 | 78 |
{ |
... | ... | |
87 | 87 |
assert(type2 != null); |
88 | 88 |
// we do some sort of resulttype = type1 - type2 |
89 | 89 |
// hence, do the unminus stuff with type 2 |
90 |
T spare = type2.max; |
|
90 |
final T spare = type2.max;
|
|
91 | 91 |
type2.max = m_basicOperations.unMinus(type2.min); |
92 | 92 |
type2.min = m_basicOperations.unMinus(spare); |
93 | 93 |
// now it's the same as with sum.. but c# does not let us fall through.. |
... | ... | |
101 | 101 |
break; |
102 | 102 |
case idiv: |
103 | 103 |
case div: |
104 |
// get the closest values to 0 for the divisor. |
|
104 | 105 |
assert(type2 != null); |
105 |
type2.min = m_basicOperations.equal(type2.min, defaultValue) ? |
|
106 |
m_basicOperations.unMinus(type2.precision) : type2.min; |
|
107 |
type2.max = m_basicOperations.equal(type2.max, defaultValue) ? |
|
108 |
type2.precision : type2.max; |
|
109 |
// hmm, brute force.. is there some formula? |
|
110 |
result.max = m_basicOperations.div(type1.min, type2.min); |
|
106 |
final Range<T> closestToZero = type2.Create(defaultValue, defaultValue); |
|
107 |
if (m_basicOperations.greater(type2.max, defaultValue) && (m_basicOperations.greater(type2.min, defaultValue) || m_basicOperations.equal(type2.min, defaultValue))) { |
|
108 |
// divisor range [X...0+] |
|
109 |
closestToZero.max = m_basicOperations.equal(type2.min, defaultValue) ? type2.precision : type2.min; // type2.min or type2.precision if that was 0 |
|
110 |
closestToZero.min = closestToZero.max; |
|
111 |
} else if (m_basicOperations.smaller(type2.max, defaultValue) && (m_basicOperations.smaller(type2.min, defaultValue) || m_basicOperations.equal(type2.min, defaultValue))) { |
|
112 |
// divisor range [0-...-X] |
|
113 |
closestToZero.max = m_basicOperations.equal(type2.min, defaultValue) ? m_basicOperations.unMinus(type2.precision) : type2.min; // type2.min or -type2.precision if that was 0 |
|
114 |
closestToZero.min = closestToZero.max; |
|
115 |
} else { |
|
116 |
// divisor range [Y ... -X] |
|
117 |
closestToZero.max = type2.precision; |
|
118 |
closestToZero.min = m_basicOperations.unMinus(type2.precision); |
|
119 |
} |
|
120 |
|
|
121 |
result.max = m_basicOperations.div(type1.min, closestToZero.min); |
|
111 | 122 |
result.min = result.max; |
112 | 123 |
|
113 |
T tmp = m_basicOperations.div(type1.max, type2.min);
|
|
124 |
T tmp = m_basicOperations.div(type1.max, closestToZero.min);
|
|
114 | 125 |
result.max = m_basicOperations.smaller(result.max, tmp) ? tmp : result.max; |
115 | 126 |
result.min = m_basicOperations.greater(result.min, tmp) ? tmp : result.min; |
116 | 127 |
|
117 |
tmp = m_basicOperations.div(type1.min, type2.max);
|
|
128 |
tmp = m_basicOperations.div(type1.min, closestToZero.max);
|
|
118 | 129 |
result.max = m_basicOperations.smaller(result.max, tmp) ? tmp : result.max; |
119 | 130 |
result.min = m_basicOperations.greater(result.min, tmp) ? tmp : result.min; |
120 | 131 |
|
121 |
tmp = m_basicOperations.div(type1.max, type2.max);
|
|
132 |
tmp = m_basicOperations.div(type1.max, closestToZero.max);
|
|
122 | 133 |
result.max = m_basicOperations.smaller(result.max, tmp) ? tmp : result.max; |
123 | 134 |
result.min = m_basicOperations.greater(result.min, tmp) ? tmp : result.min; |
124 | 135 |
break; |
Also available in: Unified diff
latest version of the ooas compiler, with grammar version 1.10