summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Uhl2012-05-04 05:13:25 (EDT)
committer Ed.Willink2012-05-04 10:47:16 (EDT)
commit64a1568ae14d67e084273c74f397476238d112ed (patch)
treea9fd7a60d548f3a751ec2587f9b714cad6b35a4e
parentfd05ebf7edcc9a969496dbaf1b8fe5956341200a (diff)
downloadorg.eclipse.ocl-64a1568ae14d67e084273c74f397476238d112ed.zip
org.eclipse.ocl-64a1568ae14d67e084273c74f397476238d112ed.tar.gz
org.eclipse.ocl-64a1568ae14d67e084273c74f397476238d112ed.tar.bz2
preserve int/long integral accuracy when coercing to BigDecimal
-rw-r--r--plugins/org.eclipse.ocl/src/org/eclipse/ocl/internal/evaluation/NumberUtil.java8
1 files changed, 5 insertions, 3 deletions
diff --git a/plugins/org.eclipse.ocl/src/org/eclipse/ocl/internal/evaluation/NumberUtil.java b/plugins/org.eclipse.ocl/src/org/eclipse/ocl/internal/evaluation/NumberUtil.java
index 62cf44f..2fbdefb 100644
--- a/plugins/org.eclipse.ocl/src/org/eclipse/ocl/internal/evaluation/NumberUtil.java
+++ b/plugins/org.eclipse.ocl/src/org/eclipse/ocl/internal/evaluation/NumberUtil.java
@@ -115,12 +115,12 @@ public class NumberUtil {
/**
* <p>
- * Coerces the given number to a common or greater precision than referenceNumber,
- * <tt>BigDecimal</TT> is greater than <tt>Double</tt> or
+ * Coerces the given number to a common or greater precision than <tt>referenceNumber</tt>,
+ * <tt>BigDecimal</tt> is greater than <tt>Double</tt> or
* <tt>BigInteger</tt> which is greater than <tt>Long</tt> precision.
* </p>
*
- * @param number a number to coerce toa common precision
+ * @param number a number to coerce to a common precision
* @param referenceNumber another number to share the common precision
* @return the coerced number, or the original number, in case of overflow
*/
@@ -130,6 +130,8 @@ public class NumberUtil {
return number;
} else if (number instanceof BigInteger) {
return new BigDecimal((BigInteger)number);
+ } else if (number instanceof Integer || number instanceof Long) {
+ return new BigDecimal(number.longValue());
} else {
return BigDecimal.valueOf(number.doubleValue());
}