Calculates the hyperbolic tangent of a number.
Quick example: tanh(30) → 1.0
Syntax
double|decimal tanh(<number>)Parameters
number: Required. A DOUBLE or DECIMAL value.
STRING and BIGINT values are implicitly converted to DOUBLE before the calculation.
Return value
The return type mirrors the input type:
| Input type | Return type |
|---|---|
| DOUBLE | DOUBLE |
| DECIMAL | DECIMAL |
| STRING | DOUBLE |
| BIGINT | DOUBLE |
| null | null |
Examples
Static values
-- Returns 1.0
SELECT tanh(30);
-- Returns null
SELECT tanh(null);Table data
The following example uses the mf_math_fun_t sample table. To create the table and insert sample data, run:
CREATE TABLE IF NOT EXISTS mf_math_fun_t (
int_data INT,
bigint_data BIGINT,
double_data DOUBLE,
decimal_data DECIMAL,
float_data FLOAT,
string_data STRING
);
INSERT INTO mf_math_fun_t VALUES
(null, -10, 0.525, 0.525BD, CAST(0.525 AS FLOAT), '10'),
(-20, null, -0.1, -0.1BD, CAST(-0.1 AS FLOAT), '-10'),
(0, -1, null, 20.45BD, CAST(-1 AS FLOAT), '30'),
(-40, 4, 0.89, null, CAST(0.89 AS FLOAT), '-30'),
(5, -50, -1, -1BD, null, '50'),
(-60, 6, 1.5, 1.5BD, CAST(1.5 AS FLOAT), '-50'),
(-1, -70, -7.5, -7.5BD, CAST(-7.5 AS FLOAT), null),
(-80, 1, -10.2, -10.2BD, CAST(-10.2 AS FLOAT), '-1'),
(9, -90, 2.58, 2.58BD, CAST(2.58 AS FLOAT), '0'),
(-100, 10, -5.8, -5.8BD, CAST(-5.8 AS FLOAT), '-90');Calculate the hyperbolic tangent of values across multiple columns:
SELECT
tanh(bigint_data) AS bigint_new,
tanh(double_data) AS double_new,
tanh(decimal_data) AS decimal_new,
tanh(string_data) AS string_new
FROM mf_math_fun_t;Result:
+---------------------+----------------------+----------------------+---------------------+
| bigint_new | double_new | decimal_new | string_new |
+---------------------+----------------------+----------------------+---------------------+
| -0.9999999958776927 | 0.48154979836430806 | 0.48154979836430806 | 0.9999999958776927 |
| NULL | -0.09966799462495582 | -0.09966799462495582 | -0.9999999958776927 |
| -0.7615941559557649 | NULL | 1.0 | 1.0 |
| 0.999329299739067 | 0.7113937318189625 | NULL | -1.0 |
| -1.0 | -0.7615941559557649 | -0.7615941559557649 | 1.0 |
| 0.9999877116507956 | 0.9051482536448664 | 0.9051482536448664 | -1.0 |
| -1.0 | -0.9999993881955461 | -0.9999993881955461 | NULL |
| 0.7615941559557649 | -0.9999999972367348 | -0.9999999972367348 | -0.7615941559557649 |
| -1.0 | 0.9885821584459533 | 0.9885821584459533 | 0.0 |
| 0.9999999958776927 | -0.9999816679925603 | -0.9999816679925603 | -1.0 |
+---------------------+----------------------+----------------------+---------------------+Related functions
TANH is a mathematical function. For more information about functions related to data computing and conversion, see Mathematical functions.
该文章对您有帮助吗?