home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / text / DigitList.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  3.6 KB  |  343 lines

  1. package java.text;
  2.  
  3. final class DigitList implements Cloneable {
  4.    public static final int MAX_COUNT = 19;
  5.    public static final int DBL_DIG = 17;
  6.    public int decimalAt = 0;
  7.    public int count = 0;
  8.    public byte[] digits = new byte[19];
  9.    private static final boolean DEBUG = false;
  10.    private static byte[] LONG_MIN_REP;
  11.    private static final double LOG10;
  12.  
  13.    boolean isZero() {
  14.       for(int var1 = 0; var1 < this.count; ++var1) {
  15.          if (this.digits[var1] != 48) {
  16.             return false;
  17.          }
  18.       }
  19.  
  20.       return true;
  21.    }
  22.  
  23.    public void clear() {
  24.       this.decimalAt = 0;
  25.       this.count = 0;
  26.    }
  27.  
  28.    public void append(int var1) {
  29.       if (this.count < 19) {
  30.          this.digits[this.count++] = (byte)var1;
  31.       }
  32.  
  33.    }
  34.  
  35.    public final double getDouble() {
  36.       if (this.count == 0) {
  37.          return (double)0.0F;
  38.       } else {
  39.          StringBuffer var1 = new StringBuffer(this.count);
  40.          var1.append('.');
  41.  
  42.          for(int var2 = 0; var2 < this.count; ++var2) {
  43.             var1.append((char)this.digits[var2]);
  44.          }
  45.  
  46.          var1.append('E');
  47.          var1.append(Integer.toString(this.decimalAt));
  48.          return Double.valueOf(var1.toString());
  49.       }
  50.    }
  51.  
  52.    public final long getLong() {
  53.       if (this.count == 0) {
  54.          return 0L;
  55.       } else if (this.isLongMIN_VALUE()) {
  56.          return Long.MIN_VALUE;
  57.       } else {
  58.          StringBuffer var1 = new StringBuffer(this.count);
  59.  
  60.          for(int var2 = 0; var2 < this.decimalAt; ++var2) {
  61.             var1.append(var2 < this.count ? (char)this.digits[var2] : '0');
  62.          }
  63.  
  64.          return Long.parseLong(var1.toString());
  65.       }
  66.    }
  67.  
  68.    boolean fitsIntoLong(boolean var1, boolean var2) {
  69.       while(this.count > 0 && this.digits[this.count - 1] == 48) {
  70.          --this.count;
  71.       }
  72.  
  73.       if (this.count != 0) {
  74.          if (this.decimalAt >= this.count && this.decimalAt <= 19) {
  75.             if (this.decimalAt < 19) {
  76.                return true;
  77.             } else {
  78.                for(int var3 = 0; var3 < this.count; ++var3) {
  79.                   byte var4 = this.digits[var3];
  80.                   byte var5 = LONG_MIN_REP[var3];
  81.                   if (var4 > var5) {
  82.                      return false;
  83.                   }
  84.  
  85.                   if (var4 < var5) {
  86.                      return true;
  87.                   }
  88.                }
  89.  
  90.                if (this.count < this.decimalAt) {
  91.                   return true;
  92.                } else {
  93.                   return !var1;
  94.                }
  95.             }
  96.          } else {
  97.             return false;
  98.          }
  99.       } else {
  100.          return var1 || var2;
  101.       }
  102.    }
  103.  
  104.    public final void set(double var1, int var3) {
  105.       this.set(var1, var3, true);
  106.    }
  107.  
  108.    final void set(double var1, int var3, boolean var4) {
  109.       if (var1 == (double)0.0F) {
  110.          var1 = (double)0.0F;
  111.       }
  112.  
  113.       String var5 = Double.toString(var1);
  114.       this.decimalAt = -1;
  115.       this.count = 0;
  116.       int var6 = 0;
  117.       int var7 = 0;
  118.       boolean var8 = false;
  119.  
  120.       for(int var9 = 0; var9 < var5.length(); ++var9) {
  121.          char var10 = var5.charAt(var9);
  122.          if (var10 == '.') {
  123.             this.decimalAt = this.count;
  124.          } else {
  125.             if (var10 == 'e' || var10 == 'E') {
  126.                var6 = Integer.valueOf(var5.substring(var9 + 1));
  127.                break;
  128.             }
  129.  
  130.             if (this.count < 19) {
  131.                if (!var8) {
  132.                   var8 = var10 != '0';
  133.                   if (!var8 && this.decimalAt != -1) {
  134.                      ++var7;
  135.                   }
  136.                }
  137.  
  138.                if (var8) {
  139.                   this.digits[this.count++] = (byte)var10;
  140.                }
  141.             }
  142.          }
  143.       }
  144.  
  145.       if (this.decimalAt == -1) {
  146.          this.decimalAt = this.count;
  147.       }
  148.  
  149.       if (var8) {
  150.          this.decimalAt += var6 - var7;
  151.       }
  152.  
  153.       if (var4) {
  154.          if (-this.decimalAt > var3) {
  155.             this.count = 0;
  156.             return;
  157.          }
  158.  
  159.          if (-this.decimalAt == var3) {
  160.             if (this.shouldRoundUp(0)) {
  161.                this.count = 1;
  162.                ++this.decimalAt;
  163.                this.digits[0] = 49;
  164.             } else {
  165.                this.count = 0;
  166.             }
  167.  
  168.             return;
  169.          }
  170.       }
  171.  
  172.       while(this.count > 1 && this.digits[this.count - 1] == 48) {
  173.          --this.count;
  174.       }
  175.  
  176.       this.round(var4 ? var3 + this.decimalAt : var3);
  177.    }
  178.  
  179.    private final void round(int var1) {
  180.       if (var1 >= 0 && var1 < this.count) {
  181.          if (this.shouldRoundUp(var1)) {
  182.             do {
  183.                --var1;
  184.                if (var1 < 0) {
  185.                   this.digits[0] = 49;
  186.                   ++this.decimalAt;
  187.                   var1 = 0;
  188.                   break;
  189.                }
  190.  
  191.                ++this.digits[var1];
  192.             } while(this.digits[var1] > 57);
  193.  
  194.             ++var1;
  195.          }
  196.  
  197.          for(this.count = var1; this.count > 1 && this.digits[this.count - 1] == 48; --this.count) {
  198.          }
  199.       }
  200.  
  201.    }
  202.  
  203.    private boolean shouldRoundUp(int var1) {
  204.       boolean var2 = false;
  205.       if (var1 < this.count) {
  206.          if (this.digits[var1] > 53) {
  207.             return true;
  208.          }
  209.  
  210.          if (this.digits[var1] == 53) {
  211.             for(int var3 = var1 + 1; var3 < this.count; ++var3) {
  212.                if (this.digits[var3] != 48) {
  213.                   return true;
  214.                }
  215.             }
  216.  
  217.             return var1 > 0 && this.digits[var1 - 1] % 2 != 0;
  218.          }
  219.       }
  220.  
  221.       return false;
  222.    }
  223.  
  224.    public final void set(long var1) {
  225.       this.set(var1, 0);
  226.    }
  227.  
  228.    public final void set(long var1, int var3) {
  229.       if (var1 <= 0L) {
  230.          if (var1 == Long.MIN_VALUE) {
  231.             this.decimalAt = this.count = 19;
  232.             System.arraycopy(LONG_MIN_REP, 0, this.digits, 0, this.count);
  233.          } else {
  234.             this.decimalAt = this.count = 0;
  235.          }
  236.       } else {
  237.          int var4;
  238.          for(var4 = 19; var1 > 0L; var1 /= 10L) {
  239.             --var4;
  240.             this.digits[var4] = (byte)((int)(48L + var1 % 10L));
  241.          }
  242.  
  243.          this.decimalAt = 19 - var4;
  244.  
  245.          int var5;
  246.          for(var5 = 18; this.digits[var5] == 48; --var5) {
  247.          }
  248.  
  249.          this.count = var5 - var4 + 1;
  250.          System.arraycopy(this.digits, var4, this.digits, 0, this.count);
  251.       }
  252.  
  253.       if (var3 > 0) {
  254.          this.round(var3);
  255.       }
  256.  
  257.    }
  258.  
  259.    public boolean equals(Object var1) {
  260.       if (this == var1) {
  261.          return true;
  262.       } else if (!(var1 instanceof DigitList)) {
  263.          return false;
  264.       } else {
  265.          DigitList var2 = (DigitList)var1;
  266.          if (this.count == var2.count && this.decimalAt == var2.decimalAt) {
  267.             for(int var3 = 0; var3 < this.count; ++var3) {
  268.                if (this.digits[var3] != var2.digits[var3]) {
  269.                   return false;
  270.                }
  271.             }
  272.  
  273.             return true;
  274.          } else {
  275.             return false;
  276.          }
  277.       }
  278.    }
  279.  
  280.    public int hashCode() {
  281.       int var1 = this.decimalAt;
  282.  
  283.       for(int var2 = 0; var2 < this.count; ++var2) {
  284.          var1 = var1 * 37 + this.digits[var2];
  285.       }
  286.  
  287.       return var1;
  288.    }
  289.  
  290.    private boolean isLongMIN_VALUE() {
  291.       if (this.decimalAt == this.count && this.count == 19) {
  292.          for(int var1 = 0; var1 < this.count; ++var1) {
  293.             if (this.digits[var1] != LONG_MIN_REP[var1]) {
  294.                return false;
  295.             }
  296.          }
  297.  
  298.          return true;
  299.       } else {
  300.          return false;
  301.       }
  302.    }
  303.  
  304.    private static final int log10(double var0) {
  305.       double var2 = Math.log(var0) / LOG10;
  306.       int var4 = (int)Math.floor(var2);
  307.       if (var2 > (double)0.0F && var0 >= Math.pow((double)10.0F, (double)(var4 + 1))) {
  308.          ++var4;
  309.       } else if (var2 < (double)0.0F && var0 < Math.pow((double)10.0F, (double)var4)) {
  310.          --var4;
  311.       }
  312.  
  313.       return var4;
  314.    }
  315.  
  316.    public String toString() {
  317.       if (this.isZero()) {
  318.          return "0";
  319.       } else {
  320.          StringBuffer var1 = new StringBuffer("0.");
  321.  
  322.          for(int var2 = 0; var2 < this.count; ++var2) {
  323.             var1.append((char)this.digits[var2]);
  324.          }
  325.  
  326.          var1.append("x10^");
  327.          var1.append(this.decimalAt);
  328.          return var1.toString();
  329.       }
  330.    }
  331.  
  332.    static {
  333.       String var0 = Long.toString(Long.MIN_VALUE);
  334.       LONG_MIN_REP = new byte[19];
  335.  
  336.       for(int var1 = 0; var1 < 19; ++var1) {
  337.          LONG_MIN_REP[var1] = (byte)var0.charAt(var1 + 1);
  338.       }
  339.  
  340.       LOG10 = Math.log((double)10.0F);
  341.    }
  342. }
  343.