Author: shawkins
Date: 2009-07-16 13:06:57 -0400 (Thu, 16 Jul 2009)
New Revision: 1138
Modified:
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
Log:
TEIID-671 adding bigdecimal as an accepted input to power.
Modified:
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
===================================================================
---
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2009-07-16
14:19:27 UTC (rev 1137)
+++
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2009-07-16
17:06:57 UTC (rev 1138)
@@ -350,8 +350,7 @@
<para>x to the y power</para>
</entry>
<entry>
- <para>x in {integer, long, float, double, biginteger}, if x is
- biginteger then return type is biginteger, else double</para>
+ <para>x in {double, bigdecimal, biginteger}, return is the same type as
x</para>
</entry>
</row>
<row>
Modified: trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java 2009-07-16
14:19:27 UTC (rev 1137)
+++
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java 2009-07-16
17:06:57 UTC (rev 1138)
@@ -282,22 +282,18 @@
}
// ================== Function = power =====================
-
- public static Object power(Object x, Object y) throws FunctionExecutionException {
- if(x == null || y == null) {
- return null;
- } else if(x instanceof Double) {
- if(y instanceof Double) {
- return new Double(Math.pow(((Double)x).doubleValue(), ((Double)y).doubleValue()));
- }
- } else if(x instanceof BigInteger) {
- if(y instanceof Integer) {
- return ((BigInteger)x).pow(((Integer)y).intValue());
- }
- }
-
- throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0007,
QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0007, new Object[]{"power",
x.getClass().getName(), y.getClass().getName()})); //$NON-NLS-1$
+
+ public static double power(double x, double y) {
+ return Math.pow(x, y);
}
+
+ public static BigInteger power(BigInteger x, int y) {
+ return x.pow(y);
+ }
+
+ public static BigDecimal power(BigDecimal x, int y) {
+ return x.pow(y);
+ }
public static int round(int number, int places) {
if(places < 0){
Modified:
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java 2009-07-16
14:19:27 UTC (rev 1137)
+++
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java 2009-07-16
17:06:57 UTC (rev 1138)
@@ -298,6 +298,7 @@
private void addPowerFunction() {
addTypedPowerFunction(DataTypeManager.DefaultDataTypes.DOUBLE,
DataTypeManager.DefaultDataTypes.DOUBLE);
addTypedPowerFunction(DataTypeManager.DefaultDataTypes.BIG_INTEGER,
DataTypeManager.DefaultDataTypes.INTEGER);
+ addTypedPowerFunction(DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
DataTypeManager.DefaultDataTypes.INTEGER);
}
private void addTypedPowerFunction(String baseType, String powerType) {
Modified:
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2009-07-16
14:19:27 UTC (rev 1137)
+++
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2009-07-16
17:06:57 UTC (rev 1138)
@@ -1341,6 +1341,10 @@
helpInvokeMethod("power", new Object[] { new Double("10"),
new Double("2") }, new Double("100")); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
}
+ @Test public void testInvokePower1() {
+ helpInvokeMethod("power", new Object[] { new
BigDecimal("10"), new Integer(2) }, new BigDecimal("100"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
@Test public void testInvokeSqrt() {
helpInvokeMethod("sqrt", new Object[] { new Double("4")}, new
Double("2")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
Show replies by date