1/*
2 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3 *             of Java bytecode.
4 *
5 * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21package proguard.evaluation.value;
22
23import proguard.classfile.ClassConstants;
24
25/**
26 * This class represents a partially evaluated double value.
27 *
28 * @author Eric Lafortune
29 */
30public abstract class DoubleValue extends Category2Value
31{
32    /**
33     * Returns the specific double value, if applicable.
34     */
35    public double value()
36    {
37        return 0.0;
38    }
39
40
41    // Basic unary methods.
42
43    /**
44     * Returns the negated value of this DoubleValue.
45     */
46    public abstract DoubleValue negate();
47
48    /**
49     * Converts this DoubleValue to an IntegerValue.
50     */
51    public abstract IntegerValue convertToInteger();
52
53    /**
54     * Converts this DoubleValue to a LongValue.
55     */
56    public abstract LongValue convertToLong();
57
58    /**
59     * Converts this DoubleValue to a FloatValue.
60     */
61    public abstract FloatValue convertToFloat();
62
63
64    // Basic binary methods.
65
66    /**
67     * Returns the generalization of this DoubleValue and the given other
68     * DoubleValue.
69     */
70    public abstract DoubleValue generalize(DoubleValue other);
71
72
73    /**
74     * Returns the sum of this DoubleValue and the given DoubleValue.
75     */
76    public abstract DoubleValue add(DoubleValue other);
77
78    /**
79     * Returns the difference of this DoubleValue and the given DoubleValue.
80     */
81    public abstract DoubleValue subtract(DoubleValue other);
82
83    /**
84     * Returns the difference of the given DoubleValue and this DoubleValue.
85     */
86    public abstract DoubleValue subtractFrom(DoubleValue other);
87
88    /**
89     * Returns the product of this DoubleValue and the given DoubleValue.
90     */
91    public abstract DoubleValue multiply(DoubleValue other);
92
93    /**
94     * Returns the quotient of this DoubleValue and the given DoubleValue.
95     */
96    public abstract DoubleValue divide(DoubleValue other);
97
98    /**
99     * Returns the quotient of the given DoubleValue and this DoubleValue.
100     */
101    public abstract DoubleValue divideOf(DoubleValue other);
102
103    /**
104     * Returns the remainder of this DoubleValue divided by the given DoubleValue.
105     */
106    public abstract DoubleValue remainder(DoubleValue other);
107
108    /**
109     * Returns the remainder of the given DoubleValue divided by this DoubleValue.
110     */
111    public abstract DoubleValue remainderOf(DoubleValue other);
112
113    /**
114     * Returns an IntegerValue with value -1, 0, or 1, if this DoubleValue is
115     * less than, equal to, or greater than the given DoubleValue, respectively.
116     */
117    public abstract IntegerValue compare(DoubleValue other);
118
119
120    // Derived binary methods.
121
122    /**
123     * Returns an IntegerValue with value 1, 0, or -1, if this DoubleValue is
124     * less than, equal to, or greater than the given DoubleValue, respectively.
125     */
126    public final IntegerValue compareReverse(DoubleValue other)
127    {
128        return compare(other).negate();
129    }
130
131
132    // Similar binary methods, but this time with more specific arguments.
133
134    /**
135     * Returns the generalization of this DoubleValue and the given other
136     * SpecificDoubleValue.
137     */
138    public DoubleValue generalize(SpecificDoubleValue other)
139    {
140        return generalize((DoubleValue)other);
141    }
142
143
144    /**
145     * Returns the sum of this DoubleValue and the given SpecificDoubleValue.
146     */
147    public DoubleValue add(SpecificDoubleValue other)
148    {
149        return add((DoubleValue)other);
150    }
151
152    /**
153     * Returns the difference of this DoubleValue and the given SpecificDoubleValue.
154     */
155    public DoubleValue subtract(SpecificDoubleValue other)
156    {
157        return subtract((DoubleValue)other);
158    }
159
160    /**
161     * Returns the difference of the given SpecificDoubleValue and this DoubleValue.
162     */
163    public DoubleValue subtractFrom(SpecificDoubleValue other)
164    {
165        return subtractFrom((DoubleValue)other);
166    }
167
168    /**
169     * Returns the product of this DoubleValue and the given SpecificDoubleValue.
170     */
171    public DoubleValue multiply(SpecificDoubleValue other)
172    {
173        return multiply((DoubleValue)other);
174    }
175
176    /**
177     * Returns the quotient of this DoubleValue and the given SpecificDoubleValue.
178     */
179    public DoubleValue divide(SpecificDoubleValue other)
180    {
181        return divide((DoubleValue)other);
182    }
183
184    /**
185     * Returns the quotient of the given SpecificDoubleValue and this
186     * DoubleValue.
187     */
188    public DoubleValue divideOf(SpecificDoubleValue other)
189    {
190        return divideOf((DoubleValue)other);
191    }
192
193    /**
194     * Returns the remainder of this DoubleValue divided by the given
195     * SpecificDoubleValue.
196     */
197    public DoubleValue remainder(SpecificDoubleValue other)
198    {
199        return remainder((DoubleValue)other);
200    }
201
202    /**
203     * Returns the remainder of the given SpecificDoubleValue and this
204     * DoubleValue.
205     */
206    public DoubleValue remainderOf(SpecificDoubleValue other)
207    {
208        return remainderOf((DoubleValue)other);
209    }
210
211    /**
212     * Returns an IntegerValue with value -1, 0, or 1, if this DoubleValue is
213     * less than, equal to, or greater than the given SpecificDoubleValue,
214     * respectively.
215     */
216    public IntegerValue compare(SpecificDoubleValue other)
217    {
218        return compare((DoubleValue)other);
219    }
220
221
222    // Derived binary methods.
223
224    /**
225     * Returns an IntegerValue with value 1, 0, or -1, if this DoubleValue is
226     * less than, equal to, or greater than the given SpecificDoubleValue,
227     * respectively.
228     */
229    public final IntegerValue compareReverse(SpecificDoubleValue other)
230    {
231        return compare(other).negate();
232    }
233
234
235    // Similar binary methods, but this time with particular arguments.
236
237    /**
238     * Returns the generalization of this DoubleValue and the given other
239     * ParticularDoubleValue.
240     */
241    public DoubleValue generalize(ParticularDoubleValue other)
242    {
243        return generalize((SpecificDoubleValue)other);
244    }
245
246
247    /**
248     * Returns the sum of this DoubleValue and the given ParticularDoubleValue.
249     */
250    public DoubleValue add(ParticularDoubleValue other)
251    {
252        return add((SpecificDoubleValue)other);
253    }
254
255    /**
256     * Returns the difference of this DoubleValue and the given ParticularDoubleValue.
257     */
258    public DoubleValue subtract(ParticularDoubleValue other)
259    {
260        return subtract((SpecificDoubleValue)other);
261    }
262
263    /**
264     * Returns the difference of the given ParticularDoubleValue and this DoubleValue.
265     */
266    public DoubleValue subtractFrom(ParticularDoubleValue other)
267    {
268        return subtractFrom((SpecificDoubleValue)other);
269    }
270
271    /**
272     * Returns the product of this DoubleValue and the given ParticularDoubleValue.
273     */
274    public DoubleValue multiply(ParticularDoubleValue other)
275    {
276        return multiply((SpecificDoubleValue)other);
277    }
278
279    /**
280     * Returns the quotient of this DoubleValue and the given ParticularDoubleValue.
281     */
282    public DoubleValue divide(ParticularDoubleValue other)
283    {
284        return divide((SpecificDoubleValue)other);
285    }
286
287    /**
288     * Returns the quotient of the given ParticularDoubleValue and this
289     * DoubleValue.
290     */
291    public DoubleValue divideOf(ParticularDoubleValue other)
292    {
293        return divideOf((SpecificDoubleValue)other);
294    }
295
296    /**
297     * Returns the remainder of this DoubleValue divided by the given
298     * ParticularDoubleValue.
299     */
300    public DoubleValue remainder(ParticularDoubleValue other)
301    {
302        return remainder((SpecificDoubleValue)other);
303    }
304
305    /**
306     * Returns the remainder of the given ParticularDoubleValue and this
307     * DoubleValue.
308     */
309    public DoubleValue remainderOf(ParticularDoubleValue other)
310    {
311        return remainderOf((SpecificDoubleValue)other);
312    }
313
314    /**
315     * Returns an IntegerValue with value -1, 0, or 1, if this DoubleValue is
316     * less than, equal to, or greater than the given ParticularDoubleValue,
317     * respectively.
318     */
319    public IntegerValue compare(ParticularDoubleValue other)
320    {
321        return compare((SpecificDoubleValue)other);
322    }
323
324
325    // Derived binary methods.
326
327    /**
328     * Returns an IntegerValue with value 1, 0, or -1, if this DoubleValue is
329     * less than, equal to, or greater than the given ParticularDoubleValue,
330     * respectively.
331     */
332    public final IntegerValue compareReverse(ParticularDoubleValue other)
333    {
334        return compare(other).negate();
335    }
336
337
338    // Implementations for Value.
339
340    public final DoubleValue doubleValue()
341    {
342        return this;
343    }
344
345    public final Value generalize(Value other)
346    {
347        return this.generalize(other.doubleValue());
348    }
349
350    public final int computationalType()
351    {
352        return TYPE_DOUBLE;
353    }
354
355    public final String internalType()
356    {
357        return String.valueOf(ClassConstants.INTERNAL_TYPE_DOUBLE);
358    }
359}
360