提交 fe9b5e70 authored 作者: noelgrandin@gmail.com's avatar noelgrandin@gmail.com

Support for COSH, SINH, and TANH functions.

上级 70ef2e60
......@@ -2406,6 +2406,16 @@ This method returns a double.
COS(ANGLE)
"
"Functions (Numeric)","COSH","
COSH(double)
","
Calculate the hyperbolic cosine.
See also Java ""Math.cosh"".
This method returns a double.
","
COSH(X)
"
"Functions (Numeric)","COT","
COT(double)
","
......@@ -2426,6 +2436,16 @@ This method returns a double.
SIN(ANGLE)
"
"Functions (Numeric)","SINH","
SINH(double)
","
Calculate the hyperbolic sine.
See also Java ""Math.sinh"".
This method returns a double.
","
SINH(ANGLE)
"
"Functions (Numeric)","TAN","
TAN(double)
","
......@@ -2436,6 +2456,16 @@ This method returns a double.
TAN(ANGLE)
"
"Functions (Numeric)","TANH","
TANH(double)
","
Calculate the hyperbolic tangent.
See also Java ""Math.tanh"".
This method returns a double.
","
TANH(X)
"
"Functions (Numeric)","ATAN2","
ATAN2(double, double)
","
......
......@@ -19,7 +19,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Support for the % operator (modulo) thanks to Noel Grandin.
<li>Support for COSH, SINH, and TANH functions.
</li><li>Support for the % operator (modulo) thanks to Noel Grandin.
</li><li>Issue 288: Some right outer join queries failed to produce the correct result or
threw exceptions such as "column x must be in the group by list".
</li><li>Some right outer joins with invalid column referenced (typos) threw a NullPointerException instead of
......
......@@ -231,7 +231,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Integrate spatial functions from http://geosysin.iict.ch/irstv-trac/wiki/H2spatial/Download
</li><li>Cluster: hot deploy (adding a node at runtime).
</li><li>Support DatabaseMetaData.insertsAreDetected: updatable result sets should detect inserts.
</li><li>Support COSH, SINH, and TANH functions
</li><li>Oracle: support DECODE method (convert to CASE WHEN).
</li><li>Native search: support "phrase search", wildcard search (* and ?), case-insensitive search, boolean operators, and grouping
</li><li>Improve documentation of access rights.
......
......@@ -73,7 +73,7 @@ public class Function extends Expression implements FunctionCall {
CEILING = 8, COS = 9, COT = 10, DEGREES = 11, EXP = 12, FLOOR = 13, LOG = 14, LOG10 = 15, MOD = 16,
PI = 17, POWER = 18, RADIANS = 19, RAND = 20, ROUND = 21, ROUNDMAGIC = 22, SIGN = 23, SIN = 24, SQRT = 25,
TAN = 26, TRUNCATE = 27, SECURE_RAND = 28, HASH = 29, ENCRYPT = 30, DECRYPT = 31, COMPRESS = 32,
EXPAND = 33, ZERO = 34, RANDOM_UUID = 35;
EXPAND = 33, ZERO = 34, RANDOM_UUID = 35, COSH = 36, SINH = 37, TANH = 38;
public static final int ASCII = 50, BIT_LENGTH = 51, CHAR = 52, CHAR_LENGTH = 53, CONCAT = 54, DIFFERENCE = 55,
HEXTORAW = 56, INSERT = 57, INSTR = 58, LCASE = 59, LEFT = 60, LENGTH = 61, LOCATE = 62, LTRIM = 63,
......@@ -165,6 +165,7 @@ public class Function extends Expression implements FunctionCall {
addFunction("BITXOR", BITXOR, 2, Value.LONG);
addFunction("CEILING", CEILING, 1, Value.DOUBLE);
addFunction("COS", COS, 1, Value.DOUBLE);
addFunction("COSH", COSH, 1, Value.DOUBLE);
addFunction("COT", COT, 1, Value.DOUBLE);
addFunction("DEGREES", DEGREES, 1, Value.DOUBLE);
addFunction("EXP", EXP, 1, Value.DOUBLE);
......@@ -182,8 +183,10 @@ public class Function extends Expression implements FunctionCall {
addFunction("ROUNDMAGIC", ROUNDMAGIC, 1, Value.DOUBLE);
addFunction("SIGN", SIGN, 1, Value.INT);
addFunction("SIN", SIN, 1, Value.DOUBLE);
addFunction("SINH", SINH, 1, Value.DOUBLE);
addFunction("SQRT", SQRT, 1, Value.DOUBLE);
addFunction("TAN", TAN, 1, Value.DOUBLE);
addFunction("TANH", TANH, 1, Value.DOUBLE);
addFunction("TRUNCATE", TRUNCATE, 2, Value.DOUBLE);
addFunction("HASH", HASH, 3, Value.BYTES);
addFunction("ENCRYPT", ENCRYPT, 3, Value.BYTES);
......@@ -447,6 +450,9 @@ public class Function extends Expression implements FunctionCall {
case COS:
result = ValueDouble.get(Math.cos(v0.getDouble()));
break;
case COSH:
result = ValueDouble.get(Math.cosh(v0.getDouble()));
break;
case COT: {
double d = Math.tan(v0.getDouble());
if (d == 0.0) {
......@@ -492,12 +498,18 @@ public class Function extends Expression implements FunctionCall {
case SIN:
result = ValueDouble.get(Math.sin(v0.getDouble()));
break;
case SINH:
result = ValueDouble.get(Math.sinh(v0.getDouble()));
break;
case SQRT:
result = ValueDouble.get(Math.sqrt(v0.getDouble()));
break;
case TAN:
result = ValueDouble.get(Math.tan(v0.getDouble()));
break;
case TANH:
result = ValueDouble.get(Math.tanh(v0.getDouble()));
break;
case SECURE_RAND:
result = ValueBytes.getNoCopy(MathUtils.secureRandomBytes(v0.getInt()));
break;
......
......@@ -60,6 +60,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
testDeterministic();
testTransactionId();
testPrecision();
testMathFunctions();
testVarArgs();
testAggregate();
testFunctions();
......@@ -274,6 +275,21 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn.close();
}
private void testMathFunctions() throws SQLException {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("CALL SINH(50)");
assertTrue(rs.next());
assertEquals(Math.sinh(50), rs.getDouble(1));
rs = stat.executeQuery("CALL COSH(50)");
assertTrue(rs.next());
assertEquals(Math.cosh(50), rs.getDouble(1));
rs = stat.executeQuery("CALL TANH(50)");
assertTrue(rs.next());
assertEquals(Math.tanh(50), rs.getDouble(1));
conn.close();
}
private void testVarArgs() throws SQLException {
//## Java 1.5 begin ##
Connection conn = getConnection("functions");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论