1 19 20 25 26 27 28 29 30 package soot.jimple; 31 32 import soot.*; 33 import soot.util.*; 34 import java.util.*; 35 36 public class DoubleConstant extends RealConstant 37 { 38 public final double value; 39 40 private DoubleConstant(double value) 41 { 42 this.value = value; 43 } 44 45 public static DoubleConstant v(double value) 46 { 47 return new DoubleConstant(value); 48 } 49 50 public boolean equals(Object c) 51 { 52 return (c instanceof DoubleConstant && ((DoubleConstant) c).value == this.value); 53 } 54 55 56 public int hashCode() 57 { 58 long v = Double.doubleToLongBits(value); 59 return (int)(v^(v>>>32)); 60 } 61 62 public NumericConstant add(NumericConstant c) 64 { 65 if (!(c instanceof DoubleConstant)) 66 throw new IllegalArgumentException ("DoubleConstant expected"); 67 return DoubleConstant.v(this.value + ((DoubleConstant)c).value); 68 } 69 70 public NumericConstant subtract(NumericConstant c) 71 { 72 if (!(c instanceof DoubleConstant)) 73 throw new IllegalArgumentException ("DoubleConstant expected"); 74 return DoubleConstant.v(this.value - ((DoubleConstant)c).value); 75 } 76 77 public NumericConstant multiply(NumericConstant c) 78 { 79 if (!(c instanceof DoubleConstant)) 80 throw new IllegalArgumentException ("DoubleConstant expected"); 81 return DoubleConstant.v(this.value * ((DoubleConstant)c).value); 82 } 83 84 public NumericConstant divide(NumericConstant c) 85 { 86 if (!(c instanceof DoubleConstant)) 87 throw new IllegalArgumentException ("DoubleConstant expected"); 88 return DoubleConstant.v(this.value / ((DoubleConstant)c).value); 89 } 90 91 public NumericConstant remainder(NumericConstant c) 92 { 93 if (!(c instanceof DoubleConstant)) 94 throw new IllegalArgumentException ("DoubleConstant expected"); 95 return DoubleConstant.v(this.value % ((DoubleConstant)c).value); 96 } 97 98 public NumericConstant equalEqual(NumericConstant c) 99 { 100 if (!(c instanceof DoubleConstant)) 101 throw new IllegalArgumentException ("DoubleConstant expected"); 102 return IntConstant.v((this.value == ((DoubleConstant)c).value) ? 1 : 0); 103 } 104 105 public NumericConstant notEqual(NumericConstant c) 106 { 107 if (!(c instanceof DoubleConstant)) 108 throw new IllegalArgumentException ("DoubleConstant expected"); 109 return IntConstant.v((this.value != ((DoubleConstant)c).value) ? 1 : 0); 110 } 111 112 public NumericConstant lessThan(NumericConstant c) 113 { 114 if (!(c instanceof DoubleConstant)) 115 throw new IllegalArgumentException ("DoubleConstant expected"); 116 return IntConstant.v((this.value < ((DoubleConstant)c).value) ? 1 : 0); 117 } 118 119 public NumericConstant lessThanOrEqual(NumericConstant c) 120 { 121 if (!(c instanceof DoubleConstant)) 122 throw new IllegalArgumentException ("DoubleConstant expected"); 123 return IntConstant.v((this.value <= ((DoubleConstant)c).value) ? 1 : 0); 124 } 125 126 public NumericConstant greaterThan(NumericConstant c) 127 { 128 if (!(c instanceof DoubleConstant)) 129 throw new IllegalArgumentException ("DoubleConstant expected"); 130 return IntConstant.v((this.value > ((DoubleConstant)c).value) ? 1 : 0); 131 } 132 133 public NumericConstant greaterThanOrEqual(NumericConstant c) 134 { 135 if (!(c instanceof DoubleConstant)) 136 throw new IllegalArgumentException ("DoubleConstant expected"); 137 return IntConstant.v((this.value >= ((DoubleConstant)c).value) ? 1 : 0); 138 } 139 140 public IntConstant cmpg(RealConstant c) { 141 if (!(c instanceof DoubleConstant)) 142 throw new IllegalArgumentException ("DoubleConstant expected"); 143 double cValue = ((DoubleConstant) c).value; 144 if (this.value < cValue) 145 return IntConstant.v(-1); 146 else if (this.value == cValue) 147 return IntConstant.v(0); 148 else 149 return IntConstant.v(1); 150 } 151 152 public IntConstant cmpl(RealConstant c) { 153 if (!(c instanceof DoubleConstant)) 154 throw new IllegalArgumentException ("DoubleConstant expected"); 155 double cValue = ((DoubleConstant) c).value; 156 if (this.value > cValue) 157 return IntConstant.v(1); 158 else if (this.value == cValue) 159 return IntConstant.v(0); 160 else 161 return IntConstant.v(-1); 162 } 163 164 public NumericConstant negate() 165 { 166 return DoubleConstant.v(-(this.value)); 167 } 168 169 public String toString() 170 { 171 String doubleString = new Double (value).toString(); 172 173 if(doubleString.equals("NaN") || 174 doubleString.equals("Infinity") || 175 doubleString.equals("-Infinity")) 176 return "#" + doubleString; 177 else 178 return doubleString; 179 } 180 181 public Type getType() 182 { 183 return DoubleType.v(); 184 } 185 186 public void apply(Switch sw) 187 { 188 ((ConstantSwitch) sw).caseDoubleConstant(this); 189 } 190 } 191 | Popular Tags |