Skip to content

Commit

Permalink
[FLINK-13450][table api] Use StrictMath instead of Math for exp
Browse files Browse the repository at this point in the history
This ensures compatibility of results across processor architectures

This closes apache#10432
  • Loading branch information
wangxiyuan authored and StephanEwen committed Dec 6, 2019
1 parent af8b3a8 commit 5545d8a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object BuiltInMethods {

val LOG2 = Types.lookupMethod(classOf[ScalarFunctions], "log2", classOf[Double])

val EXP = Types.lookupMethod(classOf[Math], "exp", classOf[Double])
val EXP = Types.lookupMethod(classOf[ScalarFunctions], "exp", classOf[Double])

val POWER = Types.lookupMethod(classOf[Math], "pow", classOf[Double], classOf[Double])
val POWER_DEC = Types.lookupMethod(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ object ScalarFunctions {
}
}

/**
* Returns exp(x).
*/
def exp(x: Double): Double = {
if (x <= 0.0) {
throw new IllegalArgumentException(s"x of 'exp(x)' must be > 0, but x = $x")
} else {
StrictMath.exp(x)
}
}

/**
* Calculates the hyperbolic tangent of a big decimal number.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class SqlExpressionTest extends ExpressionTestBase {
testSqlApi("LOG2(8)", "3.0")
testSqlApi("LOG(E())", "1.0")
testSqlApi("LOG(3,27)", "3.0000000000000004")
testSqlApi("EXP(1)", "2.718281828459045")
testSqlApi("EXP(1)", "2.7182818284590455")
testSqlApi("CEIL(2.5)", "3")
testSqlApi("CEILING(2.5)", "3")
testSqlApi("FLOOR(2.5)", "2")
Expand Down

0 comments on commit 5545d8a

Please sign in to comment.