home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / math / MathContext.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.9 KB  |  135 lines

  1. package java.math;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.Serializable;
  6. import java.io.StreamCorruptedException;
  7.  
  8. public final class MathContext implements Serializable {
  9.    private static final int DEFAULT_DIGITS = 9;
  10.    private static final RoundingMode DEFAULT_ROUNDINGMODE;
  11.    private static final int MIN_DIGITS = 0;
  12.    private static final long serialVersionUID = 5579720004786848255L;
  13.    public static final MathContext UNLIMITED;
  14.    public static final MathContext DECIMAL32;
  15.    public static final MathContext DECIMAL64;
  16.    public static final MathContext DECIMAL128;
  17.    final int precision;
  18.    final RoundingMode roundingMode;
  19.    transient BigInteger roundingMax;
  20.    transient BigInteger roundingMin;
  21.    private static final int MAX_LOOKASIDE = 1000;
  22.  
  23.    public MathContext(int var1) {
  24.       this(var1, DEFAULT_ROUNDINGMODE);
  25.    }
  26.  
  27.    public MathContext(int var1, RoundingMode var2) {
  28.       this.roundingMax = null;
  29.       this.roundingMin = null;
  30.       if (var1 < 0) {
  31.          throw new IllegalArgumentException("Digits < 0");
  32.       } else if (var2 == null) {
  33.          throw new NullPointerException("null RoundingMode");
  34.       } else {
  35.          this.precision = var1;
  36.          if (this.precision > 0 && this.precision <= 1000) {
  37.             this.roundingMax = BigInteger.TEN.pow(this.precision);
  38.             this.roundingMin = this.roundingMax.negate();
  39.          }
  40.  
  41.          this.roundingMode = var2;
  42.       }
  43.    }
  44.  
  45.    public MathContext(String var1) {
  46.       this.roundingMax = null;
  47.       this.roundingMin = null;
  48.       boolean var2 = false;
  49.       if (var1 == null) {
  50.          throw new NullPointerException("null String");
  51.       } else {
  52.          int var3;
  53.          try {
  54.             if (!var1.startsWith("precision=")) {
  55.                throw new RuntimeException();
  56.             }
  57.  
  58.             int var4 = var1.indexOf(32);
  59.             int var5 = 10;
  60.             var3 = Integer.parseInt(var1.substring(10, var4));
  61.             if (!var1.startsWith("roundingMode=", var4 + 1)) {
  62.                throw new RuntimeException();
  63.             }
  64.  
  65.             var5 = var4 + 1 + 13;
  66.             String var6 = var1.substring(var5, var1.length());
  67.             this.roundingMode = RoundingMode.valueOf(var6);
  68.          } catch (RuntimeException var7) {
  69.             throw new IllegalArgumentException("bad string format");
  70.          }
  71.  
  72.          if (var3 < 0) {
  73.             throw new IllegalArgumentException("Digits < 0");
  74.          } else {
  75.             this.precision = var3;
  76.             if (this.precision > 0 && this.precision <= 1000) {
  77.                this.roundingMax = BigInteger.TEN.pow(this.precision);
  78.                this.roundingMin = this.roundingMax.negate();
  79.             }
  80.  
  81.          }
  82.       }
  83.    }
  84.  
  85.    public int getPrecision() {
  86.       return this.precision;
  87.    }
  88.  
  89.    public RoundingMode getRoundingMode() {
  90.       return this.roundingMode;
  91.    }
  92.  
  93.    public boolean equals(Object var1) {
  94.       if (!(var1 instanceof MathContext)) {
  95.          return false;
  96.       } else {
  97.          MathContext var2 = (MathContext)var1;
  98.          return var2.precision == this.precision && var2.roundingMode == this.roundingMode;
  99.       }
  100.    }
  101.  
  102.    public int hashCode() {
  103.       return this.precision + this.roundingMode.hashCode() * 59;
  104.    }
  105.  
  106.    public String toString() {
  107.       return "precision=" + this.precision + " " + "roundingMode=" + this.roundingMode.toString();
  108.    }
  109.  
  110.    private synchronized void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  111.       var1.defaultReadObject();
  112.       if (this.precision < 0) {
  113.          String var3 = "MathContext: invalid digits in stream";
  114.          throw new StreamCorruptedException(var3);
  115.       } else if (this.roundingMode == null) {
  116.          String var2 = "MathContext: null roundingMode in stream";
  117.          throw new StreamCorruptedException(var2);
  118.       } else {
  119.          if (this.precision <= 1000) {
  120.             this.roundingMax = BigInteger.TEN.pow(this.precision);
  121.             this.roundingMin = this.roundingMax.negate();
  122.          }
  123.  
  124.       }
  125.    }
  126.  
  127.    static {
  128.       DEFAULT_ROUNDINGMODE = RoundingMode.HALF_UP;
  129.       UNLIMITED = new MathContext(0, RoundingMode.HALF_UP);
  130.       DECIMAL32 = new MathContext(7, RoundingMode.HALF_EVEN);
  131.       DECIMAL64 = new MathContext(16, RoundingMode.HALF_EVEN);
  132.       DECIMAL128 = new MathContext(34, RoundingMode.HALF_EVEN);
  133.    }
  134. }
  135.