Skip to content

Commit

Permalink
[FLINK-13450][table api] Use StrictMath instead of Math for some expr…
Browse files Browse the repository at this point in the history
…essions

This ensures cross architecture compatibility of results.

This closes apache#9681
  • Loading branch information
wangxiyuan authored and StephanEwen committed Dec 4, 2019
1 parent 9829b9c commit 1d034ad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class DataSetCost(val rowCount: Double, val cpu: Double, val io: Double) extends
if (n == 0) {
return 1.0
}
Math.pow(d, 1 / n)
StrictMath.pow(d, 1 / n)
}

def plus(other: RelOptCost): RelOptCost = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ScalarFunctions {}
object ScalarFunctions {

def power(a: Double, b: JBigDecimal): Double = {
Math.pow(a, b.doubleValue())
StrictMath.pow(a, b.doubleValue())
}

/**
Expand Down Expand Up @@ -111,7 +111,7 @@ object ScalarFunctions {
if (x <= 0.0) {
throw new IllegalArgumentException(s"x of 'log(x)' must be > 0, but x = $x")
} else {
Math.log(x)
StrictMath.log(x)
}
}

Expand Down Expand Up @@ -139,7 +139,7 @@ object ScalarFunctions {
if (base <= 1.0) {
throw new IllegalArgumentException(s"base of 'log(base, x)' must be > 1, but base = $base")
} else {
Math.log(x) / Math.log(base)
StrictMath.log(x) / StrictMath.log(base)
}
}

Expand All @@ -150,7 +150,7 @@ object ScalarFunctions {
if (x <= 0.0) {
throw new IllegalArgumentException(s"x of 'log2(x)' must be > 0, but x = $x")
} else {
Math.log(x) / Math.log(2)
StrictMath.log(x) / StrictMath.log(2)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class SqlExpressionTest extends ExpressionTestBase {
testSqlApi("LOG10(10)", "1.0")
testSqlApi("LOG2(8)", "3.0")
testSqlApi("LOG(E())", "1.0")
testSqlApi("LOG(3,27)", "3.0")
testSqlApi("LOG(3,27)", "3.0000000000000004")
testSqlApi("EXP(1)", "2.718281828459045")
testSqlApi("CEIL(2.5)", "3")
testSqlApi("CEILING(2.5)", "3")
Expand Down

0 comments on commit 1d034ad

Please sign in to comment.