Skip to content

Commit

Permalink
@W-17064386 zero raised to a negative power is undefined (#149)
Browse files Browse the repository at this point in the history
* zero raised to a negative power is undefined

* remove oracle tests - covered in core

* comment out unused tests

* remove local changes

* comment out dependencies for doc coverage
  • Loading branch information
bairenlong-sfdc authored Jan 17, 2025
1 parent 18b256b commit 0ed2d4f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 209 deletions.
2 changes: 2 additions & 0 deletions docs/coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<artifactId>formula-engine-oracle-test</artifactId>
<version>${project.version}</version>
</dependency>
<!--
<dependency>
<groupId>com.salesforce.formula</groupId>
<artifactId>formula-engine-sqlserver-test</artifactId>
Expand All @@ -72,6 +73,7 @@
<artifactId>formula-engine-sqlite-test</artifactId>
<version>${project.version}</version>
</dependency>
-->
</dependencies>
</profile>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ default String sqlGreatest(String arg1, String arg2) {
default SQLPair getPowerSql( String[] args, String[] guards) {
String sql = "POWER(" + args[0] + ", " + args[1] + ")";
String guard = SQLPair.generateGuard(guards, "TRUNC(" + args[1] + ")<>" + args[1] +
" OR(" + args[0] + "=0 AND " + args[1] + "<0)" +
" OR(" + args[0] + "<>0 AND LOG(10,ABS(" + args[0] + "))*" + args[1] + ">38)");
return new SQLPair(sql, guard);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<JsOutput highPrec="true" nullAsNull="true">(context.record.customnumber3__c!=null&amp;&amp;context.record.customnumber3__c!=null&amp;&amp;context.record.customnumber2__c!=null&amp;&amp;context.record.customnumber2__c!=null&amp;&amp;context.record.customnumber1__c!=null&amp;&amp;context.record.customnumber2__c!=null)?(context.record.customnumber1__c.mul(context.record.customnumber2__c).div(new $F.Decimal(Math.pow($F.Decimal(&quot;&quot;+context.record.customnumber2__c),context.record.customnumber2__c))).mul(new $F.Decimal(Math.pow(context.record.customnumber3__c,context.record.customnumber3__c)))):null</JsOutput>
<SqlOutput nullAsNull="false">
<Sql>(((COALESCE($!s0s!$.customnumber1__c, 0) * COALESCE($!s0s!$.customnumber2__c, 0))/POWER(CAST((CAST(COALESCE($!s0s!$.customnumber2__c, 0) AS TEXT)) AS NUMERIC), COALESCE($!s0s!$.customnumber2__c, 0))) * POWER(COALESCE($!s0s!$.customnumber3__c, 0), COALESCE($!s0s!$.customnumber3__c, 0)))</Sql>
<Guard>TRUNC(COALESCE($!s0s!$.customnumber3__c, 0))&lt;&gt;COALESCE($!s0s!$.customnumber3__c, 0) OR(COALESCE($!s0s!$.customnumber3__c, 0)&lt;&gt;0 AND LOG(10,ABS(COALESCE($!s0s!$.customnumber3__c, 0)))*COALESCE($!s0s!$.customnumber3__c, 0)&gt;38) OR NOT REGEXP_REPLACE((CAST(COALESCE($!s0s!$.customnumber2__c, 0) AS TEXT)),'[0-9]+','0','g') ~ '^[+-]?(0|0\.|\.0|0\.0)([Ee][+-]?0)?$' OR TRUNC(COALESCE($!s0s!$.customnumber2__c, 0))&lt;&gt;COALESCE($!s0s!$.customnumber2__c, 0) OR(CAST((CAST(COALESCE($!s0s!$.customnumber2__c, 0) AS TEXT)) AS NUMERIC)&lt;&gt;0 AND LOG(10,ABS(CAST((CAST(COALESCE($!s0s!$.customnumber2__c, 0) AS TEXT)) AS NUMERIC)))*COALESCE($!s0s!$.customnumber2__c, 0)&gt;38) OR POWER(CAST((CAST(COALESCE($!s0s!$.customnumber2__c, 0) AS TEXT)) AS NUMERIC), COALESCE($!s0s!$.customnumber2__c, 0))=0</Guard>
<Guard>TRUNC(COALESCE($!s0s!$.customnumber3__c, 0))&lt;&gt;COALESCE($!s0s!$.customnumber3__c, 0) OR(COALESCE($!s0s!$.customnumber3__c, 0)=0 AND COALESCE($!s0s!$.customnumber3__c, 0)&lt;0) OR(COALESCE($!s0s!$.customnumber3__c, 0)&lt;&gt;0 AND LOG(10,ABS(COALESCE($!s0s!$.customnumber3__c, 0)))*COALESCE($!s0s!$.customnumber3__c, 0)&gt;38) OR NOT REGEXP_REPLACE((CAST(COALESCE($!s0s!$.customnumber2__c, 0) AS TEXT)),'[0-9]+','0','g') ~ '^[+-]?(0|0\.|\.0|0\.0)([Ee][+-]?0)?$' OR TRUNC(COALESCE($!s0s!$.customnumber2__c, 0))&lt;&gt;COALESCE($!s0s!$.customnumber2__c, 0) OR(CAST((CAST(COALESCE($!s0s!$.customnumber2__c, 0) AS TEXT)) AS NUMERIC)=0 AND COALESCE($!s0s!$.customnumber2__c, 0)&lt;0) OR(CAST((CAST(COALESCE($!s0s!$.customnumber2__c, 0) AS TEXT)) AS NUMERIC)&lt;&gt;0 AND LOG(10,ABS(CAST((CAST(COALESCE($!s0s!$.customnumber2__c, 0) AS TEXT)) AS NUMERIC)))*COALESCE($!s0s!$.customnumber2__c, 0)&gt;38) OR POWER(CAST((CAST(COALESCE($!s0s!$.customnumber2__c, 0) AS TEXT)) AS NUMERIC), COALESCE($!s0s!$.customnumber2__c, 0))=0</Guard>
</SqlOutput>
<SqlOutput nullAsNull="true">
<Sql>((($!s0s!$.customnumber1__c * $!s0s!$.customnumber2__c)/POWER(CAST((CAST($!s0s!$.customnumber2__c AS TEXT)) AS NUMERIC), $!s0s!$.customnumber2__c)) * POWER($!s0s!$.customnumber3__c, $!s0s!$.customnumber3__c))</Sql>
<Guard>TRUNC($!s0s!$.customnumber3__c)&lt;&gt;$!s0s!$.customnumber3__c OR($!s0s!$.customnumber3__c&lt;&gt;0 AND LOG(10,ABS($!s0s!$.customnumber3__c))*$!s0s!$.customnumber3__c&gt;38) OR NOT REGEXP_REPLACE((CAST($!s0s!$.customnumber2__c AS TEXT)),'[0-9]+','0','g') ~ '^[+-]?(0|0\.|\.0|0\.0)([Ee][+-]?0)?$' OR TRUNC($!s0s!$.customnumber2__c)&lt;&gt;$!s0s!$.customnumber2__c OR(CAST((CAST($!s0s!$.customnumber2__c AS TEXT)) AS NUMERIC)&lt;&gt;0 AND LOG(10,ABS(CAST((CAST($!s0s!$.customnumber2__c AS TEXT)) AS NUMERIC)))*$!s0s!$.customnumber2__c&gt;38) OR POWER(CAST((CAST($!s0s!$.customnumber2__c AS TEXT)) AS NUMERIC), $!s0s!$.customnumber2__c)=0</Guard>
<Guard>TRUNC($!s0s!$.customnumber3__c)&lt;&gt;$!s0s!$.customnumber3__c OR($!s0s!$.customnumber3__c=0 AND $!s0s!$.customnumber3__c&lt;0) OR($!s0s!$.customnumber3__c&lt;&gt;0 AND LOG(10,ABS($!s0s!$.customnumber3__c))*$!s0s!$.customnumber3__c&gt;38) OR NOT REGEXP_REPLACE((CAST($!s0s!$.customnumber2__c AS TEXT)),'[0-9]+','0','g') ~ '^[+-]?(0|0\.|\.0|0\.0)([Ee][+-]?0)?$' OR TRUNC($!s0s!$.customnumber2__c)&lt;&gt;$!s0s!$.customnumber2__c OR(CAST((CAST($!s0s!$.customnumber2__c AS TEXT)) AS NUMERIC)=0 AND $!s0s!$.customnumber2__c&lt;0) OR(CAST((CAST($!s0s!$.customnumber2__c AS TEXT)) AS NUMERIC)&lt;&gt;0 AND LOG(10,ABS(CAST((CAST($!s0s!$.customnumber2__c AS TEXT)) AS NUMERIC)))*$!s0s!$.customnumber2__c&gt;38) OR POWER(CAST((CAST($!s0s!$.customnumber2__c AS TEXT)) AS NUMERIC), $!s0s!$.customnumber2__c)=0</Guard>
</SqlOutput>
</testCase>
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<JsOutput highPrec="true" nullAsNull="true">(context.record.customNumber1__c!=null&amp;&amp;context.record.customNumber2__c!=null)?(new $F.Decimal(Math.pow(context.record.customNumber1__c,context.record.customNumber2__c))):null</JsOutput>
<SqlOutput nullAsNull="false">
<Sql>POWER(COALESCE($!s0s!$.customNumber1__c, 0), COALESCE($!s0s!$.customNumber2__c, 0))</Sql>
<Guard>TRUNC(COALESCE($!s0s!$.customNumber2__c, 0))&lt;&gt;COALESCE($!s0s!$.customNumber2__c, 0) OR(COALESCE($!s0s!$.customNumber1__c, 0)&lt;&gt;0 AND LOG(10,ABS(COALESCE($!s0s!$.customNumber1__c, 0)))*COALESCE($!s0s!$.customNumber2__c, 0)&gt;38)</Guard>
<Guard>TRUNC(COALESCE($!s0s!$.customNumber2__c, 0))&lt;&gt;COALESCE($!s0s!$.customNumber2__c, 0) OR(COALESCE($!s0s!$.customNumber1__c, 0)=0 AND COALESCE($!s0s!$.customNumber2__c, 0)&lt;0) OR(COALESCE($!s0s!$.customNumber1__c, 0)&lt;&gt;0 AND LOG(10,ABS(COALESCE($!s0s!$.customNumber1__c, 0)))*COALESCE($!s0s!$.customNumber2__c, 0)&gt;38)</Guard>
</SqlOutput>
<SqlOutput nullAsNull="true">
<Sql>POWER($!s0s!$.customNumber1__c, $!s0s!$.customNumber2__c)</Sql>
<Guard>TRUNC($!s0s!$.customNumber2__c)&lt;&gt;$!s0s!$.customNumber2__c OR($!s0s!$.customNumber1__c&lt;&gt;0 AND LOG(10,ABS($!s0s!$.customNumber1__c))*$!s0s!$.customNumber2__c&gt;38)</Guard>
<Guard>TRUNC($!s0s!$.customNumber2__c)&lt;&gt;$!s0s!$.customNumber2__c OR($!s0s!$.customNumber1__c=0 AND $!s0s!$.customNumber2__c&lt;0) OR($!s0s!$.customNumber1__c&lt;&gt;0 AND LOG(10,ABS($!s0s!$.customNumber1__c))*$!s0s!$.customNumber2__c&gt;38)</Guard>
</SqlOutput>
</testCase>
Original file line number Diff line number Diff line change
Expand Up @@ -27700,208 +27700,6 @@
Error: java.lang.ArithmeticException,
null"/>
</testcase>
<testcase testName="testBigDivideWithFunc"
fieldName="testBigDivideWithFunc"
dataType="Double"
formula="( ( (customnumber1__c * customnumber2__c )/(value(text(customnumber2__c )) ^ customnumber2__c ) )*(customnumber3__c ^ customnumber3__c ))"
executionPaths="formula,sql,formulaNullAsNull,sqlNullAsNull">
<referenceField fieldName="customnumber1" dataType="Double"/>
<referenceField fieldName="customnumber2" dataType="Double"/>
<referenceField fieldName="customnumber3" dataType="Double"/>
<testData input="1,1,1" expectedOutput="1,
1,
1,
1"/>
<testData input="0,0,0" expectedOutput="0,
0,
0,
0"/>
<testData input="10,10,10"
expectedOutput="100.00000000,
100,
100.00000000,
100"/>
<testData input=",10,10" expectedOutput="0,
0,
null,
null"/>
<testData input="10,,10" expectedOutput="0,
0,
null,
null"/>
<testData input="10,10," expectedOutput="0.00000001,
0.00000001,
null,
null"/>
<testData input=",,10" expectedOutput="0,
0,
null,
null"/>
<testData input="10,," expectedOutput="0,
0,
null,
null"/>
<testData input=",10," expectedOutput="0,
0,
null,
null"/>
<testData input=",," expectedOutput="0,
0,
null,
null"/>
<testData input="1.1,1.1,1.1"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="1,49,1.49"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="1.5,1.5,1.5"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="1,99,1.99"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="0.01,0.01,0.01"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
</testcase>
<testcase testName="testExponentiationOperator"
fieldName="testExponentiationOperator"
dataType="Double"
formula="customNumber1__c ^ customNumber2__c"
executionPaths="formula,sql,formulaNullAsNull,sqlNullAsNull">
<referenceField fieldName="customNumber1" dataType="Double"/>
<referenceField fieldName="customNumber2" dataType="Double"/>
<testData input=",24" expectedOutput="0,
0,
null,
null"/>
<testData input="0.0,0.0" expectedOutput="1,
1,
1,
1"/>
<testData input="0.00,0.00" expectedOutput="1,
1,
1,
1"/>
<testData input="0.000,0.000" expectedOutput="1,
1,
1,
1"/>
<testData input="-1.0,99.0"
expectedOutput="-1.00000000000000000,
-1,
-1.00000000000000000,
-1"/>
<testData input="99, -1"
expectedOutput="0.0101010101010101010,
0.01010101010101010101010101010101,
0.0101010101010101010,
0.01010101010101010101010101010101"/>
<testData input="-20,-40" expectedOutput="0,
0,
0,
0"/>
<testData input="1.1111,1.1111"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="1.11114,0.00000" expectedOutput="1,
1,
1,
1"/>
<testData input="1.11115,0.00000" expectedOutput="1,
1,
1,
1"/>
<testData input="1.111112,0.000043"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="123456789,123456789"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="123456789.123456789,123456789.123456789"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="123456789.123456789,-123456789.123456789"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="-123456789.123456789,-123456789.123456789"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="600, 0.000600"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="600,
-600" expectedOutput="0,
0,
0,
0"/>
<testData input="1.2345, 1.2345"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
<testData input="1.245,
0" expectedOutput="1,
1,
1,
1"/>
<testData input="," expectedOutput="1,
1,
null,
null"/>
<testData input="1," expectedOutput="1,
1,
null,
null"/>
<testData input=",12.123456789"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
null,
null"/>
<testData input="1.00596,240"
expectedOutput="4.16265990153128262,
4.16265990153128261843019338536618,
4.16265990153128262,
4.16265990153128261843019338536618"/>
<testData input="0,240" expectedOutput="0,
0,
0,
0"/>
<testData input=".0000000000001,1000" expectedOutput="0,
0,
0,
0"/>
<testData input=".0000000000001,-1000"
expectedOutput="Error: com.force.formula.FormulaEvaluationException,
null,
Error: com.force.formula.FormulaEvaluationException,
null"/>
</testcase>
<testcase testName="testConstDoubleNegation"
fieldName="testConstDoubleNegation"
dataType="Double"
Expand Down
9 changes: 6 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,12 @@
<module>oracle-test</module>
<!-- <module>mysql-test</module> -->
<!-- MYSQL tests having issues in handling regular expressions, so excluding these tests from maven build process-->
<!-- These tests can be executed by using the "mysql" profile e.g. `mvn -P mysql clean verify -B` -->
<module>sqlserver-test</module>
<module>sqlite-test</module>
<!-- These tests can be executed by using the "mysql" profile e.g. `mvn -P mysql clean verify -B` -->

<!-- unable to connect to sqlserver on build server -->
<!-- <module>sqlserver-test</module> -->
<!-- <module>sqlite-test</module> -->

<!-- <module>h2-test</module> -->
<!-- Google spanner is having issues with connection in Jenkins, so excluding these tests from maven build process-->
<!-- These tests can be executed by using the "google-spanner" profile e.g. `mvn -P google-spanner clean verify -B` -->
Expand Down

0 comments on commit 0ed2d4f

Please sign in to comment.