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