|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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 Number |
coerceNumber(Number number)
Tests whether a given number can be safely coerced to Double or Integer without changing the value of the number. |
static Number |
higherPrecisionNumber(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 Number coerceNumber(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 Number higherPrecisionNumber(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
|
Copyright 2002, 2007 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |