home *** CD-ROM | disk | FTP | other *** search
- package java.text;
-
- final class DigitList implements Cloneable {
- public static final int MAX_COUNT = 19;
- public static final int DBL_DIG = 17;
- public int decimalAt = 0;
- public int count = 0;
- public byte[] digits = new byte[19];
- private static final boolean DEBUG = false;
- private static byte[] LONG_MIN_REP;
- private static final double LOG10;
-
- boolean isZero() {
- for(int var1 = 0; var1 < this.count; ++var1) {
- if (this.digits[var1] != 48) {
- return false;
- }
- }
-
- return true;
- }
-
- public void clear() {
- this.decimalAt = 0;
- this.count = 0;
- }
-
- public void append(int var1) {
- if (this.count < 19) {
- this.digits[this.count++] = (byte)var1;
- }
-
- }
-
- public final double getDouble() {
- if (this.count == 0) {
- return (double)0.0F;
- } else {
- StringBuffer var1 = new StringBuffer(this.count);
- var1.append('.');
-
- for(int var2 = 0; var2 < this.count; ++var2) {
- var1.append((char)this.digits[var2]);
- }
-
- var1.append('E');
- var1.append(Integer.toString(this.decimalAt));
- return Double.valueOf(var1.toString());
- }
- }
-
- public final long getLong() {
- if (this.count == 0) {
- return 0L;
- } else if (this.isLongMIN_VALUE()) {
- return Long.MIN_VALUE;
- } else {
- StringBuffer var1 = new StringBuffer(this.count);
-
- for(int var2 = 0; var2 < this.decimalAt; ++var2) {
- var1.append(var2 < this.count ? (char)this.digits[var2] : '0');
- }
-
- return Long.parseLong(var1.toString());
- }
- }
-
- boolean fitsIntoLong(boolean var1, boolean var2) {
- while(this.count > 0 && this.digits[this.count - 1] == 48) {
- --this.count;
- }
-
- if (this.count != 0) {
- if (this.decimalAt >= this.count && this.decimalAt <= 19) {
- if (this.decimalAt < 19) {
- return true;
- } else {
- for(int var3 = 0; var3 < this.count; ++var3) {
- byte var4 = this.digits[var3];
- byte var5 = LONG_MIN_REP[var3];
- if (var4 > var5) {
- return false;
- }
-
- if (var4 < var5) {
- return true;
- }
- }
-
- if (this.count < this.decimalAt) {
- return true;
- } else {
- return !var1;
- }
- }
- } else {
- return false;
- }
- } else {
- return var1 || var2;
- }
- }
-
- public final void set(double var1, int var3) {
- this.set(var1, var3, true);
- }
-
- final void set(double var1, int var3, boolean var4) {
- if (var1 == (double)0.0F) {
- var1 = (double)0.0F;
- }
-
- String var5 = Double.toString(var1);
- this.decimalAt = -1;
- this.count = 0;
- int var6 = 0;
- int var7 = 0;
- boolean var8 = false;
-
- for(int var9 = 0; var9 < var5.length(); ++var9) {
- char var10 = var5.charAt(var9);
- if (var10 == '.') {
- this.decimalAt = this.count;
- } else {
- if (var10 == 'e' || var10 == 'E') {
- var6 = Integer.valueOf(var5.substring(var9 + 1));
- break;
- }
-
- if (this.count < 19) {
- if (!var8) {
- var8 = var10 != '0';
- if (!var8 && this.decimalAt != -1) {
- ++var7;
- }
- }
-
- if (var8) {
- this.digits[this.count++] = (byte)var10;
- }
- }
- }
- }
-
- if (this.decimalAt == -1) {
- this.decimalAt = this.count;
- }
-
- if (var8) {
- this.decimalAt += var6 - var7;
- }
-
- if (var4) {
- if (-this.decimalAt > var3) {
- this.count = 0;
- return;
- }
-
- if (-this.decimalAt == var3) {
- if (this.shouldRoundUp(0)) {
- this.count = 1;
- ++this.decimalAt;
- this.digits[0] = 49;
- } else {
- this.count = 0;
- }
-
- return;
- }
- }
-
- while(this.count > 1 && this.digits[this.count - 1] == 48) {
- --this.count;
- }
-
- this.round(var4 ? var3 + this.decimalAt : var3);
- }
-
- private final void round(int var1) {
- if (var1 >= 0 && var1 < this.count) {
- if (this.shouldRoundUp(var1)) {
- do {
- --var1;
- if (var1 < 0) {
- this.digits[0] = 49;
- ++this.decimalAt;
- var1 = 0;
- break;
- }
-
- ++this.digits[var1];
- } while(this.digits[var1] > 57);
-
- ++var1;
- }
-
- for(this.count = var1; this.count > 1 && this.digits[this.count - 1] == 48; --this.count) {
- }
- }
-
- }
-
- private boolean shouldRoundUp(int var1) {
- boolean var2 = false;
- if (var1 < this.count) {
- if (this.digits[var1] > 53) {
- return true;
- }
-
- if (this.digits[var1] == 53) {
- for(int var3 = var1 + 1; var3 < this.count; ++var3) {
- if (this.digits[var3] != 48) {
- return true;
- }
- }
-
- return var1 > 0 && this.digits[var1 - 1] % 2 != 0;
- }
- }
-
- return false;
- }
-
- public final void set(long var1) {
- this.set(var1, 0);
- }
-
- public final void set(long var1, int var3) {
- if (var1 <= 0L) {
- if (var1 == Long.MIN_VALUE) {
- this.decimalAt = this.count = 19;
- System.arraycopy(LONG_MIN_REP, 0, this.digits, 0, this.count);
- } else {
- this.decimalAt = this.count = 0;
- }
- } else {
- int var4;
- for(var4 = 19; var1 > 0L; var1 /= 10L) {
- --var4;
- this.digits[var4] = (byte)((int)(48L + var1 % 10L));
- }
-
- this.decimalAt = 19 - var4;
-
- int var5;
- for(var5 = 18; this.digits[var5] == 48; --var5) {
- }
-
- this.count = var5 - var4 + 1;
- System.arraycopy(this.digits, var4, this.digits, 0, this.count);
- }
-
- if (var3 > 0) {
- this.round(var3);
- }
-
- }
-
- public boolean equals(Object var1) {
- if (this == var1) {
- return true;
- } else if (!(var1 instanceof DigitList)) {
- return false;
- } else {
- DigitList var2 = (DigitList)var1;
- if (this.count == var2.count && this.decimalAt == var2.decimalAt) {
- for(int var3 = 0; var3 < this.count; ++var3) {
- if (this.digits[var3] != var2.digits[var3]) {
- return false;
- }
- }
-
- return true;
- } else {
- return false;
- }
- }
- }
-
- public int hashCode() {
- int var1 = this.decimalAt;
-
- for(int var2 = 0; var2 < this.count; ++var2) {
- var1 = var1 * 37 + this.digits[var2];
- }
-
- return var1;
- }
-
- private boolean isLongMIN_VALUE() {
- if (this.decimalAt == this.count && this.count == 19) {
- for(int var1 = 0; var1 < this.count; ++var1) {
- if (this.digits[var1] != LONG_MIN_REP[var1]) {
- return false;
- }
- }
-
- return true;
- } else {
- return false;
- }
- }
-
- private static final int log10(double var0) {
- double var2 = Math.log(var0) / LOG10;
- int var4 = (int)Math.floor(var2);
- if (var2 > (double)0.0F && var0 >= Math.pow((double)10.0F, (double)(var4 + 1))) {
- ++var4;
- } else if (var2 < (double)0.0F && var0 < Math.pow((double)10.0F, (double)var4)) {
- --var4;
- }
-
- return var4;
- }
-
- public String toString() {
- if (this.isZero()) {
- return "0";
- } else {
- StringBuffer var1 = new StringBuffer("0.");
-
- for(int var2 = 0; var2 < this.count; ++var2) {
- var1.append((char)this.digits[var2]);
- }
-
- var1.append("x10^");
- var1.append(this.decimalAt);
- return var1.toString();
- }
- }
-
- static {
- String var0 = Long.toString(Long.MIN_VALUE);
- LONG_MIN_REP = new byte[19];
-
- for(int var1 = 0; var1 < 19; ++var1) {
- LONG_MIN_REP[var1] = (byte)var0.charAt(var1 + 1);
- }
-
- LOG10 = Math.log((double)10.0F);
- }
- }
-