Merged gcj-eclipse branch to trunk.

From-SVN: r120621
This commit is contained in:
Tom Tromey 2007-01-09 19:58:05 +00:00
parent c648dedbde
commit 97b8365caf
17478 changed files with 606493 additions and 100744 deletions

View file

@ -48,6 +48,30 @@ import java.io.Serializable;
*/
public final class MathContext implements Serializable
{
/** A MathContext for unlimited precision arithmetic * */
public static final MathContext UNLIMITED =
new MathContext(0, RoundingMode.HALF_UP);
/**
* A MathContext for the IEEE 754R Decimal32 format - 7 digit preicision and
* HALF_EVEN rounding.
*/
public static final MathContext DECIMAL32 =
new MathContext(7, RoundingMode.HALF_EVEN);
/**
* A MathContext for the IEEE 754R Decimal64 format - 16 digit preicision and
* HALF_EVEN rounding.
*/
public static final MathContext DECIMAL64 =
new MathContext(16, RoundingMode.HALF_EVEN);
/**
* A MathContext for the IEEE 754R Decimal128 format - 34 digit preicision and
* HALF_EVEN rounding.
*/
public static final MathContext DECIMAL128 =
new MathContext(34, RoundingMode.HALF_EVEN);
/**
* This is the serialVersionUID reported here:
@ -56,7 +80,9 @@ public final class MathContext implements Serializable
private static final long serialVersionUID = 5579720004786848255L;
private int precision;
private RoundingMode roundMode;
/**
* Constructs a new MathContext with the specified precision and with HALF_UP
* rounding.
@ -65,12 +91,26 @@ public final class MathContext implements Serializable
* @throws IllegalArgumentException if precision is < 0.
*/
public MathContext(int setPrecision)
{
this(setPrecision, RoundingMode.HALF_UP);
}
/**
* Constructs a new MathContext with the specified precision and rounding
* mode.
* @param setPrecision the precision
* @param setRoundingMode the rounding mode
*
* @throws IllegalArgumentException if precision is < 0.
*/
public MathContext(int setPrecision, RoundingMode setRoundingMode)
{
if (setPrecision < 0)
throw new IllegalArgumentException("Precision cannot be less than zero.");
precision = setPrecision;
roundMode = setRoundingMode;
}
/**
* Constructs a MathContext from a String that has the same form as one
* produced by the toString() method.
@ -85,6 +125,7 @@ public final class MathContext implements Serializable
{
int roundingModeIndex = val.indexOf("roundingMode", 10);
precision = Integer.parseInt(val.substring(10, roundingModeIndex - 1));
roundMode = RoundingMode.valueOf(val.substring(roundingModeIndex + 13));
}
catch (NumberFormatException nfe)
{
@ -109,7 +150,8 @@ public final class MathContext implements Serializable
if (!(x instanceof MathContext))
return false;
MathContext mc = (MathContext)x;
return mc.precision == this.precision;
return mc.precision == this.precision
&& mc.roundMode.equals(this.roundMode);
}
/**
@ -121,6 +163,18 @@ public final class MathContext implements Serializable
return precision;
}
/**
* Returns the rounding mode setting. This will be one of
* RoundingMode.CEILING, RoundingMode.DOWN, RoundingMode.FLOOR,
* RoundingMode.HALF_DOWN, RoundingMode.HALF_EVEN, RoundingMode.HALF_UP,
* RoundingMode.UNNECESSARY, or RoundingMode.UP.
* @return the rounding mode setting.
*/
public RoundingMode getRoundingMode()
{
return roundMode;
}
/**
* Returns "precision=p roundingMode=MODE" where p is an int giving the
* precision and MODE is UP, DOWN, HALF_UP, HALF_DOWN, HALF_EVEN, CEILING,
@ -130,7 +184,7 @@ public final class MathContext implements Serializable
*/
public String toString()
{
return "precision="+precision;
return "precision="+precision+" roundingMode="+roundMode;
}
/**
@ -139,6 +193,6 @@ public final class MathContext implements Serializable
*/
public int hashCode()
{
return precision;
return precision ^ roundMode.hashCode();
}
}