|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.ocl.internal.evaluation.NumberUtil
public class NumberUtil
Utility for converting numeric values to double or integer precision as needed.
Constructor Summary | |
---|---|
NumberUtil()
|
Method Summary | |
---|---|
static java.lang.Number |
coerceNumber(java.lang.Number number)
Tests whether a given number can be safely coerced to Double or Integer without changing the value of the number. |
static java.lang.Number |
commonPrecisionNumber(java.lang.Number number,
java.lang.Number referenceNumber)
Coerces the given number to a common or greater precision than referenceNumber, BigDecimal is greater than Double or BigInteger which is greater than Long precision. |
static java.lang.Number |
higherPrecisionNumber(java.lang.Number number)
Coerces the given number to Double or Long precision, if possible. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NumberUtil()
Method Detail |
---|
public static java.lang.Number coerceNumber(java.lang.Number number)
Tests whether a given number can be safely coerced to Double or Integer without changing the value of the number. Safe means that coercing a number to Double or Integer and then coercing it back to the original type will result in the same value (no loss of precision). This is trivial for types, which have a smaller domain then Integer or Double, but for example a Long number may not be safely coerced to Integer.
If the coercion is safe, the number will be returned as either Double or Integer, as appropriate to the original precision. Otherwise the original number is returned.
number
- a number to coerce to Integer or Double
public static java.lang.Number commonPrecisionNumber(java.lang.Number number, java.lang.Number referenceNumber)
Coerces the given number to a common or greater precision than referenceNumber, BigDecimal is greater than Double or BigInteger which is greater than Long precision.
number
- a number to coerce to a common precisionreferenceNumber
- another number to share the common precision
public static java.lang.Number higherPrecisionNumber(java.lang.Number number)
Coerces the given number to Double or Long precision, if possible. Note that this is only impossible for BigDecimal or BigInteger values, respectively, that are out of range of their primitive counterparts.
number
- a number to coerce to Long or Double
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |